jinbi-utils 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.babelrc +19 -0
  2. package/.cz-config.js +55 -0
  3. package/.dockerignore +3 -0
  4. package/.editorconfig +12 -0
  5. package/.eslintignore +8 -0
  6. package/.eslintrc.js +54 -0
  7. package/.versionrc.json +9 -0
  8. package/CHANGELOG.md +49 -49
  9. package/CHUNK_OPTIMIZER_USAGE.md +132 -0
  10. package/Dockerfile +3 -0
  11. package/QUICK_RELEASE.md +85 -0
  12. package/README.md +189 -189
  13. package/RELEASE_GUIDE.md +243 -0
  14. package/api-extractor.json +15 -0
  15. package/commitlint.config.js +3 -0
  16. package/jest.config.js +15 -0
  17. package/package.json +82 -109
  18. package/rollup.config.chunk-optimizer.js +32 -0
  19. package/rollup.config.js +73 -0
  20. package/src/array/index.ts +85 -0
  21. package/src/build/chunk-optimizer/ARCHITECTURE.md +347 -0
  22. package/src/build/chunk-optimizer/QUICK_START.md +370 -0
  23. package/src/build/chunk-optimizer/README.md +240 -0
  24. package/src/build/chunk-optimizer/core/chunk-generator.ts +166 -0
  25. package/src/build/chunk-optimizer/core/classifier.ts +148 -0
  26. package/src/build/chunk-optimizer/core/dependency-reader.ts +138 -0
  27. package/src/build/chunk-optimizer/examples/basic-usage.ts +234 -0
  28. package/src/build/chunk-optimizer/index.ts +166 -0
  29. package/src/build/chunk-optimizer/rules/common-rules.ts +131 -0
  30. package/src/build/chunk-optimizer/rules/framework-rules.ts +93 -0
  31. package/src/build/chunk-optimizer/rules/index.ts +27 -0
  32. package/src/build/chunk-optimizer/test.ts +94 -0
  33. package/src/build/chunk-optimizer/types.ts +128 -0
  34. package/src/color/index.ts +58 -0
  35. package/src/common/index.ts +353 -0
  36. package/src/constant/common.constant.ts +13 -0
  37. package/src/date/index.ts +143 -0
  38. package/src/dom/index.ts +198 -0
  39. package/src/file/index.ts +319 -0
  40. package/src/http/apiBuilder/README.md +648 -0
  41. package/src/http/apiBuilder/api-builder.ts +502 -0
  42. package/src/http/apiBuilder/example.ts +243 -0
  43. package/src/http/apiBuilder/index.ts +1 -0
  44. package/src/http/apiBuilder//345/277/253/351/200/237/345/217/202/350/200/203.md +199 -0
  45. package/src/http/http.ts +79 -0
  46. package/src/http/httpEnums.ts +61 -0
  47. package/src/iam/index.ts +46 -0
  48. package/src/index.ts +20 -0
  49. package/src/middleware/requestLogger.middware.ts +371 -0
  50. package/src/middleware/requestLoggerUnified.ts +371 -0
  51. package/src/number/index.ts +362 -0
  52. package/src/object/index.ts +54 -0
  53. package/src/print/index.ts +102 -0
  54. package/src/string/index.ts +189 -0
  55. package/src/utils/curl.ts +108 -0
  56. package/src/validate/index.ts +100 -0
  57. package/src/websocket/emitter.ts +39 -0
  58. package/src/websocket/index.ts +6 -0
  59. package/src/websocket/manager.ts +151 -0
  60. package/src/websocket/pinia-store.ts +91 -0
  61. package/src/websocket/service.ts +34 -0
  62. package/src/websocket/types.ts +45 -0
  63. package/test/common/index.test.ts +19 -0
  64. package/test/date/index.test.ts +107 -0
  65. package/test/file/index.test.ts +104 -0
  66. package/test/number/index.test.ts +108 -0
  67. package/test/object/index.test.ts +20 -0
  68. package/test/string/index.test.ts +82 -0
  69. package/tsconfig.json +39 -0
  70. package/typedoc.json +12 -0
  71. package/types/file/index.d.ts +7 -0
  72. package/types/index.d.ts +1 -0
  73. package/types/websocket/emitter.d.ts +16 -0
  74. package/types/websocket/index.d.ts +6 -0
  75. package/types/websocket/manager.d.ts +36 -0
  76. package/types/websocket/pinia-store.d.ts +25 -0
  77. package/types/websocket/service.d.ts +13 -0
  78. package/types/websocket/types.d.ts +34 -0
  79. package/dist/chunk-optimizer.cjs +0 -703
  80. package/dist/index.esm.js +0 -2791
  81. package/dist/index.esm.min.js +0 -15
  82. package/dist/index.umd.js +0 -2899
  83. package/dist/index.umd.min.js +0 -16
