@zcrkey/js-utils 0.0.5 → 0.0.7

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 (55) hide show
  1. package/README.md +9 -0
  2. package/dist/cjs/color.d.ts +195 -0
  3. package/dist/cjs/color.js +353 -0
  4. package/{src/eventCenter.ts → dist/cjs/eventCenter.js} +120 -112
  5. package/dist/cjs/index.d.ts +9 -0
  6. package/dist/cjs/index.js +54 -0
  7. package/dist/cjs/obj.js +37 -0
  8. package/{src/storage.ts → dist/cjs/storage.js} +118 -101
  9. package/dist/cjs/tree.js +145 -0
  10. package/dist/{util.d.ts → cjs/util.d.ts} +3 -3
  11. package/{src/util.ts → dist/cjs/util.js} +173 -257
  12. package/dist/esm/color.d.ts +195 -0
  13. package/dist/esm/color.js +500 -0
  14. package/dist/esm/eventCenter.d.ts +59 -0
  15. package/dist/esm/index.d.ts +9 -0
  16. package/dist/esm/index.js +6 -0
  17. package/dist/esm/obj.d.ts +12 -0
  18. package/dist/{objUtil.js → esm/obj.js} +6 -6
  19. package/dist/esm/storage.d.ts +44 -0
  20. package/dist/esm/tree.d.ts +48 -0
  21. package/dist/esm/util.d.ts +209 -0
  22. package/dist/{util.js → esm/util.js} +129 -129
  23. package/dist/{index.umd.js → umd/index.umd.js} +1 -1
  24. package/package.json +15 -4
  25. package/.dumi/global.less +0 -1396
  26. package/.dumirc.ts +0 -36
  27. package/.fatherrc.ts +0 -14
  28. package/.husky/commit-msg +0 -4
  29. package/.husky/pre-commit +0 -4
  30. package/.prettierignore +0 -2
  31. package/.stylelintrc +0 -10
  32. package/dist/index.d.ts +0 -8
  33. package/dist/index.js +0 -5
  34. package/docs/api/eventCenter/index.md +0 -34
  35. package/docs/api/index.md +0 -5
  36. package/docs/api/storage/index.md +0 -9
  37. package/docs/api/storage/local.tsx +0 -91
  38. package/docs/api/storage/session.tsx +0 -85
  39. package/docs/api/treeUtil/index.md +0 -5
  40. package/docs/api/treeUtil/index.tsx +0 -266
  41. package/docs/api/util/index.md +0 -6
  42. package/docs/api/util/index.tsx +0 -405
  43. package/docs/api/util/is.tsx +0 -196
  44. package/docs/guide.md +0 -24
  45. package/src/index.ts +0 -8
  46. package/src/objUtil.ts +0 -20
  47. package/src/treeUtil.ts +0 -164
  48. package/tsconfig.json +0 -18
  49. /package/dist/{eventCenter.d.ts → cjs/eventCenter.d.ts} +0 -0
  50. /package/dist/{objUtil.d.ts → cjs/obj.d.ts} +0 -0
  51. /package/dist/{storage.d.ts → cjs/storage.d.ts} +0 -0
  52. /package/dist/{treeUtil.d.ts → cjs/tree.d.ts} +0 -0
  53. /package/dist/{eventCenter.js → esm/eventCenter.js} +0 -0
  54. /package/dist/{storage.js → esm/storage.js} +0 -0
  55. /package/dist/{treeUtil.js → esm/tree.js} +0 -0
