iota-utools 0.0.6 → 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 (102) hide show
  1. package/README.md +147 -124
  2. package/lib/cjs/datatree/deepClone.js +30 -0
  3. package/lib/cjs/datatree/deleteTreeNode.js +20 -0
  4. package/lib/cjs/datatree/findTreeNode.js +32 -0
  5. package/lib/cjs/datatree/fuzzySearchTree.js +40 -0
  6. package/lib/cjs/datatree/toFlatTree.js +17 -0
  7. package/lib/cjs/datatree/toTreeFlat.js +25 -0
  8. package/lib/cjs/fileStream/downFile.js +33 -0
  9. package/lib/cjs/fileStream/downStream.js +48 -0
  10. package/lib/cjs/index.js +57 -0
  11. package/lib/{storage → cjs/storage}/index.d.ts +5 -0
  12. package/lib/cjs/storage/index.js +50 -0
  13. package/lib/cjs/storage/local.js +47 -0
  14. package/lib/cjs/storage/session.js +47 -0
  15. package/lib/cjs/utools/copyText.js +25 -0
  16. package/lib/cjs/utools/debounce.js +22 -0
  17. package/lib/cjs/utools/sleep.js +18 -0
  18. package/lib/cjs/utools/throttle.js +33 -0
  19. package/lib/cjs/utools/typeof.js +45 -0
  20. package/lib/cjs/uuid/generateString.js +18 -0
  21. package/lib/cjs/uuid/generateUUID.js +20 -0
  22. package/lib/es/array/index.d.ts +1 -0
  23. package/lib/es/array/uniqueArrayByProperty.d.ts +7 -0
  24. package/lib/es/datatree/deepClone.d.ts +6 -0
  25. package/lib/es/datatree/deepClone.js +28 -0
  26. package/lib/es/datatree/deleteTreeNode.d.ts +7 -0
  27. package/lib/es/datatree/deleteTreeNode.js +18 -0
  28. package/lib/es/datatree/findTreeNode.d.ts +8 -0
  29. package/lib/es/datatree/findTreeNode.js +30 -0
  30. package/lib/es/datatree/fuzzySearchTree.d.ts +8 -0
  31. package/lib/es/datatree/fuzzySearchTree.js +38 -0
  32. package/lib/es/datatree/index.d.ts +6 -0
  33. package/lib/es/datatree/models.d.ts +4 -0
  34. package/lib/es/datatree/toFlatTree.d.ts +6 -0
  35. package/lib/es/datatree/toFlatTree.js +15 -0
  36. package/lib/es/datatree/toTreeFlat.d.ts +7 -0
  37. package/lib/es/datatree/toTreeFlat.js +23 -0
  38. package/lib/es/fileStream/downFile.d.ts +8 -0
  39. package/lib/es/fileStream/downFile.js +31 -0
  40. package/lib/es/fileStream/downStream.d.ts +8 -0
  41. package/lib/es/fileStream/downStream.js +46 -0
  42. package/lib/es/fileStream/index.d.ts +2 -0
  43. package/lib/es/index.d.ts +5 -0
  44. package/lib/es/index.js +20 -0
  45. package/lib/es/params/decodeParams.d.ts +6 -0
  46. package/lib/es/params/encodeParams.d.ts +6 -0
  47. package/lib/es/params/index.d.ts +2 -0
  48. package/lib/es/storage/index.d.ts +12 -0
  49. package/lib/es/storage/index.js +47 -0
  50. package/lib/es/storage/local.d.ts +21 -0
  51. package/lib/es/storage/local.js +43 -0
  52. package/lib/es/storage/session.d.ts +21 -0
  53. package/lib/es/storage/session.js +43 -0
  54. package/lib/es/utools/copyText.d.ts +6 -0
  55. package/lib/es/utools/copyText.js +23 -0
  56. package/lib/es/utools/debounce.d.ts +7 -0
  57. package/lib/es/utools/debounce.js +20 -0
  58. package/lib/es/utools/index.d.ts +5 -0
  59. package/lib/es/utools/sleep.d.ts +5 -0
  60. package/lib/es/utools/sleep.js +16 -0
  61. package/lib/es/utools/throttle.d.ts +7 -0
  62. package/lib/es/utools/throttle.js +31 -0
  63. package/lib/es/utools/typeof.d.ts +10 -0
  64. package/lib/es/utools/typeof.js +34 -0
  65. package/lib/es/uuid/generateString.d.ts +6 -0
  66. package/lib/es/uuid/generateString.js +16 -0
  67. package/lib/es/uuid/generateUUID.d.ts +6 -0
  68. package/lib/es/uuid/generateUUID.js +18 -0
  69. package/lib/es/uuid/index.d.ts +2 -0
  70. package/package.json +44 -39
  71. package/lib/index.cjs.js +0 -2
  72. package/lib/index.cjs.js.map +0 -1
  73. package/lib/index.js +0 -2
  74. package/lib/index.js.map +0 -1
  75. /package/lib/{array → cjs/array}/index.d.ts +0 -0
  76. /package/lib/{array → cjs/array}/uniqueArrayByProperty.d.ts +0 -0
  77. /package/lib/{datatree → cjs/datatree}/deepClone.d.ts +0 -0
  78. /package/lib/{datatree → cjs/datatree}/deleteTreeNode.d.ts +0 -0
  79. /package/lib/{datatree → cjs/datatree}/findTreeNode.d.ts +0 -0
  80. /package/lib/{datatree → cjs/datatree}/fuzzySearchTree.d.ts +0 -0
  81. /package/lib/{datatree → cjs/datatree}/index.d.ts +0 -0
  82. /package/lib/{datatree → cjs/datatree}/models.d.ts +0 -0
  83. /package/lib/{datatree → cjs/datatree}/toFlatTree.d.ts +0 -0
  84. /package/lib/{datatree → cjs/datatree}/toTreeFlat.d.ts +0 -0
  85. /package/lib/{fileStream → cjs/fileStream}/downFile.d.ts +0 -0
  86. /package/lib/{fileStream → cjs/fileStream}/downStream.d.ts +0 -0
  87. /package/lib/{fileStream → cjs/fileStream}/index.d.ts +0 -0
  88. /package/lib/{main.d.ts → cjs/index.d.ts} +0 -0
  89. /package/lib/{params → cjs/params}/decodeParams.d.ts +0 -0
  90. /package/lib/{params → cjs/params}/encodeParams.d.ts +0 -0
  91. /package/lib/{params → cjs/params}/index.d.ts +0 -0
  92. /package/lib/{storage → cjs/storage}/local.d.ts +0 -0
  93. /package/lib/{storage → cjs/storage}/session.d.ts +0 -0
  94. /package/lib/{utools → cjs/utools}/copyText.d.ts +0 -0
  95. /package/lib/{utools → cjs/utools}/debounce.d.ts +0 -0
  96. /package/lib/{utools → cjs/utools}/index.d.ts +0 -0
  97. /package/lib/{utools → cjs/utools}/sleep.d.ts +0 -0
  98. /package/lib/{utools → cjs/utools}/throttle.d.ts +0 -0
  99. /package/lib/{utools → cjs/utools}/typeof.d.ts +0 -0
  100. /package/lib/{uuid → cjs/uuid}/generateString.d.ts +0 -0
  101. /package/lib/{uuid → cjs/uuid}/generateUUID.d.ts +0 -0
  102. /package/lib/{uuid → cjs/uuid}/index.d.ts +0 -0
