Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: issue#52:新增log方法 #57

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4

- name: Set node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
Expand All @@ -40,13 +40,13 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4

- name: Set node version to ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: pnpm
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4

- name: Set node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: pnpm
Expand All @@ -29,7 +29,7 @@ jobs:
run: pnpm run docs:build

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
publish_branch: docs
publish_dir: ./docs/.vitepress/dist/
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: pnpm
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry = https://registry.npmmirror.com
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default () => {
return defineConfig({
base: '/xparcai-utils/',
title: 'XParCai工具库',
description: 'Collection of common JavaScript or TypeScript utils.',
description: '一个使用TS构建的JS轮子库,专为CV的小趴菜们设计。',
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
outline: { label: '快速定位' },
Expand Down
8 changes: 6 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xparcai-utils-docs",
"type": "module",
"version": "0.0.1-beta.1",
"description": "🍒 Collection of common JavaScript or TypeScript utils.",
"description": "🍒 一个使用TS构建的JS轮子库,专为CV的小趴菜们设计。",
"author": {
"name": "VictorBo",
"email": "[email protected]",
Expand All @@ -26,7 +26,11 @@
"scripts": {
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
"docs:preview": "vitepress preview",
"clean": "run-s clean:*",
"clean:deps": "rimraf node_modules",
"clean:dist": "rimraf .vitepress/dist",
"clean:cache": "rimraf .vitepress/cache"
},
"devDependencies": {
"vite": "^5.3.1",
Expand Down
7 changes: 7 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ export default defineConfig(
'unicorn/error-message': 'off',
},
},
// @xparcai-utils/log 包取消禁用console
{
files: ['packages/log/**/*.*'],
rules: {
'no-console': 'off',
},
},
)
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xparcai-utils-example",
"type": "module",
"version": "0.0.1-beta.1",
"description": "🍒 Collection of common JavaScript or TypeScript utils.",
"description": "🍒 一个使用TS构建的JS轮子库,专为CV的小趴菜们设计。",
"author": {
"name": "VictorBo",
"email": "[email protected]",
Expand Down
11 changes: 7 additions & 4 deletions examples/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
<body>
<div class="xparcai-welcome">欢迎测试xparcai-utils工具库</div>
<script>
console.log(
'umd => ',
window['xparcai-utils'].isType('xparcai', 'String'),
)
const xparcai = window['xparcai-utils']
console.log('xparcai函数列表 => ', xparcai)
console.log('umd => ', xparcai.isType('xparcai', 'String'))
xparcai.log.success('一枚小趴菜')
xparcai.log.error('一枚小趴菜')
xparcai.log.warn('一枚小趴菜')
xparcai.log.info('一枚小趴菜')
</script>
</body>
</html>
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@
"build": "pnpm -r --filter=./packages/* run build",
"docs": "pnpm -F xparcai-utils-docs run docs:dev",
"docs:build": "pnpm -F xparcai-utils-docs run docs:build",
"example:umd": "pnpm -F xparcai-utils-example run test:umd",
"example:cjs": "pnpm -F xparcai-utils-example run test:cjs",
"example:mjs": "pnpm -F xparcai-utils-example run test:mjs",
"example:pkg": "pnpm -F xparcai-utils-example run test:pkg",
"release": "pnpm run build && pnpm run test run && run-s release:*",
"release:bummp": "bumpp -r",
"release:publish": "pnpm -r --filter=./packages/* publish",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "vitest",
"clean": "run-s clean:*",
"clean:deps": "rimraf node_modules && pnpm -r run clean",
"clean:deps": "pnpm -r run clean && rimraf node_modules",
"clean:lock": "rimraf pnpm-lock.yaml",
"preinstall": "npx only-allow pnpm",
"prepare": "npx simple-git-hooks",
Expand All @@ -54,6 +58,7 @@
"@rollup/plugin-eslint": "^9.0.5",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.4",
"@types/node": "^20.14.2",
"@types/shelljs": "^0.8.15",
Expand All @@ -63,13 +68,13 @@
"fast-glob": "^3.3.2",
"jsdom": "^24.1.0",
"lint-staged": "^15.2.7",
"magic-string": "^0.30.10",
"npm-run-all": "^4.1.5",
"npm-run-all2": "^6.2.2",
"only-allow": "^1.2.1",
"ora": "^8.0.1",
"rimraf": "^5.0.7",
"rollup": "^4.18.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-polyfill-node": "^0.13.0",
"rollup-plugin-typescript2": "^0.36.0",
"shelljs": "^0.8.5",
"simple-git-hooks": "^2.11.1",
Expand Down
1 change: 1 addition & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from '@xparcai-utils/tool'
export * from '@xparcai-utils/is'
export * from '@xparcai-utils/string'
export * from '@xparcai-utils/object'
export * from '@xparcai-utils/log'
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xparcai-utils",
"type": "module",
"version": "0.0.1-beta.1",
"description": "🍒 Collection of common JavaScript or TypeScript utils.",
"description": "🍒 一个使用TS构建的JS轮子库,专为CV的小趴菜们设计。",
"author": {
"name": "VictorBo",
"email": "[email protected]",
Expand Down Expand Up @@ -38,8 +38,7 @@
"browser": "./dist/index.js"
}
},
"main": "src/index.ts",
"types": "src/index.d.ts",
"main": "index.ts",
"files": [
"README.md",
"dist"
Expand All @@ -55,6 +54,7 @@
},
"dependencies": {
"@xparcai-utils/is": "workspace:*",
"@xparcai-utils/log": "workspace:*",
"@xparcai-utils/object": "workspace:*",
"@xparcai-utils/string": "workspace:*",
"@xparcai-utils/tool": "workspace:*"
Expand Down
8 changes: 8 additions & 0 deletions packages/is/__test__/isBrowser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from 'vitest'
import { isBrowser } from '../src/isBrowser'

describe('@xparcai-utils/is', () => {
it('isBrowser', () => {
expect(isBrowser()).toBe(false)
})
})
9 changes: 9 additions & 0 deletions packages/is/__test__/isEmptyString.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { describe, expect, it } from 'vitest'
import { isEmptyString } from '../src/isEmptyString'

describe('@xparcai-utils/is', () => {
it('isEmptyString', () => {
expect(isEmptyString(1)).toBe(false)
expect(isEmptyString('')).toBe(true)
})
})
4 changes: 0 additions & 4 deletions packages/is/__test__/isHttp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ describe('@xparcai-utils/is', () => {
isHttp.setCondition('s')
expect(isHttp('http://xparcai.com')).toBe(false)
expect(isHttp('https://xparcai.com')).toBe(true)

// 设置默认值调用
expect(isHttp.setCondition('s')('http://xparcai.com')).toBe(false)
expect(isHttp.setCondition('s')('https://xparcai.com')).toBe(true)
})
})
2 changes: 2 additions & 0 deletions packages/is/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './src/isElement'
export * from './src/isEmail'
export * from './src/isEmptyArray'
export * from './src/isEmptyObject'
export * from './src/isEmptyString'
export * from './src/isError'
export * from './src/isFalse'
export * from './src/isFunction'
Expand All @@ -27,3 +28,4 @@ export * from './src/isSymbol'
export * from './src/isTrue'
export * from './src/isType'
export * from './src/isUndefined'
export * from './src/isBrowser'
5 changes: 2 additions & 3 deletions packages/is/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@xparcai-utils/is",
"type": "module",
"version": "0.0.1-beta.1",
"description": "🍒 Collection of common JavaScript or TypeScript utils.",
"description": "🍒 一个使用TS构建的JS轮子库,专为CV的小趴菜们设计。",
"author": {
"name": "VictorBo",
"email": "[email protected]",
Expand Down Expand Up @@ -38,8 +38,7 @@
"browser": "./dist/index.js"
}
},
"main": "src/index.ts",
"types": "src/index.d.ts",
"main": "index.ts",
"files": [
"README.md",
"dist"
Expand Down
7 changes: 7 additions & 0 deletions packages/is/src/isBrowser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* 是否是浏览器环境
* @returns 是否是浏览器环境
*/
export function isBrowser(): boolean {
return typeof window !== 'undefined'
}
2 changes: 1 addition & 1 deletion packages/is/src/isEmptyObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isObject } from './isObject'

/**
* 某个对象是否为空对象
* @param object 某个对象
* @param obj 某个对象
* @returns 是否为空对象
*/
export function isEmptyObject(obj: unknown): boolean {
Expand Down
10 changes: 10 additions & 0 deletions packages/is/src/isEmptyString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { isString } from './isString'

/**
* 某个字符串是否为空字符串
* @param str 某个字符串
* @returns 是否为空字符串
*/
export function isEmptyString(str: unknown): boolean {
return isString(str) && str === ''
}
1 change: 0 additions & 1 deletion packages/is/src/isHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ export function isHttp(url: string, condition: Condition = _condition): boolean
*/
isHttp.setCondition = function (condition: Condition = _condition) {
_condition = condition
return isHttp
}
42 changes: 42 additions & 0 deletions packages/log/__test__/log.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, expect, it, vi } from 'vitest'
import { log } from '../src/log'

describe('@xparcai-utils/log', () => {
it('log.info', () => {
// TODO 这个单测其实屌用没有,应该检测console.log是否被调用,但是因为有样式,就这把...
const infoSpy = vi.spyOn(log, 'info')
log.info('info内容')
expect(infoSpy).toHaveBeenCalledWith('info内容')
})
// it('log.warning', () => {
// expect(log.warning('warning头部', 'warning内容'))
// })
// it('log.success', () => {
// expect(log.success('success头部', 'success内容'))
// })
// it('log.picture', () => {
// expect(log.picture('https://cdn.wwads.cn/creatives/g8PYzZVx4gEYWkNxKb1ncQWxYas6WJFIsuu29iT5.png', 1))
// })
// it('log.table', () => {
// const data = [
// { id: 1, name: 'Alice', age: 25 },
// { id: 2, name: 'Bob', age: 30 },
// { id: 3, name: 'Charlie', age: 35 },
// ]
// const columns = [
// {
// title: 'ID',
// key: 'id',
// },
// {
// title: '名字',
// key: 'name',
// },
// {
// title: '年龄',
// key: 'age',
// },
// ]
// expect(log.table(data, columns))
// })
})
1 change: 1 addition & 0 deletions packages/log/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/log'
Loading