sculp-js 1.11.1-alpha.3 → 1.13.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 (63) hide show
  1. package/lib/cjs/array.js +1 -1
  2. package/lib/cjs/async.js +32 -1
  3. package/lib/cjs/base64.js +1 -1
  4. package/lib/cjs/clipboard.js +5 -3
  5. package/lib/cjs/cloneDeep.js +1 -1
  6. package/lib/cjs/cookie.js +1 -1
  7. package/lib/cjs/date.js +1 -1
  8. package/lib/cjs/dom.js +1 -1
  9. package/lib/cjs/download.js +1 -1
  10. package/lib/cjs/easing.js +1 -1
  11. package/lib/cjs/file.js +1 -1
  12. package/lib/cjs/func.js +1 -1
  13. package/lib/cjs/index.js +2 -1
  14. package/lib/cjs/isEqual.js +1 -1
  15. package/lib/cjs/math.js +1 -1
  16. package/lib/cjs/number.js +1 -1
  17. package/lib/cjs/object.js +1 -1
  18. package/lib/cjs/path.js +1 -1
  19. package/lib/cjs/qs.js +1 -1
  20. package/lib/cjs/random.js +1 -1
  21. package/lib/cjs/string.js +1 -1
  22. package/lib/cjs/tooltip.js +1 -1
  23. package/lib/cjs/tree.js +126 -52
  24. package/lib/cjs/type.js +1 -1
  25. package/lib/cjs/unique.js +1 -1
  26. package/lib/cjs/url.js +1 -1
  27. package/lib/cjs/validator.js +1 -1
  28. package/lib/cjs/variable.js +1 -1
  29. package/lib/cjs/watermark.js +1 -1
  30. package/lib/cjs/we-decode.js +1 -1
  31. package/lib/es/array.js +1 -1
  32. package/lib/es/async.js +32 -2
  33. package/lib/es/base64.js +1 -1
  34. package/lib/es/clipboard.js +5 -3
  35. package/lib/es/cloneDeep.js +1 -1
  36. package/lib/es/cookie.js +1 -1
  37. package/lib/es/date.js +1 -1
  38. package/lib/es/dom.js +1 -1
  39. package/lib/es/download.js +1 -1
  40. package/lib/es/easing.js +1 -1
  41. package/lib/es/file.js +1 -1
  42. package/lib/es/func.js +1 -1
  43. package/lib/es/index.js +2 -2
  44. package/lib/es/isEqual.js +1 -1
  45. package/lib/es/math.js +1 -1
  46. package/lib/es/number.js +1 -1
  47. package/lib/es/object.js +1 -1
  48. package/lib/es/path.js +1 -1
  49. package/lib/es/qs.js +1 -1
  50. package/lib/es/random.js +1 -1
  51. package/lib/es/string.js +1 -1
  52. package/lib/es/tooltip.js +1 -1
  53. package/lib/es/tree.js +127 -53
  54. package/lib/es/type.js +1 -1
  55. package/lib/es/unique.js +1 -1
  56. package/lib/es/url.js +1 -1
  57. package/lib/es/validator.js +1 -1
  58. package/lib/es/variable.js +1 -1
  59. package/lib/es/watermark.js +1 -1
  60. package/lib/es/we-decode.js +1 -1
  61. package/lib/index.d.ts +72 -12
  62. package/lib/umd/index.js +2 -2
  63. package/package.json +3 -4
package/lib/cjs/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -58,6 +58,37 @@ function asyncMap(list, mapper, concurrency = Infinity) {
58
58
  }
59
59
  });
60
60
  }
