jinbi-utils 1.0.0

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 (68) 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/Dockerfile +3 -0
  8. package/README.md +160 -0
  9. package/api-extractor.json +15 -0
  10. package/commitlint.config.js +3 -0
  11. package/dist/index.esm.js +846 -0
  12. package/dist/index.esm.min.js +15 -0
  13. package/dist/index.umd.js +886 -0
  14. package/dist/index.umd.min.js +16 -0
  15. package/docs/assets/css/main.css +2679 -0
  16. package/docs/assets/images/icons.png +0 -0
  17. package/docs/assets/images/icons@2x.png +0 -0
  18. package/docs/assets/images/widgets.png +0 -0
  19. package/docs/assets/images/widgets@2x.png +0 -0
  20. package/docs/assets/js/main.js +1 -0
  21. package/docs/assets/js/search.json +1 -0
  22. package/docs/globals.html +144 -0
  23. package/docs/index.html +147 -0
  24. package/docs/interfaces/file.compressimgqualitycallback.html +212 -0
  25. package/docs/interfaces/file.compressimgscalecallback.html +206 -0
  26. package/docs/interfaces/file.exportbyblobparams.html +294 -0
  27. package/docs/interfaces/file.filesizeobject.html +227 -0
  28. package/docs/interfaces/file.genexportbyblobparams.html +237 -0
  29. package/docs/modules/common.html +188 -0
  30. package/docs/modules/date.html +364 -0
  31. package/docs/modules/file.html +452 -0
  32. package/docs/modules/number.html +356 -0
  33. package/docs/modules/object.html +245 -0
  34. package/docs/modules/print.html +183 -0
  35. package/docs/modules/string.html +352 -0
  36. package/docs/modules/validate.html +389 -0
  37. package/jest.config.js +15 -0
  38. package/package.json +75 -0
  39. package/rollup.config.js +65 -0
  40. package/src/common/index.ts +285 -0
  41. package/src/date/index.ts +141 -0
  42. package/src/file/index.ts +296 -0
  43. package/src/http/http.ts +0 -0
  44. package/src/http/httpEnums.ts +62 -0
  45. package/src/index.ts +8 -0
  46. package/src/number/index.ts +190 -0
  47. package/src/object/index.ts +54 -0
  48. package/src/print/index.ts +102 -0
  49. package/src/string/index.ts +111 -0
  50. package/src/validate/index.ts +78 -0
  51. package/src/wecom/wecom.ts +75 -0
  52. package/test/common/index.test.ts +19 -0
  53. package/test/date/index.test.ts +107 -0
  54. package/test/file/index.test.ts +104 -0
  55. package/test/number/index.test.ts +108 -0
  56. package/test/object/index.test.ts +20 -0
  57. package/test/string/index.test.ts +82 -0
  58. package/tsconfig.json +39 -0
  59. package/typedoc.json +9 -0
  60. package/types/common/index.d.ts +17 -0
  61. package/types/date/index.d.ts +60 -0
  62. package/types/file/index.d.ts +96 -0
  63. package/types/index.d.ts +8 -0
  64. package/types/number/index.d.ts +62 -0
  65. package/types/object/index.d.ts +25 -0
  66. package/types/print/index.d.ts +11 -0
  67. package/types/string/index.d.ts +45 -0
  68. package/types/validate/index.d.ts +45 -0