package/.dumirc.ts DELETED
@@ -1,36 +0,0 @@
1
- import { defineConfig } from 'dumi';
2
-
3
- // more config: https://d.umijs.org/config
4
- export default defineConfig({
5
- outputPath: 'docs-dist',
6
- themeConfig: {
7
- name: '@zcrkey/js-utils',
8
- nav: {
9
- 'zh-CN': [
10
- { title: '指南', link: '/guide' },
11
- { title: 'API', link: '/api' },
12
- ],
13
- },
14
- footer: 'zcrkey | Copyright © 2023-present</span>',
15
- title: '@zcrkey/js-utils',
16
- description: {
17
- 'zh-CN': '一个 javascript 实用函数库',
18
- },
19
- actions: {
20
- 'zh-CN': [
21
- {
22
- type: 'primary',
23
- text: '开始使用',
24
- link: '/guide',
25
- },
26
- {
27
- text: 'API总览',
28
- link: '/api',
29
- },
30
- ],
31
- },
32
- socialLinks: {
33
- github: 'https://cnb.cool/cnbkey/zcrkey/js-utils.git',
34
- },
35
- },
36
- });
package/.fatherrc.ts DELETED
@@ -1,14 +0,0 @@
1
- import { defineConfig } from 'father';
2
-
3
- export default defineConfig({
4
- // more father config: https://github.com/umijs/father/blob/master/docs/config.md
5
- esm: {
6
- output: 'dist',
7
- },
8
- umd: {
9
- output: {
10
- path: 'dist',
11
- filename: 'index.umd.js',
12
- },
13
- },
14
- });
package/.husky/commit-msg DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
- npx commitlint --edit "${1}"
package/.husky/pre-commit DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
- npx lint-staged
package/.prettierignore DELETED
@@ -1,2 +0,0 @@
1
- /dist
2
- *.yaml
package/.stylelintrc DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "@umijs/lint/dist/config/stylelint",
3
- "rules": {
4
- "color-hex-length": null,
5
- "alpha-value-notation": null,
6
- "comment-empty-line-before": null,
7
- "selector-class-pattern": null,
8
- "custom-property-pattern": null
9
- }
10
- }
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export type * from './eventCenter';
2
- export { default as CrEventCenter } from './eventCenter';
3
- export type * from './objUtil';
4
- export { default as CrObjUtil } from './objUtil';
5
- export { default as CrStorage } from './storage';
6
- export type * from './treeUtil';
7
- export { default as CrTreeUtil } from './treeUtil';
8
- export { default as CrUtil } from './util';
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- export { default as CrEventCenter } from "./eventCenter";
2
- export { default as CrObjUtil } from "./objUtil";
3
- export { default as CrStorage } from "./storage";
4
- export { default as CrTreeUtil } from "./treeUtil";
5
- export { default as CrUtil } from "./util";
@@ -1,34 +0,0 @@
1
- # CrEventCenter 事件发布订阅
2
-
3
- 事件发布订阅
4
-
5
- - 推荐仅在原生 javascript 中使用
6
- - 不推荐中在三大框架中使用,而是使用各家框架的状态管理库(存在问题,闭包函数未能及时更新 useState 中的值)
7
-
8
- 原生写法
9
-
10
- ```
11
- import { CrEventCenter } from '@zcrkey/js-utils';
12
- import type { TSubscription } from '@zcrkey/js-utils';
13
-
14
- // 订阅事件
15
- const subscription: TSubscription = CrEventCenter.on('xxx_xxx', (params) => {
16
- console.log('params',params)
17
- });
18
-
19
- // 发布事件
20
- CrEventCenter.emit('xxx_xxx',{a:1,b:2})
21
-
22
- // 移除订阅事件
23
- subscription.remove()
24
- // 或者
25
- CrEventCenter.off(subscription);
26
-
27
- // 查找订阅事件
28
- const item = CrEventCenter.find('xxx_xxx')
29
-
30
- // 清除所有订阅事件
31
- CrEventCenter.clear()
32
-
33
-
34
- ```
package/docs/api/index.md DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- order: -1
3
- ---
4
-
5
- # API 总览
@@ -1,9 +0,0 @@
1
- # CrStorage 浏览器存储
2
-
3
- 浏览器存储
4
-
5
- - localStorage:大小(10mb)、访问(任何窗口)
6
- - sessionStorage 大小(5mb)、访问(同一窗口)
7
-
8
- <code src="./local.tsx"></code>
9
- <code src="./session.tsx"></code>
@@ -1,91 +0,0 @@
1
- /**
2
- * title: localStorage
3
- */
4
-
5
- import { CrStorage } from '@zcrkey/js-utils';
6
- import React, { useState } from 'react';
7
-
8
- const LOGIN_USER = 'loginUser';
9
-
10
- export default () => {
11
- const [data, setData] = useState<any>();
12
-
13
- const onSet = () => {
14
- // CrStorage.setLocalItem(LOGIN_USER, null);
15
- // CrStorage.setLocalItem(LOGIN_USER, -1);
16
- // CrStorage.setLocalItem(LOGIN_USER, undefined);
17
- // CrStorage.setLocalItem(LOGIN_USER, {});
18
- // CrStorage.setLocalItem(LOGIN_USER, []);
19
- CrStorage.setLocalItem(LOGIN_USER, {
20
- name: 'zcr',
21
- sex: '男',
22
- age: 18,
23
- });
24
- };
25
-
26
- const onGet = () => {
27
- const data = CrStorage.getLocalItem(LOGIN_USER);
28
- setData(data);
29
- };
30
-
31
- const onClear = () => {
32
- CrStorage.removeLocalItem(LOGIN_USER);
33
- setData('');
34
- };
35
-
36
- const onAllClear = () => {
37
- CrStorage.clearLocal();
38
- setData('');
39
- };
40
-
41
- return (
42
- <>
43
- <div className="flex flex-direction">
44
- <div className="text-lg">CrUtil.setLocalItem</div>
45
- <div>
46
- <button
47
- type="button"
48
- className="cr-btn line-blue radius"
49
- onClick={onSet}
50
- >
51
- 设置用户数据
52
- </button>
53
- </div>
54
- <div className="text-lg">CrUtil.getLocalItem</div>
55
- <div>
56
- <button
57
- type="button"
58
- className="cr-btn line-blue radius"
59
- onClick={onGet}
60
- >
61
- 获取用户数据
62
- </button>
63
- </div>
64
- <div className="text-lg">CrUtil.removeLocalItem</div>
65
- <div>
66
- <button
67
- type="button"
68
- className="cr-btn line-blue radius"
69
- onClick={onClear}
70
- >
71
- 清除用户数据
72
- </button>
73
- </div>
74
- </div>
75
- <div className="text-lg">CrUtil.clearLocal</div>
76
- <div>
77
- <button
78
- type="button"
79
- className="cr-btn line-blue radius"
80
- onClick={onAllClear}
81
- >
82
- 清除全部
83
- </button>
84
- </div>
85
-
86
- <div className="divider"></div>
87
-
88
- <p>用户数据:{JSON.stringify(data)}</p>
89
- </>
90
- );
91
- };
@@ -1,85 +0,0 @@
1
- /**
2
- * title: sessionStorage
3
- */
4
-
5
- import { CrStorage } from '@zcrkey/js-utils';
6
- import React, { useState } from 'react';
7
-
8
- const LOGIN_USER = 'loginUser';
9
-
10
- export default () => {
11
- const [data, setData] = useState<any>();
12
-
13
- const onSet = () => {
14
- CrStorage.setSessionItem(LOGIN_USER, {
15
- name: 'zcr',
16
- sex: '男',
17
- age: 18,
18
- });
19
- };
20
-
21
- const onGet = () => {
22
- setData(CrStorage.getSessionItem(LOGIN_USER));
23
- };
24
-
25
- const onClear = () => {
26
- CrStorage.removeSessionItem(LOGIN_USER);
27
- setData('');
28
- };
29
-
30
- const onAllClear = () => {
31
- CrStorage.clearSession();
32
- setData('');
33
- };
34
-
35
- return (
36
- <>
37
- <div className="flex flex-direction">
38
- <div className="text-lg">CrUtil.setSessionItem</div>
39
- <div>
40
- <button
41
- type="button"
42
- className="cr-btn line-blue radius"
43
- onClick={onSet}
44
- >
45
- 设置用户数据
46
- </button>
47
- </div>
48
- <div className="text-lg">CrUtil.getSessionItem</div>
49
- <div>
50
- <button
51
- type="button"
52
- className="cr-btn line-blue radius"
53
- onClick={onGet}
54
- >
55
- 获取用户数据
56
- </button>
57
- </div>
58
- <div className="text-lg">CrUtil.removeSessionItem</div>
59
- <div>
60
- <button
61
- type="button"
62
- className="cr-btn line-blue radius"
63
- onClick={onClear}
64
- >
65
- 清除用户数据
66
- </button>
67
- </div>
68
- </div>
69
- <div className="text-lg">CrUtil.clearSession</div>
70
- <div>
71
- <button
72
- type="button"
73
- className="cr-btn line-blue radius"
74
- onClick={onAllClear}
75
- >
76
- 清除全部
77
- </button>
78
- </div>
79
-
80
- <div className="divider"></div>
81
-
82
- <p>用户数据:{JSON.stringify(data)}</p>
83
- </>
84
- );
85
- };
@@ -1,5 +0,0 @@
1
- # CrTreeUtil 树工具类
2
-
3
- 树工具类
4
-
5
- <code src="./index.tsx"></code>
@@ -1,266 +0,0 @@
1
- /**
2
- * title: 基本使用
3
- */
4
-
5
- import { CrTreeUtil } from '@zcrkey/js-utils';
6
- import React, { useState } from 'react';
7
-
8
- const listData = [
9
- { id: '1', parentId: null, name: '节点 1' },
10
- { id: '1-1', parentId: '1', name: '节点 1-1' },
11
- { id: '1-1-1', parentId: '1-1', name: '节点 1-1-1' },
12
- { id: '1-1-2', parentId: '1-1', name: '节点 1-1-2' },
13
- { id: '1-2', parentId: '1', name: '节点 1-2' },
14
- { id: '1-2-1', parentId: '1-2', name: '节点 1-2-1' },
15
- { id: '1-2-1-1', parentId: '1-2-1', name: '节点 1-2-1-1' },
16
-
17
- { id: '2', parentId: null, name: '节点 2' },
18
- { id: '2-1', parentId: '2', name: '节点 2-1' },
19
- { id: '2-1-1', parentId: '2-1', name: '节点 2-1-1' },
20
- { id: '2-1-2', parentId: '2-1', name: '节点 2-1-2' },
21
- { id: '2-2', parentId: '2', name: '节点 2-2' },
22
-
23
- { id: '3', parentId: null, name: '节点 3' },
24
- { id: '3-1', parentId: '3', name: '节点 3-1' },
25
- { id: '3-1-1', parentId: '3-1', name: '节点 3-1-1' },
26
- { id: '3-1-1-1', parentId: '3-1-1', name: '节点 3-1-1-1' },
27
- { id: '3-2', parentId: '3', name: '节点 3-2' },
28
- { id: '3-2-1', parentId: '3-2', name: '节点 3-2-1' },
29
-
30
- { id: '4', parentId: null, name: '节点 4' },
31
- ];
32
-
33
- const treeData = [
34
- {
35
- id: '1',
36
- parentId: null,
37
- name: '节点 1',
38
- children: [
39
- {
40
- id: '1-1',
41
- parentId: '1',
42
- name: '节点 1-1',
43
- children: [
44
- {
45
- id: '1-1-1',
46
- parentId: '1-1',
47
- name: '节点 1-1-1',
48
- },
49
- {
50
- id: '1-1-2',
51
- parentId: '1-1',
52
- name: '节点 1-1-2',
53
- },
54
- ],
55
- },
56
- {
57
- id: '1-2',
58
- parentId: '1',
59
- name: '节点 1-2',
60
- children: [
61
- {
62
- id: '1-2-1',
63
- parentId: '1-2',
64
- name: '节点 1-2-1',
65
- children: [
66
- {
67
- id: '1-2-1-1',
68
- parentId: '1-2-1',
69
- name: '节点 1-2-1-1',
70
- },
71
- ],
72
- },
73
- ],
74
- },
75
- ],
76
- },
77
- {
78
- id: '2',
79
- parentId: null,
80
- name: '节点 2',
81
- children: [
82
- {
83
- id: '2-1',
84
- parentId: '2',
85
- name: '节点 2-1',
86
- children: [
87
- {
88
- id: '2-1-1',
89
- parentId: '2-1',
90
- name: '节点 2-1-1',
91
- },
92
- {
93
- id: '2-1-2',
94
- parentId: '2-1',
95
- name: '节点 2-1-2',
96
- },
97
- ],
98
- },
99
- {
100
- id: '2-2',
101
- parentId: '2',
102
- name: '节点 2-2',
103
- },
104
- ],
105
- },
106
- {
107
- id: '3',
108
- parentId: null,
109
- name: '节点 3',
110
- children: [
111
- {
112
- id: '3-1',
113
- parentId: '3',
114
- name: '节点 3-1',
115
- children: [
116
- {
117
- id: '3-1-1',
118
- parentId: '3-1',
119
- name: '节点 3-1-1',
120
- children: [
121
- {
122
- id: '3-1-1-1',
123
- parentId: '3-1-1',
124
- name: '节点 3-1-1-1',
125
- },
126
- ],
127
- },
128
- ],
129
- },
130
- {
131
- id: '3-2',
132
- parentId: '3',
133
- name: '节点 3-2',
134
- children: [
135
- {
136
- id: '3-2-1',
137
- parentId: '3-2',
138
- name: '节点 3-2-1',
139
- },
140
- ],
141
- },
142
- ],
143
- },
144
- {
145
- id: '4',
146
- parentId: null,
147
- name: '节点 4',
148
- },
149
- ];
150
-
151
- export default () => {
152
- const [result, setResult] = useState<any>({});
153
-
154
- const listToTree = () => {
155
- let res = CrTreeUtil.listToTree(listData, {
156
- isDeepCopy: true,
157
- });
158
- setResult({
159
- ...result,
160
- listToTree: res,
161
- });
162
- };
163
-
164
- const treeToList = () => {
165
- let res = CrTreeUtil.treeToList(treeData, {
166
- isDeepCopy: true,
167
- });
168
- setResult({
169
- ...result,
170
- treeToList: res,
171
- });
172
- };
173
-
174
- const getFlatParentDatas = () => {
175
- let res = CrTreeUtil.getFlatParentDatas(listData, '3-1-1-1', {
176
- valueField: 'id',
177
- getData: (item: any) => item,
178
- });
179
- setResult({
180
- ...result,
181
- getFlatParentDatas: res,
182
- });
183
- };
184
-
185
- return (
186
- <>
187
- <div className="flex flex-direction">
188
- <div>列表数据转树型数据</div>
189
- <div className="text-lg">CrTreeUtil.listToTree</div>
190
- <div>
191
- <button
192
- type="button"
193
- className="cr-btn line-blue radius"
194
- onClick={listToTree}
195
- >
196
- 调用
197
- </button>
198
- <div>
199
- <div style={{ display: 'inline-grid', width: '50%' }}>
200
- <pre style={{ marginBottom: '0px' }}>
201
- {JSON.stringify(listData, null, 2)}
202
- </pre>
203
- </div>
204
- <div style={{ display: 'inline-grid', width: '50%' }}>
205
- <pre style={{ marginBottom: '0px' }}>
206
- {JSON.stringify(result.listToTree, null, 2)}
207
- </pre>
208
- </div>
209
- </div>
210
- </div>
211
- </div>
212
- <div className="divider"></div>
213
- <div className="flex flex-direction">
214
- <div>树型数据转列表数据</div>
215
- <div className="text-lg">CrTreeUtil.treeToList</div>
216
- <div>
217
- <button
218
- type="button"
219
- className="cr-btn line-blue radius"
220
- onClick={treeToList}
221
- >
222
- 调用
223
- </button>
224
- <div>
225
- <div style={{ display: 'inline-grid', width: '50%' }}>
226
- <pre style={{ marginBottom: '0px' }}>
227
- {JSON.stringify(treeData, null, 2)}
228
- </pre>
229
- </div>
230
- <div style={{ display: 'inline-grid', width: '50%' }}>
231
- <pre style={{ marginBottom: '0px' }}>
232
- {JSON.stringify(result.treeToList, null, 2)}
233
- </pre>
234
- </div>
235
- </div>
236
- </div>
237
- </div>
238
- <div className="divider"></div>
239
- <div className="flex flex-direction">
240
- <div>获取扁平化父级数据</div>
241
- <div className="text-lg">CrTreeUtil.getFlatParentDatas</div>
242
- <div>
243
- <button
244
- type="button"
245
- className="cr-btn line-blue radius"
246
- onClick={getFlatParentDatas}
247
- >
248
- 调用
249
- </button>
250
- <div>
251
- <div style={{ display: 'inline-grid', width: '50%' }}>
252
- <pre style={{ marginBottom: '0px' }}>
253
- 值:'3-1-1-1' 数据源:{JSON.stringify(listData, null, 2)}
254
- </pre>
255
- </div>
256
- <div style={{ display: 'inline-grid', width: '50%' }}>
257
- <pre style={{ marginBottom: '0px' }}>
258
- {JSON.stringify(result.getFlatParentDatas, null, 2)}
259
- </pre>
260
- </div>
261
- </div>
262
- </div>
263
- </div>
264
- </>
265
- );
266
- };
@@ -1,6 +0,0 @@
1
- # CrUtil 实用函数
2
-
3
- 实用函数
4
-
5
- <code src="./index.tsx"></code>
6
- <code src="./is.tsx"></code>