61
+ /**
62
+ * Execute a promise safely
63
+ *
64
+ * @param { Promise } promise
65
+ * @param { Object= } errorExt - Additional Information you can pass safeAwait the err object
66
+ * @return { Promise }
67
+ * @example
68
+ * async function asyncTaskWithCb(cb) {
69
+ let err, user, savedTask, notification;
70
+
71
+ [ err, user ] = await safeAwait(UserModel.findById(1));
72
+ if(!user) return cb('No user found');
73
+
74
+ [ err, savedTask ] = await safeAwait(TaskModel({userId: user.id, name: 'Demo Task'}));
75
+ if(err) return cb('Error occurred while saving task')
76
+
77
+ cb(null, savedTask);
78
+ }
79
+ */
80
+ function safeAwait(promise, errorExt) {
81
+ return promise
82
+ .then((data) => [null, data])
83
+ .catch((err) => {
84
+ if (errorExt) {
85
+ const parsedError = Object.assign({}, err, errorExt);
86
+ return [parsedError, undefined];
87
+ }
88
+ return [err, undefined];
89
+ });
90
+ }
61
91
 
62
92
  exports.asyncMap = asyncMap;
93
+ exports.safeAwait = safeAwait;
63
94
  exports.wait = wait;
package/lib/cjs/base64.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -10,9 +10,11 @@ var dom = require('./dom.js');
10
10
  var type = require('./type.js');
11
11
 
12
12
  /**
13
- * 复制文本,优先使用navigator.clipboard,若不支持则回退使用execCommand方式
13
+ * 复制文本,优先使用navigator.clipboard,仅在安全上下文(HTTPS/localhost)下生效,若不支持则回退使用execCommand方式
14
14
  * @param {string} text
15
- * @param {AsyncCallback} options 可选参数:成功回调、失败回调、容器元素
15
+ * @param {CopyTextOptions} options 可选参数:成功回调successCallback、失败回调failCallback、容器元素container
16
+ * (默认document.body, 当不支持clipboard时必须传复制按钮元素,包裹模拟选择操作的临时元素,
17
+ * 解决脱离文档流的元素无法复制的问题,如Modal内复制操作)
16
18
  */