package/package.json CHANGED
@@ -1,109 +1,82 @@
1
- {
2
- "name": "jinbi-utils",
3
- "version": "1.0.20",
4
- "description": "",
5
- "main": "dist/index.umd.min.js",
6
- "module": "dist/index.esm.min.js",
7
- "typings": "types/index.d.ts",
8
- "files": [
9
- "dist",
10
- "types",
11
- "README.md",
12
- "CHANGELOG.md"
13
- ],
14
- "exports": {
15
- ".": {
16
- "types": "./types/index.d.ts",
17
- "import": "./dist/index.esm.min.js",
18
- "require": "./dist/index.umd.min.js",
19
- "default": "./dist/index.esm.min.js"
20
- },
21
- "./chunk-optimizer": {
22
- "types": "./types/build/chunk-optimizer/index.d.ts",
23
- "require": "./dist/chunk-optimizer.min.cjs",
24
- "default": "./dist/chunk-optimizer.min.cjs"
25
- }
26
- },
27
- "scripts": {
28
- "dev": "cross-env NODE_ENV=development rollup -w -c",
29
- "build": "npm run build:main && npm run build:chunk-optimizer && npm run build:docs",
30
- "build:main": "cross-env NODE_ENV=production rollup -c",
31
- "build:chunk-optimizer": "rollup -c rollup.config.chunk-optimizer.js",
32
- "watch:dist": "nodemon --watch ./dist --exec 'yalc publish --force'",
33
- "build:docs": "typedoc",
34
- "lint:fix": "eslint src/** --fix",
35
- "lint": "eslint src/**",
36
- "test": "jest --coverage",
37
- "test:dev": "jest --watch --coverage",
38
- "prepublishOnly": "npm run build",
39
- "release:major": "npm run build && standard-version --release-as major && npm publish && git push --follow-tags",
40
- "release:minor": "npm run build && standard-version --release-as minor && npm publish && git push --follow-tags",
41
- "release:patch": "npm run build && standard-version --release-as patch && npm publish && git push --follow-tags",
42
- "release:beta": "npm run build && standard-version --prerelease beta && npm publish --tag beta && git push --follow-tags",
43
- "release": "npm run release:patch"
44
- },
45
- "keywords": [
46
- "fe-utils",
47
- "typescript"
48
- ],
49
- "repository": {
50
- "type": "git",
51
- "url": ""
52
- },
53
- "bugs": {
54
- "url": "https://git"
55
- },
56
- "author": "",
57
- "license": "MIT",
58
- "devDependencies": {
59
- "@babel/core": "^7.9.6",
60
- "@babel/plugin-transform-modules-commonjs": "^7.10.1",
61
- "@babel/preset-env": "^7.9.6",
62
- "@babel/preset-typescript": "^7.10.1",
63
- "@commitlint/cli": "^11.0.0",
64
- "@commitlint/config-conventional": "^11.0.0",
65
- "@types/jest": "^25.2.3",
66
- "@types/node": "^24.10.0",
67
- "@typescript-eslint/eslint-plugin": "^3.0.2",
68
- "@typescript-eslint/parser": "^3.0.2",
69
- "axios": "1.8.2",
70
- "babel-jest": "^26.0.1",
71
- "babel-preset-es2015-rollup": "^3.0.0",
72
- "conventional-changelog": "^3.1.23",
73
- "cross-env": "^7.0.2",
74
- "cz-conventional-changelog": "^3.3.0",
75
- "cz-customizable": "^6.3.0",
76
- "eslint": "^7.1.0",
77
- "eslint-plugin-import": "^2.22.1",
78
- "husky": "^2.3.0",
79
- "jest": "^26.0.1",
80
- "lint-staged": "^10.4.0",
81
- "rollup": "^2.10.9",
82
- "rollup-plugin-babel": "^4.4.0",
83
- "rollup-plugin-cleaner": "^1.0.0",
84
- "rollup-plugin-eslint": "^7.0.0",
85
- "rollup-plugin-serve": "^1.0.1",
86
- "rollup-plugin-terser": "^6.1.0",
87
- "rollup-plugin-typescript2": "^0.27.1",
88
- "standard-version": "^9.5.0",
89
- "ts-jest": "^26.0.0",
90
- "tslib": "^2.8.1",
91
- "typedoc": "^0.17.8",
92
- "typedoc-plugin-external-module-name": "^4.0.3",
93
- "typescript": "^3.9.3"
94
- },
95
- "config": {
96
- "commitizen": {
97
- "path": "node_modules/cz-customizable"
98
- }
99
- },
100
- "husky": {
101
- "hooks": {
102
- "pre-commit": "exit 0",
103
- "commit-msg": "exit 0"
104
- }
105
- },
106
- "optionalDependencies": {
107
- "fsevents": "^2.3.2"
108
- }
109
- }
1
+ {
2
+ "name": "jinbi-utils",
3
+ "version": "1.0.21",
4
+ "description": "",
5
+ "main": "dist/index.umd.min.js",
6
+ "module": "dist/index.esm.min.js",
7
+ "typings": "types/index.d.ts",
8
+ "scripts": {
9
+ "dev": "cross-env NODE_ENV=development rollup -w -c",
10
+ "build": "cross-env NODE_ENV=production rollup -c && npm run build:docs",
11
+ "watch:dist": "nodemon --watch ./dist --exec 'yalc publish --force'",
12
+ "build:docs": "typedoc",
13
+ "lint:fix": "eslint src/** --fix",
14
+ "lint": "eslint src/**",
15
+ "test": "jest --coverage",
16
+ "test:dev": "jest --watch --coverage"
17
+ },
18
+ "keywords": [
19
+ "fe-utils",
20
+ "typescript"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": ""
25
+ },
26
+ "bugs": {
27
+ "url": "https://git"
28
+ },
29
+ "author": "",
30
+ "license": "MIT",
31
+ "devDependencies": {
32
+ "@babel/core": "^7.9.6",
33
+ "@babel/plugin-transform-modules-commonjs": "^7.10.1",
34
+ "@babel/preset-env": "^7.9.6",
35
+ "@babel/preset-typescript": "^7.10.1",
36
+ "@commitlint/cli": "^11.0.0",
37
+ "@commitlint/config-conventional": "^11.0.0",
38
+ "@types/jest": "^25.2.3",
39
+ "@typescript-eslint/eslint-plugin": "^3.0.2",
40
+ "@typescript-eslint/parser": "^3.0.2",
41
+ "axios": "1.8.2",
42
+ "babel-jest": "^26.0.1",
43
+ "babel-preset-es2015-rollup": "^3.0.0",
44
+ "conventional-changelog": "^3.1.23",
45
+ "cross-env": "^7.0.2",
46
+ "cz-conventional-changelog": "^3.3.0",
47
+ "cz-customizable": "^6.3.0",
48
+ "eslint": "^7.1.0",
49
+ "eslint-plugin-import": "^2.22.1",
50
+ "husky": "^2.3.0",
51
+ "jest": "^26.0.1",
52
+ "lint-staged": "^10.4.0",
53
+ "rollup": "^2.10.9",
54
+ "rollup-plugin-babel": "^4.4.0",
55
+ "rollup-plugin-cleaner": "^1.0.0",
56
+ "rollup-plugin-eslint": "^7.0.0",
57
+ "rollup-plugin-serve": "^1.0.1",
58
+ "rollup-plugin-terser": "^6.1.0",
59
+ "rollup-plugin-typescript2": "^0.27.1",
60
+ "ts-jest": "^26.0.0",
61
+ "typedoc": "^0.17.8",
62
+ "typedoc-plugin-external-module-name": "^4.0.3",
63
+ "typescript": "^3.9.3"
64
+ },
65
+ "config": {
66
+ "commitizen": {
67
+ "path": "node_modules/cz-customizable"
68
+ }
69
+ },
70
+ "husky": {
71
+ "hooks": {
72
+ "pre-commit": "exit 0",
73
+ "commit-msg": "exit 0"
74
+ }
75
+ },
76
+ "dependencies": {
77
+ "@wecom/jssdk": "^2.3.1",
78
+ "pinia": "^2.1.7",
79
+ "tslib": "^2.8.1",
80
+ "vue": "^3.4.0"
81
+ }
82
+ }
@@ -0,0 +1,32 @@
1
+ import babel from 'rollup-plugin-babel';
2
+ import typescript from 'rollup-plugin-typescript2';
3
+ import { terser } from 'rollup-plugin-terser';
4
+
5
+ const output = [
6
+ {
7
+ file: 'dist/chunk-optimizer.cjs',
8
+ format: 'cjs',
9
+ },
10
+ ];
11
+
12
+ if (process.env.NODE_ENV === 'production') {
13
+ output.push({
14
+ file: 'dist/chunk-optimizer.min.cjs',
15
+ format: 'cjs',
16
+ plugins: [terser()],
17
+ });
18
+ }
19
+
20
+ export default {
21
+ input: 'src/build/chunk-optimizer/index.ts',
22
+ output,
23
+ external: ['fs', 'path'],
24
+ plugins: [
25
+ typescript({
26
+ useTsconfigDeclarationDir: true,
27
+ }),
28
+ babel({
29
+ exclude: 'node_modules/**',
30
+ }),
31
+ ],
32
+ };
@@ -0,0 +1,73 @@
1
+ import babel from 'rollup-plugin-babel';
2
+ import { eslint } from "rollup-plugin-eslint";
3
+ import typescript from 'rollup-plugin-typescript2';
4
+ import cleaner from 'rollup-plugin-cleaner';
5
+ import { terser } from "rollup-plugin-terser";
6
+ import serve from 'rollup-plugin-serve';
7
+ import pkg from './package.json';
8
+
9
+ // 端口
10
+ const PORT = 3001;
11
+ // 是否是生产
12
+ const IS_PROD = process.env.NODE_ENV === 'production';
13
+
14
+ const formats = ['umd', 'esm'];
15
+ const output = formats.map((format) => ({
16
+ file: `dist/index.${format}.js`,
17
+ format,
18
+ name: pkg.name,
19
+ globals: {
20
+ 'axios': 'axios',
21
+ 'pinia': 'pinia'
22
+ }
23
+ }));
24
+
25
+ // 生成模式生成压缩文件
26
+ if (IS_PROD) {
27
+ formats.forEach((format) => {
28
+ output.push({
29
+ file: `dist/index.${format}.min.js`,
30
+ format,
31
+ name: pkg.name,
32
+ globals: {
33
+ 'axios': 'axios',
34
+ 'pinia': 'pinia'
35
+ },
36
+ plugins: [terser()],
37
+ });
38
+ });
39
+ }
40
+
41
+ export default {
42
+ input: 'src/index.ts',
43
+ output,
44
+ external: ['fsevents', 'axios', 'pinia', 'fs', 'path'],
45
+ plugins: [
46
+ eslint({
47
+ fix: true,
48
+ exclude: 'node_modules/**'
49
+ }),
50
+ // 使用 tsconfig.json 中定义 的 declarationDir
51
+ typescript({
52
+ useTsconfigDeclarationDir: true,
53
+ }),
54
+ babel({
55
+ exclude: 'node_modules/**',
56
+ }),
57
+ cleaner({
58
+ targets: [
59
+ './dist/',
60
+ './types/'
61
+ ]
62
+ }),
63
+ !IS_PROD && (
64
+ serve({
65
+ open: false,
66
+ contentBase: ['dist', 'example'],
67
+ historyApiFallback: true,
68
+ host: 'localhost',
69
+ port: PORT,
70
+ })
71
+ ),
72
+ ],
73
+ };
@@ -0,0 +1,85 @@
1
+ /**
2
+ * 数组处理相关
3
+ * @packageDocumentation
4
+ * @module Array
5
+ * @preferred
6
+ */
7
+
8
+ /**
9
+ * 从对象数组中提取指定 key 的值,组成新数组
10
+ * @param arr - 对象数组
11
+ * @param key - 要提取的键名
12
+ * @returns 提取的值数组
13
+ */
14
+ export function getKeyList<T extends Record<string, any>>(
15
+ arr: T[],
16
+ key: string
17
+ ): any[] {
18
+ if (!Array.isArray(arr)) return [];
19
+
20
+ const result: any[] = [];
21
+ for (const item of arr) {
22
+ if (item && item[key] !== undefined && item[key] !== null) {
23
+ result.push(item[key]);
24
+ }
25
+ }
26
+
27
+ return result;
28
+ }
29
+
30
+ /**
31
+ * 判断父数组是否包含子数组的所有元素(深度比较)
32
+ * 注意:此函数需要配合深度比较工具使用
33
+ * @param parent - 父数组
34
+ * @param children - 子数组
35
+ * @param compareFn - 比较函数,用于判断两个元素是否相等
36
+ * @returns 是否包含所有子元素
37
+ */
38
+ export function isIncludeAllChildren<T>(
39
+ parent: T[],
40
+ children: T[],
41
+ compareFn?: (a: T, b: T) => boolean
42
+ ): boolean {
43
+ if (!Array.isArray(parent) || !Array.isArray(children)) return false;
44
+
45
+ const defaultCompareFn = (a: T, b: T) => JSON.stringify(a) === JSON.stringify(b);
46
+ const compare = compareFn || defaultCompareFn;
47
+
48
+ return children.every(child => parent.some(item => compare(item, child)));
49
+ }
50
+
51
+ /**
52
+ * 判断数组或对象是否为空
53
+ * @param value - 待检查的值
54
+ * @returns 是否为空
55
+ */
56
+ export function isAllEmpty(value: any): boolean {
57
+ if (value === null || value === undefined) return true;
58
+ if (typeof value === 'string') return value.trim().length === 0;
59
+ if (Array.isArray(value)) return value.length === 0;
60
+ if (typeof value === 'object') return Object.keys(value).length === 0;
61
+ return false;
62
+ }
63
+
64
+ /**
65
+ * 计算两个数组的交集
66
+ * @param arr1 - 数组1
67
+ * @param arr2 - 数组2
68
+ * @returns 交集数组
69
+ */
70
+ export function intersection<T>(arr1: T[], arr2: T[]): T[] {
71
+ if (!Array.isArray(arr1) || !Array.isArray(arr2)) return [];
72
+ return arr1.filter(item => arr2.includes(item));
73
+ }
74
+
75
+ /**
76
+ * 数组求和
77
+ * @param arr - 数字数组
78
+ * @returns 数组元素之和
79
+ */
80
+ export function sum(arr: number[]): number {
81
+ return Array.isArray(arr) && arr.length > 0
82
+ ? arr.reduce((acc, val) => acc + val, 0)
83
+ : 0;
84
+ }
85
+