package/README.md CHANGED
@@ -1,124 +1,147 @@
1
- ## iota-tools
2
-
3
- ### 类型判断:
4
-
5
- ```ts
6
- // 数据类型
7
- function etTypeof(value: any): string
8
-
9
- // 是否是数组
10
- function isArray(value: any): boolean
11
-
12
- // 是否是布尔值
13
- function isBoolean(value: any): boolean
14
-
15
- // 是否是字符串类型
16
- function isString(value: any): boolean
17
-
18
- // 是否是数字
19
- function isNumber(value: any): boolean
20
-
21
- // 是否是object 类型 - @::
22
- function isObject(value: any): boolean
23
-
24
- // 是否是一个方法
25
- function isFunction(value: any): boolean
26
-
27
- // 是否是一个Map
28
- function isMap(value: any): boolean
29
-
30
- // 是否是一个Set 类型
31
- function isSet(value: any): boolean
32
-
33
- // 是否是一个Symbol 类型
34
- function isSymbol(value: any): boolean
35
- ```
36
-
37
- ### 复制文本的方法
38
-
39
- ```ts
40
- // 复制文本
41
- function copyText(text: string): void
42
- ```
43
-
44
- ### 阻塞进程方法
45
-
46
- ```ts
47
- // 阻塞进程
48
- function sleep(ms: number): void
49
- ```
50
-
51
- ### LocalStorage 存取
52
-
53
- ```ts
54
- // 向 localStorage 存数据
55
- function setLocalStorage(key: string, data: any)
56
-
57
- // 向 localStorage 取数据
58
- function getLocalStorage(key: string): any
59
-
60
- // 移除 localStorage 数据
61
- function removeLocalStorageKey(...args: string[])
62
- ```
63
-
64
- ### SessionStorage 存取
65
-
66
- ```ts
67
- // 向 sessionStorage 存数据
68
- function setSessionStorage(key: string, data: any)
69
-
70
- // 向 sessionStorage 取数据
71
- function getSessionStorage(key: string): any
72
-
73
- // 移除 sessionStorage 数据
74
- function removeSessionStorageKey(...args: string[])
75
- ```
76
-
77
- ### params 处理
78
-
79
- ```ts
80
- // 将字符串转成对象 {key:value}
81
- function decodeParams(queryString: string)
82
-
83
- // 将对象转成 ?key=value&key=value
84
- function encodeParams(query: Record<string, any>)
85
- ```
86
-
87
- ### 拉流、文件流下载
88
-
89
- ```ts
90
- // 下载文件流
91
- function downFile(stream: string | ArrayBuffer, name: string, mimeType: string = "text/plain;charset=utf-8")
92
-
93
- // 拉流且下载文件流
94
- function downStream(path: string, defaultName: string, token?: string, params?: Record<string, any>)
95
- ```
96
-
97
- ### 数组处理方法
98
-
99
- ```ts
100
- // 根据key 类型数据去去重
101
- function uniqueArrayByProperty<T>(array: T[], key: keyof T): T[]
102
- ```
103
-
104
- ### Tree 数据处理
105
-
106
- ```ts
107
- // -> 扁平树
108
- function toFlatTree(origin: TreeData[])
109
-
110
- // 扁平树 -> 树
111
- function toTreeFlat<T extends TreeData>(origin: T[], parentId: number | string = "root")
112
-
113
- // 深拷贝
114
- function deepClone<T = any>(obj: T): T
115
-
116
- // 删除某个节点 纯函数
117
- function deleteTreeNode<T extends TreeData>(origin: T[], id: string | number, key: keyof T = "id"): T[]
118
-
119
- // 查找某个节点
120
- function findTreeNode<T extends TreeData>(origin: T[], findValue: any, key: keyof T = "id"): T | null
121
-
122
- // 模糊查询 树节点
123
- function fuzzySearchTree<T extends TreeData>(treeData: T[], findStr: string, label: keyof T = "title"): T[]
124
- ```
1
+ ## iota-tools
2
+
3
+ ### 类型判断:
4
+
5
+ ```ts
6
+ // 数据类型
7
+ function etTypeof(value: any): string
8
+
9
+ // 是否是数组
10
+ function isArray(value: any): boolean
11
+
12
+ // 是否是布尔值
13
+ function isBoolean(value: any): boolean
14
+
15
+ // 是否是字符串类型
16
+ function isString(value: any): boolean
17
+
18
+ // 是否是数字
19
+ function isNumber(value: any): boolean
20
+
21
+ // 是否是object 类型 - @::
22
+ function isObject(value: any): boolean
23
+
24
+ // 是否是一个方法
25
+ function isFunction(value: any): boolean
26
+
27
+ // 是否是一个Map
28
+ function isMap(value: any): boolean
29
+
30
+ // 是否是一个Set 类型
31
+ function isSet(value: any): boolean
32
+
33
+ // 是否是一个Symbol 类型
34
+ function isSymbol(value: any): boolean
35
+ ```
36
+
37
+ ### 复制文本的方法
38
+
39
+ ```ts
40
+ // 复制文本
41
+ function copyText(text: string): void
42
+ ```
43
+
44
+ ### 阻塞进程方法
45
+
46
+ ```ts
47
+ // 进程阻塞
48
+ function sleep(ms: number): void
49
+ ```
50
+
51
+ ### LocalStorage 存取
52
+
53
+ ```ts
54
+ // 向 localStorage 存数据
55
+ function setLocalStorage(key: string, data: any)
56
+
57
+ // 向 localStorage 取数据
58
+ function getLocalStorage(key: string): any
59
+
60
+ // 移除 localStorage 数据
61
+ function removeLocalStorageKey(...args: string[])
62
+ ```
63
+
64
+ ### SessionStorage 存取
65
+
66
+ ```ts
67
+ // 向 sessionStorage 存数据
68
+ function setSessionStorage(key: string, data: any)
69
+
70
+ // 向 sessionStorage 取数据
71
+ function getSessionStorage(key: string): any
72
+
73
+ // 移除 sessionStorage 数据
74
+ function removeSessionStorageKey(...args: string[])
75
+ ```
76
+
77
+ ### 拉流、文件流下载
78
+
79
+ ```ts
80
+ // 下载文件流
81
+ function downFile(stream: string | ArrayBuffer, name: string, mimeType: string = "text/plain;charset=utf-8")
82
+
83
+ // 拉流且下载文件流
84
+ function downStream(path: string, defaultName: string, token?: string, params?: Record<string, any>)
85
+ ```
86
+
87
+ ### 数组处理方法
88
+
89
+ ```ts
90
+ // 根据key 类型数据去去重
91
+ function uniqueArrayByProperty<T>(array: T[], key: keyof T): T[]
92
+ ```
93
+
94
+ ### object 数据处理
95
+
96
+ ```ts
97
+ // 对象扁平话
98
+ function flattenObject(obj: any, parentKey: string = "", res: any = {})
99
+
100
+ // 扁平反转
101
+ function unflattenObject(obj: any)
102
+ ```
103
+
104
+ ### 字符处理
105
+
106
+ ```ts
107
+ // 字符串format 替换
108
+ function format(str:string,...args:string[]):string
109
+
110
+ // 模版字符串替换
111
+ function templateReplace(str:string, data:Record<string,any>,egex: RegExp = /\(\((\w+)\)\)/g):string
112
+
113
+ // 将字符串转成对象 {key:value}
114
+ function decodeParams(queryString: string)
115
+
116
+ // 将对象转成 ?key=value&key=value
117
+ function encodeParams(query: Record<string, any>)
118
+ ```
119
+
120
+ ### Tree 数据处理
121
+
122
+ ```ts
123
+ // -> 扁平树
124
+ function toFlatTree(origin: TreeData[]
125
+
126
+ // 扁平树 -> 树
127
+ function toTreeFlat<T extends TreeData>(origin: T[], parentId: number | string = "root")
128
+
129
+ // 深拷贝
130
+ function deepClone<T = any>(obj: T): T
131
+
132
+ // 删除某个节点 纯函数
133
+ function deleteTreeNode<T extends TreeData>(origin: T[], id: string | number, key: keyof T = "id"): T[]
134
+
135
+ // 查找某个节点 - 返回同指针数据
136
+ function findTreeNode<T extends TreeData>(origin: T[], findValue: any, key: keyof T = "id"): T | null
137
+
138
+ // 模糊查询 树节点
139
+ function fuzzySearchTree<T extends TreeData>(treeData: T[], findStr: string, label: keyof T = "title"): T[]
140
+ ```
141
+
142
+ ### 异步
143
+
144
+ ```ts
145
+ // promsie 借鉴awit-to的设计 向作者致敬
146
+ function awitto<T>(promise: Promise<T>): Promise<[any, T | null]>
147
+ ```
@@ -0,0 +1,30 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ /**
6
+ * @description: 深拷贝
7
+ * @param {any} obj
8
+ * @return {*} obj
9
+ */
10
+ const deepClone = (obj) => {
11
+ if (obj === null || typeof obj !== "object") {
12
+ return obj;
13
+ }
14
+ if (Array.isArray(obj)) {
15
+ const arrCopy = [];
16
+ for (const item of obj) {
17
+ arrCopy.push(deepClone(item));
18
+ }
19
+ return arrCopy;
20
+ }
21
+ const objCopy = {};
22
+ for (const key in obj) {
23
+ if (obj.hasOwnProperty(key)) {
24
+ objCopy[key] = deepClone(obj[key]);
25
+ }
26
+ }
27
+ return objCopy;
28
+ };
29
+
30
+ exports.deepClone = deepClone;
@@ -0,0 +1,20 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ /**
6
+ * @description: 过滤筛选树 -- search tree
7
+ * @param origin 数据源
8
+ * @param id
9
+ * @return new tree data 纯函数
10
+ */
11
+ function deleteTreeNode(origin, id, key = "id") {
12
+ return origin.filter((node) => {
13
+ if (node.children) {
14
+ node.children = deleteTreeNode(node.children, id, key);
15
+ }
16
+ return node[key] !== id;
17
+ });
18
+ }
19
+
20
+ exports.deleteTreeNode = deleteTreeNode;
@@ -0,0 +1,32 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ /**
6
+ * @description: 查找树节点
7
+ * @param origin 数据源
8
+ * @param findValue 找到节点
9
+ * @param key 默认id
10
+ * @return T
11
+ */
12
+ function findTreeNode(origin, findValue, key = "id") {
13
+ let result = null;
14
+ const fun = (data) => {
15
+ if (Array.isArray(data)) {
16
+ for (let i = 0; i < data.length; i++) {
17
+ let item = data[i];
18
+ if (item[key] === findValue) {
19
+ result = item;
20
+ return;
21
+ }
22
+ if (item.children && item.children.length) {
23
+ fun(item.children);
24
+ }
25
+ }
26
+ }
27
+ };
28
+ fun(origin);
29
+ return result;
30
+ }
31
+
32
+ exports.findTreeNode = findTreeNode;
@@ -0,0 +1,40 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ /**
6
+ * @description: 过滤筛选树 -- search tree
7
+ * @param treeData 数据源
8
+ * @param findStr 关键字
9
+ * @param label 关键字段
10
+ * @return new tree data
11
+ */
12
+ const fuzzySearchTree = (treeData, findStr, label = "title") => {
13
+ if (!treeData)
14
+ return [];
15
+ let list = [];
16
+ treeData.forEach((item) => {
17
+ // 确保label属性是字符串并且包含findStr
18
+ if (typeof item[label] === "string" && item[label].includes(findStr)) {
19
+ // 递归处理子节点
20
+ let children = item.children ? fuzzySearchTree(item.children, findStr, label) : [];
21
+ // 如果子节点中没有匹配的项,则保留原子节点
22
+ children = children.length > 0 ? children : item.children;
23
+ // 构造新的节点,保留匹配的子节点
24
+ const obj = { ...item, children };
25
+ list.push(obj);
26
+ }
27
+ else if (item.children && item.children.length > 0) {
28
+ // 如果当前节点不匹配,但有子节点,则递归处理子节点
29
+ const children = fuzzySearchTree(item.children, findStr, label);
30
+ // 如果子节点中有匹配的项,则保留当前节点,并更新其子节点
31
+ if (children.length > 0) {
32
+ const obj = { ...item, children };
33
+ list.push(obj);
34
+ }
35
+ }
36
+ });
37
+ return list;
38
+ };
39
+
40
+ exports.fuzzySearchTree = fuzzySearchTree;
@@ -0,0 +1,17 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ /**
6
+ * @description: tree data -> 扁平树
7
+ * @param origin 数据源
8
+ * @return treedata
9
+ */
10
+ function toFlatTree(origin) {
11
+ return origin.reduce((res, item) => {
12
+ const { children, ...i } = item;
13
+ return res.concat(i, children && children.length ? toFlatTree(children) : []);
14
+ }, []);
15
+ }
16
+
17
+ exports.toFlatTree = toFlatTree;
@@ -0,0 +1,25 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ /**
6
+ * @description: 扁平树 -> tree data
7
+ * @param origins 数据源
8
+ * @param parentId 父级ID
9
+ * @return 平铺数据
10
+ */
11
+ function toTreeFlat(origin, parentId = "root") {
12
+ // treeArr 变量数据
13
+ // 第一次:查找所有parentId为的数据组成第一级
14
+ const child = origin.filter((item) => item.parentId === parentId);
15
+ // 第一次:循环parentId为数组
16
+ return child.map((item) => {
17
+ return {
18
+ ...item,
19
+ // 当前存在id(id与parentId应该是必须有的)调用initTree() 查找所有parentId为本id的数据
20
+ children: toTreeFlat(origin, item.id),
21
+ };
22
+ });
23
+ }
24
+
25
+ exports.toTreeFlat = toTreeFlat;
@@ -0,0 +1,33 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ /**
6
+ * @description: 下载文件
7
+ * @param stream 文件源,string or buffer
8
+ * @param name 文件名称
9
+ * @param mimeType type josn
10
+ * @return new tree data 纯函数
11
+ */
12
+ const downFile = (stream, name, mimeType = "text/plain;charset=utf-8") => {
13
+ // 创建 Blob 对象
14
+ let blob;
15
+ if (typeof stream === "string") {
16
+ blob = new Blob([stream], { type: mimeType });
17
+ }
18
+ else {
19
+ blob = new Blob([stream], { type: mimeType });
20
+ }
21
+ // 创建下载链接并触发下载
22
+ const a = document.createElement("a");
23
+ a.href = URL.createObjectURL(blob);
24
+ a.download = name;
25
+ a.style.display = "none";
26
+ document.body.appendChild(a);
27
+ a.click();
28
+ document.body.removeChild(a);
29
+ // 清理创建的 URL 对象
30
+ URL.revokeObjectURL(a.href);
31
+ };
32
+
33
+ exports.downFile = downFile;
@@ -0,0 +1,48 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ var downFile = require('./downFile.js');
6
+
7
+ /**
8
+ * @description: 拉流下载方法
9
+ * @param path 下载url
10
+ * @param defaultName 匹配请求如果没有使用名称
11
+ * @param token 鉴权 Authorization
12
+ * @param params 参数 object
13
+ */
14
+ const downStream = (path, defaultName, token, params) => {
15
+ // 处理查询参数
16
+ const queryParams = new URLSearchParams(params).toString();
17
+ const urlWithParams = queryParams ? `${path}?${queryParams}` : path;
18
+ const xhr = new XMLHttpRequest();
19
+ xhr.open("GET", urlWithParams);
20
+ xhr.responseType = "blob";
21
+ if (token)
22
+ xhr.setRequestHeader("Authorization", token);
23
+ xhr.onload = function () {
24
+ if (xhr.status === 200 || xhr.status === 304) {
25
+ const disposition = xhr.getResponseHeader("Content-Disposition");
26
+ let filename = defaultName;
27
+ // 从 Content-Disposition 中提取文件名
28
+ if (disposition && disposition.indexOf("attachment") !== -1) {
29
+ const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
30
+ const matches = filenameRegex.exec(disposition);
31
+ if (matches != null && matches[1]) {
32
+ filename = matches[1].replace(/['"]/g, "");
33
+ }
34
+ }
35
+ // 下载文件
36
+ downFile.downFile(this.response, filename);
37
+ }
38
+ else {
39
+ console.error(`Failed to download file. Status: ${xhr.status}`);
40
+ }
41
+ };
42
+ xhr.onerror = function () {
43
+ console.error("Request failed.");
44
+ };
45
+ xhr.send();
46
+ };
47
+
48
+ exports.downStream = downStream;
@@ -0,0 +1,57 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ var index = require('./storage/index.js');
6
+ var _typeof = require('./utools/typeof.js');
7
+ var sleep = require('./utools/sleep.js');
8
+ var copyText = require('./utools/copyText.js');
9
+ var debounce = require('./utools/debounce.js');
10
+ var throttle = require('./utools/throttle.js');
11
+ var downFile = require('./fileStream/downFile.js');
12
+ var downStream = require('./fileStream/downStream.js');
13
+ var toFlatTree = require('./datatree/toFlatTree.js');
14
+ var toTreeFlat = require('./datatree/toTreeFlat.js');
15
+ var findTreeNode = require('./datatree/findTreeNode.js');
16
+ var fuzzySearchTree = require('./datatree/fuzzySearchTree.js');
17
+ var deleteTreeNode = require('./datatree/deleteTreeNode.js');
18
+ var deepClone = require('./datatree/deepClone.js');
19
+ var generateUUID = require('./uuid/generateUUID.js');
20
+ var generateString = require('./uuid/generateString.js');
21
+ var local = require('./storage/local.js');
22
+ var session = require('./storage/session.js');
23
+
24
+
25
+
26
+ exports.monitorLocalStorage = index.monitorLocalStorage;
27
+ exports.monitorSessionStorage = index.monitorSessionStorage;
28
+ exports.getTypeof = _typeof.getTypeof;
29
+ exports.isArray = _typeof.isArray;
30
+ exports.isBoolean = _typeof.isBoolean;
31
+ exports.isFunction = _typeof.isFunction;
32
+ exports.isMap = _typeof.isMap;
33
+ exports.isNumber = _typeof.isNumber;
34
+ exports.isObject = _typeof.isObject;
35
+ exports.isSet = _typeof.isSet;
36
+ exports.isString = _typeof.isString;
37
+ exports.isSymbol = _typeof.isSymbol;
38
+ exports.sleep = sleep.sleep;
39
+ exports.copyText = copyText.copyText;
40
+ exports.debounce = debounce.debounce;
41
+ exports.throttle = throttle.throttle;
42
+ exports.downFile = downFile.downFile;
43
+ exports.downStream = downStream.downStream;
44
+ exports.toFlatTree = toFlatTree.toFlatTree;
45
+ exports.toTreeFlat = toTreeFlat.toTreeFlat;
46
+ exports.findTreeNode = findTreeNode.findTreeNode;
47
+ exports.fuzzySearchTree = fuzzySearchTree.fuzzySearchTree;
48
+ exports.deleteTreeNode = deleteTreeNode.deleteTreeNode;
49
+ exports.deepClone = deepClone.deepClone;
50
+ exports.generateUUID = generateUUID.generateUUID;
51
+ exports.generateString = generateString.generateString;
52
+ exports.getLocalStorage = local.getLocalStorage;
53
+ exports.removeLocalStorageKey = local.removeLocalStorageKey;
54
+ exports.setLocalStorage = local.setLocalStorage;
55
+ exports.getSessionStorage = session.getSessionStorage;
56
+ exports.removeSessionStorageKey = session.removeSessionStorageKey;
57
+ exports.setSessionStorage = session.setSessionStorage;
@@ -5,3 +5,8 @@
5
5
  */
6
6
  export * from "./local";
7
7
  export * from "./session";
8
+ export declare const monitorLocalStorage: () => void;
9
+ /**
10
+ * @这个方法实际没多大用
11
+ */
12
+ export declare const monitorSessionStorage: () => void;
@@ -0,0 +1,50 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ 'use strict';
4
+
5
+ /**
6
+ * @web 环境下才能使用注册
7
+ * 包含了storage 增删改查封装 存储监听等功能
8
+ * 监听的方式使用的浏览器evet 事件模型
9
+ */
10
+ // init envet storage change
11
+ const monitorLocalStorage = () => {
12
+ let originalSetItem = localStorage.setItem;
13
+ //重写setItem函数
14
+ localStorage.setItem = function (key, newValue) {
15
+ //创建setItemEvent事件
16
+ let event = new Event("localStorage");
17
+ event.key = key;
18
+ event.newValue = newValue;
19
+ //提交setItemEvent事件
20
+ window.dispatchEvent(event);
21
+ //执行原setItem函数
22
+ originalSetItem.call(this, key, newValue);
23
+ };
24
+ };
25
+ /**
26
+ * @这个方法实际没多大用
27
+ */
28
+ const monitorSessionStorage = () => {
29
+ let originalSetItem = sessionStorage.setItem;
30
+ //重写setItem函数
31
+ sessionStorage.setItem = function (key, newValue) {
32
+ //创建setItemEvent事件
33
+ let event = new Event("sessionStorage");
34
+ event.key = key;
35
+ event.newValue = newValue;
36
+ //提交setItemEvent事件
37
+ window.dispatchEvent(event);
38
+ //执行原setItem函数
39
+ originalSetItem.call(this, key, newValue);
40
+ };
41
+ };
42
+ // 用于local 监听
43
+ const monitorStorage = () => {
44
+ monitorLocalStorage();
45
+ monitorSessionStorage();
46
+ };
47
+ monitorStorage();
48
+
49
+ exports.monitorLocalStorage = monitorLocalStorage;
50
+ exports.monitorSessionStorage = monitorSessionStorage;