17
19
  function copyText(text, options) {
18
20
  const { successCallback = void 0, failCallback = void 0 } = type.isNullOrUnDef(options) ? {} : options;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -118,6 +118,7 @@ exports.urlParse = url.urlParse;
118
118
  exports.urlSetParams = url.urlSetParams;
119
119
  exports.urlStringify = url.urlStringify;
120
120
  exports.asyncMap = async.asyncMap;
121
+ exports.safeAwait = async.safeAwait;
121
122
  exports.wait = async.wait;
122
123
  exports.chooseLocalFile = file.chooseLocalFile;
123
124
  exports.compressImg = file.compressImg;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/math.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/string.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/tree.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  'use strict';
8
8
 
9
- var array = require('./array.js');
10
9
  var object = require('./object.js');
11
10
  var type = require('./type.js');
12
11
 
@@ -18,58 +17,126 @@ const defaultSearchTreeOptions = {
18
17
  ignoreCase: true
19
18
  };
20
19
  /**
21
- * 深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
20
+ * 树遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
22
21
  * @param {ArrayLike<V>} tree 树形数据
23
22
  * @param {Function} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
24
- * @param {string} children 定制子元素的key
25
- * @param {boolean} isReverse 是否反向遍历
23
+ * @param {options} options 支持定制子元素名称、反向遍历、广度优先遍历,默认{
24
+ childField: 'children',
25
+ reverse: false,
26
+ breadthFirst: false
27
+ }
26
28
  * @returns {*}
27
29
  */
28
- function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
30
+ function forEachDeep(tree, iterator, options = {
31
+ childField: 'children',
32
+ reverse: false,
33
+ breadthFirst: false
34
+ }) {
35
+ const { childField = 'children', reverse = false, breadthFirst = false } = type.isObject(options) ? options : {};
29
36
  let isBreak = false;
37
+ const queue = [];
30
38
  const walk = (arr, parent, level = 0) => {
31
- if (isReverse) {
32
- for (let i = arr.length - 1; i >= 0; i--) {
39
+ if (reverse) {
40
+ for (let index = arr.length - 1; index >= 0; index--) {
33
41
  if (isBreak) {
34
42
  break;
35
43
  }
36
- const re = iterator(arr[i], i, arr, tree, parent, level);
37
- if (re === false) {
38
- isBreak = true;
39
- break;
44
+ const item = arr[index];
45
+ // 广度优先
46
+ if (breadthFirst) {
47
+ queue.push({ item, index, array: arr, tree, parent, level });
40
48
  }
41
- else if (re === true) {
42
- continue;
49
+ else {
50
+ const re = iterator(item, index, arr, tree, parent, level);
51
+ if (re === false) {
52
+ isBreak = true;
53
+ break;
54
+ }
55
+ else if (re === true) {
56
+ continue;
57
+ }
58
+ // @ts-ignore
59
+ if (item && Array.isArray(item[childField])) {
60
+ // @ts-ignore
61
+ walk(item[childField], item, level + 1);
62
+ }
43
63
  }
44
- // @ts-ignore
45
- if (arr[i] && Array.isArray(arr[i][children])) {
64
+ }
65
+ if (breadthFirst) {
66
+ // Process queue
67
+ while (!isBreak) {
68
+ const current = queue.shift();
69
+ // iterate(info);
70
+ // @ts-ignore
71
+ const { item, index, array, tree, parent, level } = current;
72
+ const re = iterator(item, index, array, tree, parent, level);
73
+ if (re === false) {
74
+ isBreak = true;
75
+ break;
76
+ }
77
+ else if (re === true) {
78
+ continue;
79
+ }
46
80
  // @ts-ignore
47
- walk(arr[i][children], arr[i], level + 1);
81
+ if (item && Array.isArray(item[childField])) {
82
+ // @ts-ignore
83
+ walk(item[childField], item, level + 1);
84
+ }
48
85
  }
49
86
  }
50
87
  }
51
88
  else {
52
- for (let i = 0, len = arr.length; i < len; i++) {
89
+ for (let index = 0, len = arr.length; index < len; index++) {
53
90
  if (isBreak) {
54
91
  break;
55
92
  }
56
- const re = iterator(arr[i], i, arr, tree, parent, level);
57
- if (re === false) {
58
- isBreak = true;
59
- break;
93
+ const item = arr[index];
94
+ if (breadthFirst) {
95
+ // 广度优先
96
+ queue.push({ item, index: index, array: arr, tree, parent, level });
60
97
  }
61
- else if (re === true) {
62
- continue;
98
+ else {
99
+ // 深度优先
100
+ const re = iterator(item, index, arr, tree, parent, level);
101
+ if (re === false) {
102
+ isBreak = true;
103
+ break;
104
+ }
105
+ else if (re === true) {
106
+ continue;
107
+ }
108
+ // @ts-ignore
109
+ if (item && Array.isArray(item[childField])) {
110
+ // @ts-ignore
111
+ walk(item[childField], item, level + 1);
112
+ }
63
113
  }
64
- // @ts-ignore
65
- if (arr[i] && Array.isArray(arr[i][children])) {
114
+ }
115
+ if (breadthFirst) {
116
+ while (!isBreak) {
117
+ const current = queue.shift();
118
+ if (!current)
119
+ break;
120
+ // @ts-ignore
121
+ const { item, index, array, tree, parent, level } = current;
122
+ const re = iterator(item, index, array, tree, parent, level);
123
+ if (re === false) {
124
+ isBreak = true;
125
+ break;
126
+ }
127
+ else if (re === true) {
128
+ continue;
129
+ }
66
130
  // @ts-ignore
67
- walk(arr[i][children], arr[i], level + 1);
131
+ if (item && Array.isArray(item[childField])) {
132
+ // @ts-ignore
133
+ walk(item[childField], item, level + 1);
134
+ }
68
135
  }
69
136
  }
70
137
  }
71
138
  };
72
- walk(tree, null);
139
+ walk(tree, null, 0);
73
140
  // @ts-ignore
74
141
  tree = null;
75
142
  }
@@ -181,17 +248,20 @@ function searchTreeById(tree, nodeId, config) {
181
248
  /**
182
249
  * 扁平化数组转换成树
183
250
  * @param {any[]} list
184
- * @param {IFieldOptions} options
251
+ * @param {IFieldOptions} options 定制id字段名,子元素字段名,父元素字段名,默认
252
+ * { keyField: 'key', childField: 'children', pidField: 'pid' }
185
253
  * @returns {any[]}
186
254
  */
187
255
  function formatTree(list, options = defaultFieldOptions) {
188
- const { keyField, childField, pidField } = options;
256
+ const { keyField = 'key', childField = 'children', pidField = 'pid' } = type.isObject(options) ? options : {};
189
257
  const treeArr = [];
190
258
  const sourceMap = {};
191
- array.arrayEach(list, item => {
259
+ for (let i = 0, len = list.length; i < len; i++) {
260
+ const item = list[i];
192
261
  sourceMap[item[keyField]] = item;
193
- });
194
- array.arrayEach(list, item => {
262
+ }
263
+ for (let i = 0, len = list.length; i < len; i++) {
264
+ const item = list[i];
195
265
  const parent = sourceMap[item[pidField]];
196
266
  if (parent) {
197
267
  (parent[childField] || (parent[childField] = [])).push(item);
@@ -199,21 +269,23 @@ function formatTree(list, options = defaultFieldOptions) {
199
269
  else {
200
270
  treeArr.push(item);
201
271
  }
202
- });
272
+ }
203
273
  // @ts-ignore
204
274
  list = null;
205
275
  return treeArr;
206
276
  }
207
277
  /**
208
278
  * 树形结构转扁平化
209
- * @param {any} treeList
210
- * @param {IFieldOptions} options
211
- * @returns {*}
279
+ * @param {any[]} treeList
280
+ * @param {IFieldOptions} options 定制id字段名,子元素字段名,父元素字段名,默认
281
+ * { keyField: 'key', childField: 'children', pidField: 'pid' }
282
+ * @returns {any[]}
212
283
  */
213
284
  function flatTree(treeList, options = defaultFieldOptions) {
214
- const { childField, keyField, pidField } = options;
285
+ const { keyField = 'key', childField = 'children', pidField = 'pid' } = type.isObject(options) ? options : {};
215
286
  let res = [];
216
- array.arrayEach(treeList, node => {
287
+ for (let i = 0, len = treeList.length; i < len; i++) {
288
+ const node = treeList[i];
217
289
  const item = {
218
290
  ...node,
219
291
  [childField]: [] // 清空子级
@@ -227,7 +299,7 @@ function flatTree(treeList, options = defaultFieldOptions) {
227
299
  }));
228
300
  res = res.concat(flatTree(children, options));
229
301
  }
230
- });
302
+ }
231
303
  return res;
232
304
  }
233
305
  /**
@@ -241,7 +313,12 @@ function flatTree(treeList, options = defaultFieldOptions) {
241
313
  * 2. 若无任何过滤条件或keyword模式匹配且keyword为空串,返回原对象;其他情况返回新数组
242
314
  * @param {V[]} nodes
243
315
  * @param {IFilterCondition} filterCondition
244
- * @param {ISearchTreeOpts} options
316
+ * @param {ISearchTreeOpts} options 默认配置项 {
317
+ childField: 'children',
318
+ nameField: 'name',
319
+ removeEmptyChild: false,
320
+ ignoreCase: true
321
+ }
245
322
  * @returns {V[]}
246
323
  */
247
324
  function fuzzySearchTree(nodes, filterCondition, options = defaultSearchTreeOptions) {
@@ -250,7 +327,8 @@ function fuzzySearchTree(nodes, filterCondition, options = defaultSearchTreeOpti
250
327
  return nodes;
251
328
  }
252
329
  const result = [];
253
- array.arrayEach(nodes, node => {
330
+ for (let i = 0, len = nodes.length; i < len; i++) {
331
+ const node = nodes[i];
254
332
  // 递归检查子节点是否匹配
255
333
  const matchedChildren = node[options.childField] && node[options.childField].length > 0
256
334
  ? fuzzySearchTree(node[options.childField] || [], filterCondition, options)
@@ -271,26 +349,22 @@ function fuzzySearchTree(nodes, filterCondition, options = defaultSearchTreeOpti
271
349
  });
272
350
  }
273
351
  else if (options.removeEmptyChild) {
274
- node[options.childField] && delete node[options.childField];
275
- result.push({
276
- ...node
277
- });
352
+ const { [options.childField]: _, ...other } = node;
353
+ result.push(other);
278
354
  }
279
355
  else {
280
356
  result.push({
281
357
  ...node,
282
- ...{ [options.childField]: [] }
358
+ [options.childField]: []
283
359
  });
284
360
  }
285
361
  }
286
362
  else {
287
- node[options.childField] && delete node[options.childField];
288
- result.push({
289
- ...node
290
- });
363
+ const { [options.childField]: _, ...other } = node;
364
+ result.push(other);
291
365
  }
292
366
  }
293
- });
367
+ }
294
368
  return result;
295
369
  }
296
370
 
package/lib/cjs/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -56,5 +56,35 @@ function asyncMap(list, mapper, concurrency = Infinity) {
56
56
  }
57
57
  });
58
58
  }
59
+ /**
60
+ * Execute a promise safely
61
+ *
62
+ * @param { Promise } promise
63
+ * @param { Object= } errorExt - Additional Information you can pass safeAwait the err object
64
+ * @return { Promise }
65
+ * @example
66
+ * async function asyncTaskWithCb(cb) {
67
+ let err, user, savedTask, notification;
68
+
69
+ [ err, user ] = await safeAwait(UserModel.findById(1));
70
+ if(!user) return cb('No user found');
71
+
72
+ [ err, savedTask ] = await safeAwait(TaskModel({userId: user.id, name: 'Demo Task'}));
73
+ if(err) return cb('Error occurred while saving task')
74
+
75
+ cb(null, savedTask);
76
+ }
77
+ */
78
+ function safeAwait(promise, errorExt) {
79
+ return promise
80
+ .then((data) => [null, data])
81
+ .catch((err) => {
82
+ if (errorExt) {
83
+ const parsedError = Object.assign({}, err, errorExt);
84
+ return [parsedError, undefined];
85
+ }
86
+ return [err, undefined];
87
+ });
88
+ }
59
89
 
60
- export { asyncMap, wait };
90
+ export { asyncMap, safeAwait, wait };
package/lib/es/base64.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,9 +8,11 @@ import { select } from './dom.js';
8
8
  import { isFunction, isNullOrUnDef } from './type.js';
9
9
 
10
10
  /**
11
- * 复制文本,优先使用navigator.clipboard,若不支持则回退使用execCommand方式
11
+ * 复制文本,优先使用navigator.clipboard,仅在安全上下文(HTTPS/localhost)下生效,若不支持则回退使用execCommand方式
12
12
  * @param {string} text
13
- * @param {AsyncCallback} options 可选参数:成功回调、失败回调、容器元素
13
+ * @param {CopyTextOptions} options 可选参数:成功回调successCallback、失败回调failCallback、容器元素container
14
+ * (默认document.body, 当不支持clipboard时必须传复制按钮元素,包裹模拟选择操作的临时元素,
15
+ * 解决脱离文档流的元素无法复制的问题,如Modal内复制操作)
14
16
  */
15
17
  function copyText(text, options) {
16
18
  const { successCallback = void 0, failCallback = void 0 } = isNullOrUnDef(options) ? {} : options;