package/.babelrc ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "modules": false,
7
+ "targets": {
8
+ "node": "current"
9
+ }
10
+ }
11
+ ],
12
+ "@babel/preset-typescript"
13
+ ],
14
+ "env": {
15
+ "test": {
16
+ "plugins": ["@babel/plugin-transform-modules-commonjs"]
17
+ }
18
+ }
19
+ }
package/.cz-config.js ADDED
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+
5
+ types: [
6
+ {value: 'feat', name: 'feat: 新特性或功能'},
7
+ {value: 'fix', name: 'fix: 修复Bug'},
8
+ {value: 'docs', name: 'docs: 文档的变更'},
9
+ {value: 'style', name: 'style: 不影响代码运行的风格更改(空白、格式、缺少分号等)'},
10
+ {value: 'refactor', name: 'refactor: 代码重构, 注意和feat、fix区分'},
11
+ {value: 'perf', name: 'perf: 提高性能'},
12
+ {value: 'test', name: 'test: 添加测试'},
13
+ {value: 'chore', name: 'chore: 开发工具(构建、脚手架工具等)和库(如文档生成)的更改'},
14
+ {value: 'revert', name: 'revert: 代码回滚'},
15
+ {value: 'WIP', name: 'WIP: 进行中开发'}
16
+ ],
17
+
18
+ // list of Function Modules
19
+ scopes: [
20
+ {name: '模块1'},
21
+ {name: '模块2'},
22
+ ],
23
+
24
+ // it needs to match the value for field type. Eg.: 'fix'
25
+ /*
26
+ scopeOverrides: {
27
+ fix: [
28
+ {name: 'merge'},
29
+ {name: 'style'},
30
+ {name: 'e2eTest'},
31
+ {name: 'unitTest'}
32
+ ]
33
+ },
34
+ */
35
+ // override the messages, defaults are as follows
36
+ messages: {
37
+ type: '选择一种提交类型:',
38
+ scope: '选择一个scope (可选):',
39
+ // used if allowCustomScopes is true
40
+ customScope: 'Denote the SCOPE of this change:',
41
+ subject: '简短说明:\n',
42
+ body: '长说明,使用"|"换行(可选):\n',
43
+ breaking: '非兼容性说明 (可选):\n',
44
+ footer: '关联关闭的issue,例如:#31, #34(可选):\n',
45
+ confirmCommit: '确定提交说明?'
46
+ },
47
+
48
+
49
+ allowCustomScopes: true,
50
+ allowBreakingChanges: ['feat', 'fix'],
51
+
52
+ // limit subject length
53
+ subjectLimit: 100
54
+
55
+ };
package/.dockerignore ADDED
@@ -0,0 +1,3 @@
1
+ .git
2
+ node_modules
3
+ npm-debug.log
package/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
package/.eslintignore ADDED
@@ -0,0 +1,8 @@
1
+ /.git
2
+ /.vscode
3
+ node_modules
4
+ dist
5
+ test
6
+ rollup.config.js
7
+ types
8
+ *
package/.eslintrc.js ADDED
@@ -0,0 +1,54 @@
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "commonjs": true,
5
+ "es6": true,
6
+ "node": true
7
+ },
8
+ "extends": [
9
+ "eslint:recommended",
10
+ "plugin:@typescript-eslint/recommended"
11
+ ],
12
+ "parser": "@typescript-eslint/parser",
13
+ "plugins": ["@typescript-eslint"],
14
+ "parserOptions": {
15
+ "ecmaVersion": 2015,
16
+ "sourceType": "module",
17
+ "project": "./tsconfig.json"
18
+ },
19
+ "rules": {
20
+ 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
21
+ 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
22
+ 'prefer-promise-reject-errors': 'off', // 要求使用 Error 对象作为 Promise 拒绝的原因
23
+ 'linebreak-style': 'off', // 回车换行风格
24
+ 'no-trailing-spaces': 1, // 允许在空行、在注释块中使用空白符
25
+ 'import/prefer-default-export': 'off', //
26
+ 'object-curly-newline': 'off', // 不强制花括号内换行
27
+ 'import/named': 'off', // 停用 import/named 校验
28
+ 'no-underscore-dangle': 'off', // 禁止标识符中有悬空下划线
29
+ 'import/order': 'off',
30
+ 'prefer-object-spread': 1, // 禁止使用以对象字面量作为第一个参数的 Object.assign,优先使用对象扩展。
31
+ 'arrow-parens': [2, "as-needed", { "requireForBlockBody": true }], // 要求箭头函数的参数使用圆括号
32
+ "comma-dangle": ["error", "always-multiline"], // 要求或禁止使用拖尾逗号
33
+ "semi": 2, // 要求或禁止使用分号代替 ASI
34
+ "keyword-spacing": 2, // 强制关键字周围空格的一致性
35
+ "@typescript-eslint/explicit-function-return-type": "off",
36
+ "@typescript-eslint/interface-name-prefix": "off",
37
+ "@typescript-eslint/no-empty-function": "off",
38
+ "@typescript-eslint/no-inferrable-types": "off",
39
+ "@typescript-eslint/no-empty-interface": "off",
40
+ "@typescript-eslint/no-non-null-assertion": "off",
41
+ "@typescript-eslint/no-explicit-any": "off",
42
+ "@typescript-eslint/explicit-module-boundary-types": "off",
43
+ "@typescript-eslint/member-delimiter-style": ["error", {
44
+ "multiline": {
45
+ "delimiter": "semi",
46
+ "requireLast": true
47
+ },
48
+ "singleline": {
49
+ "delimiter": "semi",
50
+ "requireLast": true
51
+ }
52
+ }]
53
+ }
54
+ };
package/Dockerfile ADDED
@@ -0,0 +1,3 @@
1
+ FROM nginx
2
+
3
+ COPY docs /usr/share/nginx/html/
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+
2
+
3
+
4
+
5
+ # jbwy-utils 使用说明
6
+
7
+ 这是一个实用工具库,包含了多个常用的功能模块。以下是各个模块的详细说明:
8
+
9
+ ## 1. Common 模块 (common/index.ts)
10
+ 通用函数集合,提供了一些基础工具方法:
11
+
12
+ ### 1.1 判空相关
13
+ ```typescript
14
+ import { isEmpty } from 'jbwy-utils/common'
15
+
16
+ isEmpty('') // 返回 true
17
+ isEmpty(null) // 返回 true
18
+ isEmpty(undefined) // 返回 true
19
+ isEmpty(12323) // 返回 false
20
+ ```
21
+
22
+ ### 1.2 环境判断
23
+ ```typescript
24
+ import { getDeviceType, getEnvironment, getIsComWx } from 'jbwy-utils/common'
25
+
26
+ // 获取设备类型
27
+ const deviceInfo = getDeviceType()
28
+ // 返回: { isWxWork, isWeixin, isMobileScreen, isMobileAny }
29
+
30
+ // 获取运行环境
31
+ const env = getEnvironment()
32
+ // 返回: 'com-wx-mobile' | 'com-wx-pc' | 'wx-mobile' | 'wx-pc' | 'other'
33
+
34
+ // 判断是否企业微信环境
35
+ const isComWx = getIsComWx()
36
+ ```
37
+
38
+ ### 1.3 URL参数处理
39
+ ```typescript
40
+ import { getQueryString, getQueryVariable } from 'jbwy-utils/common'
41
+
42
+ // 获取URL参数
43
+ getQueryString(url, 'key')
44
+ getQueryVariable('key')
45
+ ```
46
+
47
+ ## 2. Number 模块 (number/index.ts)
48
+ 数字处理相关函数:
49
+
50
+ ```typescript
51
+ import { toThousands, formatFloat, ceil, floor } from 'jbwy-utils/number'
52
+
53
+ // 千分位格式化
54
+ toThousands(12345) // 返回 '12,345'
55
+ toThousands('12323.12') // 返回 '12,323.12'
56
+
57
+ // 格式化小数位
58
+ formatFloat('1.2345') // 返回 '1.23'
59
+ formatFloat('1.2345', 3) // 返回 '1.235'
60
+
61
+ // 向上取整
62
+ ceil('1.234', 2) // 返回 1.24
63
+
64
+ // 向下取整
65
+ floor('1.234', 2) // 返回 1.23
66
+ ```
67
+
68
+ ## 3. String 模块 (string/index.ts)
69
+ 字符串处理相关函数:
70
+
71
+ ```typescript
72
+ import { formatPhone, formatPhoneHide, formatBank } from 'jbwy-utils/string'
73
+
74
+ // 格式化手机号
75
+ formatPhone('18211572781') // 返回 '182 1157 2781'
76
+ formatPhone('18211572781', '-') // 返回 '182-1157-2781'
77
+
78
+ // 隐藏手机号中间四位
79
+ formatPhoneHide('18211572781') // 返回 '182****2781'
80
+
81
+ // 格式化银行卡号
82
+ formatBank('6282356862823568123') // 返回 '6282 3568 6282 3568 123'
83
+ ```
84
+
85
+ ## 4. Validate 模块 (validate/index.ts)
86
+ 提供各种验证函数:
87
+
88
+ ```typescript
89
+ import { isMobile, isEmail, isTelephone, isQQ } from 'jbwy-utils/validate'
90
+
91
+ // 验证手机号
92
+ isMobile('13800138000') // 返回 true/false
93
+
94
+ // 验证邮箱
95
+ isEmail('example@email.com') // 返回 true/false
96
+
97
+ // 验证固定电话
98
+ isTelephone('0755-88888888') // 返回 true/false
99
+
100
+ // 验证QQ号
101
+ isQQ('10000') // 返回 true/false
102
+ ```
103
+
104
+ ## 5. File 模块 (file/index.ts)
105
+ 文件处理相关函数:
106
+
107
+ ```typescript
108
+ import { calcFileSize, fileSizeFormat, compressImg } from 'jbwy-utils/file'
109
+
110
+ // 计算文件大小
111
+ calcFileSize(1024) // 返回 { size: 1, unit: 'KB' }
112
+
113
+ // 格式化文件大小
114
+ fileSizeFormat('1024', 'KB') // 返回 '1MB'
115
+
116
+ // 压缩图片
117
+ compressImg(file, scaleCallback, qualityCallback)
118
+ ```
119
+
120
+ ## 6. Object 模块 (object/index.ts)
121
+ 对象处理相关函数:
122
+
123
+ ```typescript
124
+ import { deepEqual, findNodePath } from 'jbwy-utils/object'
125
+
126
+ // 深度比较两个对象是否相等
127
+ deepEqual({a: 10}, {a: 10}) // 返回 true
128
+ deepEqual({a: 10}, {a: 10, b: 20}) // 返回 false
129
+
130
+ // 查找树结构节点路径
131
+ findNodePath(nodeValue, nodeKey, treeArray, childrenKey)
132
+ ```
133
+
134
+ ## 7. WeChat Work 模块 (wecom/wecom.ts)
135
+ 企业微信相关功能:
136
+
137
+ ```typescript
138
+ import { initWWConfig } from 'jbwy-utils/wecom'
139
+
140
+ // 初始化企业微信配置
141
+ initWWConfig()
142
+ ```
143
+
144
+ ## 安装和使用
145
+
146
+ 1. 安装依赖:
147
+ ```bash
148
+ npm install jbwy-utils
149
+ ```
150
+
151
+ 2. 引入使用:
152
+ ```typescript
153
+ import { isEmpty } from 'jbwy-utils/common'
154
+ import { formatPhone } from 'jbwy-utils/string'
155
+ // ... 按需引入其他功能
156
+ ```
157
+
158
+ 注意:所有模块都支持按需引入,可以只引入需要使用的功能,减少打包体积。
159
+
160
+
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "mainEntryPointFilePath": "./types/index.d.ts",
4
+ "bundledPackages": [ ],
5
+ "dtsRollup": {
6
+ "enabled": true,
7
+ "untrimmedFilePath": "./types/index.d.ts"
8
+ },
9
+ "docModel": {
10
+ "enabled": true
11
+ },
12
+ "apiReport": {
13
+ "enabled": true
14
+ }
15
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ };