sculp-js 1.7.2 → 1.8.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 (60) hide show
  1. package/README.md +5 -3
  2. package/lib/cjs/array.js +1 -1
  3. package/lib/cjs/async.js +1 -1
  4. package/lib/cjs/base64.js +1 -1
  5. package/lib/cjs/clipboard.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 -28
  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 +3 -4
  14. package/lib/cjs/math.js +1 -1
  15. package/lib/cjs/number.js +1 -1
  16. package/lib/cjs/object.js +130 -1
  17. package/lib/cjs/path.js +1 -1
  18. package/lib/cjs/qs.js +1 -1
  19. package/lib/cjs/random.js +1 -1
  20. package/lib/cjs/string.js +1 -1
  21. package/lib/cjs/tooltip.js +1 -1
  22. package/lib/cjs/tree.js +1 -87
  23. package/lib/cjs/type.js +11 -4
  24. package/lib/cjs/unique.js +1 -1
  25. package/lib/cjs/url.js +1 -1
  26. package/lib/cjs/validator.js +1 -1
  27. package/lib/cjs/variable.js +1 -1
  28. package/lib/cjs/watermark.js +1 -1
  29. package/lib/cjs/we-decode.js +1 -1
  30. package/lib/es/array.js +1 -1
  31. package/lib/es/async.js +1 -1
  32. package/lib/es/base64.js +1 -1
  33. package/lib/es/clipboard.js +1 -1
  34. package/lib/es/cookie.js +1 -1
  35. package/lib/es/date.js +1 -1
  36. package/lib/es/dom.js +2 -27
  37. package/lib/es/download.js +1 -1
  38. package/lib/es/easing.js +1 -1
  39. package/lib/es/file.js +1 -1
  40. package/lib/es/func.js +1 -1
  41. package/lib/es/index.js +5 -5
  42. package/lib/es/math.js +1 -1
  43. package/lib/es/number.js +1 -1
  44. package/lib/es/object.js +130 -2
  45. package/lib/es/path.js +1 -1
  46. package/lib/es/qs.js +1 -1
  47. package/lib/es/random.js +1 -1
  48. package/lib/es/string.js +1 -1
  49. package/lib/es/tooltip.js +1 -1
  50. package/lib/es/tree.js +2 -87
  51. package/lib/es/type.js +11 -5
  52. package/lib/es/unique.js +1 -1
  53. package/lib/es/url.js +1 -1
  54. package/lib/es/validator.js +1 -1
  55. package/lib/es/variable.js +1 -1
  56. package/lib/es/watermark.js +1 -1
  57. package/lib/es/we-decode.js +1 -1
  58. package/lib/index.d.ts +24 -46
  59. package/lib/umd/index.js +140 -117
  60. package/package.json +3 -10
package/lib/es/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -116,31 +116,6 @@ function smoothScroll(options) {
116
116
  render();
117
117
  });
118
118
  }
119
- const domReadyCallbacks = [];
120
- const eventType = 'DOMContentLoaded';
121
- const listener = () => {
122
- domReadyCallbacks.forEach(callback => callback());
123
- domReadyCallbacks.length = 0;
124
- document.removeEventListener(eventType, listener);
125
- };
126
- document.addEventListener(eventType, listener);
127
- let readied = false;
128
- function isDomReady() {
129
- if (readied)
130
- return true;
131
- readied = ['complete', 'loaded', 'interactive'].indexOf(document.readyState) !== -1;
132
- return readied;
133
- }
134
- function onDomReady(callback) {
135
- // document readied
136
- if (isDomReady()) {
137
- setTimeout(callback, 0);
138
- }
139
- // listen document to ready
140
- else {
141
- domReadyCallbacks.push(callback);
142
- }
143
- }
144
119
  /**
145
120
  * 获取元素样式属性的计算值
146
121
  * @param {HTMLElement} el
@@ -183,4 +158,4 @@ function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
183
158
  return strWidth;
184
159
  }
185
160
 
186
- export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll };
161
+ export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, removeClass, setStyle, smoothScroll };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,13 +8,13 @@ export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayRemove } from './arr
8
8
  export { copyText } from './clipboard.js';
9
9
  export { cookieDel, cookieGet, cookieSet } from './cookie.js';
10
10
  export { calculateDate, calculateDateTime, dateParse, dateToEnd, dateToStart, formatDate, isValidDate } from './date.js';
11
- export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll } from './dom.js';
11
+ export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, removeClass, setStyle, smoothScroll } from './dom.js';
12
12
  export { crossOriginDownload, downloadBlob, downloadData, downloadHref, downloadURL } from './download.js';
13
- export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectMap, objectAssign as objectMerge, objectOmit, objectPick } from './object.js';
13
+ export { cloneDeep, isEqual, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectMap, objectAssign as objectMerge, objectOmit, objectPick } from './object.js';
14
14
  export { pathJoin, pathNormalize } from './path.js';
15
15
  export { qsParse, qsStringify } from './qs.js';
16
16
  export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, parseQueryParams, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase } from './string.js';
17
- export { arrayLike, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, objectHas, typeIs } from './type.js';
17
+ export { arrayLike, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, objectHas, typeIs } from './type.js';
18
18
  export { urlDelParams, urlParse, urlSetParams, urlStringify } from './url.js';
19
19
  export { asyncMap, wait } from './async.js';
20
20
  export { chooseLocalFile, compressImg, supportCanvas } from './file.js';
@@ -24,7 +24,7 @@ export { STRING_POOL, randomNumber, randomString, randomUuid } from './random.js
24
24
  export { HEX_POOL, formatNumber, numberAbbr, numberToHex } from './number.js';
25
25
  export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.js';
26
26
  export { tooltipEvent } from './tooltip.js';
27
- export { buildTree, flatTree, forEachDeep, formatTree, fuzzySearchTree, mapDeep, searchTreeById } from './tree.js';
27
+ export { flatTree, forEachDeep, formatTree, fuzzySearchTree, mapDeep, searchTreeById } from './tree.js';
28
28
  export { add, divide, multiply, strip, subtract } from './math.js';
29
29
  export { weAtob, weBtoa } from './we-decode.js';
30
30
  export { decodeFromBase64, encodeToBase64 } from './base64.js';
package/lib/es/math.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -166,6 +166,13 @@ function objectFill(source, target, fillable) {
166
166
  });
167
167
  return source;
168
168
  }
169
+ /**
170
+ * 获取对象指定层级下的属性值(现在可用ES6+的可选链?.来替代)
171
+ * @param {AnyObject} obj
172
+ * @param {string} path
173
+ * @param {boolean} strict
174
+ * @returns
175
+ */
169
176
  function objectGet(obj, path, strict = false) {
170
177
  path = path.replace(/\[(\w+)\]/g, '.$1');
171
178
  path = path.replace(/^\./, '');
@@ -301,5 +308,126 @@ function cloneDeep(source, map = new WeakMap()) {
301
308
  }
302
309
  return copy;
303
310
  }
311
+ /**
312
+ * 比较两值是否相等,适用所有数据类型
313
+ * @param {Comparable} a
314
+ * @param {Comparable} b
315
+ * @returns {boolean}
316
+ */
317
+ function isEqual(a, b) {
318
+ return deepEqual(a, b);
319
+ }
320
+ function deepEqual(a, b, compared = new WeakMap()) {
321
+ // 相同值快速返回
322
+ if (Object.is(a, b))
323
+ return true;
324
+ // 类型不同直接返回false
325
+ const typeA = Object.prototype.toString.call(a);
326
+ const typeB = Object.prototype.toString.call(b);
327
+ if (typeA !== typeB)
328
+ return false;
329
+ // 只缓存对象类型
330
+ if (isObject(a) && isObject(b)) {
331
+ if (compared.has(a))
332
+ return compared.get(a) === b;
333
+ compared.set(a, b);
334
+ compared.set(b, a);
335
+ }
336
+ // 处理特殊对象类型
337
+ switch (typeA) {
338
+ case '[object Date]':
339
+ return a.getTime() === b.getTime();
340
+ case '[object RegExp]':
341
+ return a.toString() === b.toString();
342
+ case '[object Map]':
343
+ return compareMap(a, b, compared);
344
+ case '[object Set]':
345
+ return compareSet(a, b, compared);
346
+ case '[object ArrayBuffer]':
347
+ return compareArrayBuffer(a, b);
348
+ case '[object DataView]':
349
+ return compareDataView(a, b, compared);
350
+ case '[object Int8Array]':
351
+ case '[object Uint8Array]':
352
+ case '[object Uint8ClampedArray]':
353
+ case '[object Int16Array]':
354
+ case '[object Uint16Array]':
355
+ case '[object Int32Array]':
356
+ case '[object Uint32Array]':
357
+ case '[object Float32Array]':
358
+ case '[object Float64Array]':
359
+ return compareTypedArray(a, b, compared);
360
+ case '[object Object]':
361
+ return compareObjects(a, b, compared);
362
+ case '[object Array]':
363
+ return compareArrays(a, b, compared);
364
+ }
365
+ return false;
366
+ }
367
+ // 辅助比较函数
368
+ function compareMap(a, b, compared) {
369
+ if (a.size !== b.size)
370
+ return false;
371
+ for (const [key, value] of a) {
372
+ if (!b.has(key) || !deepEqual(value, b.get(key), compared))
373
+ return false;
374
+ }
375
+ return true;
376
+ }
377
+ function compareSet(a, b, compared) {
378
+ if (a.size !== b.size)
379
+ return false;
380
+ for (const value of a) {
381
+ let found = false;
382
+ for (const bValue of b) {
383
+ if (deepEqual(value, bValue, compared)) {
384
+ found = true;
385
+ break;
386
+ }
387
+ }
388
+ if (!found)
389
+ return false;
390
+ }
391
+ return true;
392
+ }
393
+ function compareArrayBuffer(a, b) {
394
+ if (a.byteLength !== b.byteLength)
395
+ return false;
396
+ return new DataView(a).getInt32(0) === new DataView(b).getInt32(0);
397
+ }
398
+ function compareDataView(a, b, compared) {
399
+ return a.byteLength === b.byteLength && deepEqual(new Uint8Array(a.buffer), new Uint8Array(b.buffer), compared);
400
+ }
401
+ function compareTypedArray(a, b, compared) {
402
+ return a.byteLength === b.byteLength && deepEqual(Array.from(a), Array.from(b), compared);
403
+ }
404
+ function compareObjects(a, b, compared) {
405
+ const keysA = Reflect.ownKeys(a);
406
+ const keysB = Reflect.ownKeys(b);
407
+ if (keysA.length !== keysB.length)
408
+ return false;
409
+ for (const key of keysA) {
410
+ if (!keysB.includes(key))
411
+ return false;
412
+ if (!deepEqual(a[key], b[key], compared))
413
+ return false;
414
+ }
415
+ // 原型链比较
416
+ return Object.getPrototypeOf(a) === Object.getPrototypeOf(b);
417
+ }
418
+ function compareArrays(a, b, compared) {
419
+ // 增加有效索引检查
420
+ const keysA = Object.keys(a).map(Number);
421
+ const keysB = Object.keys(b).map(Number);
422
+ if (keysA.length !== keysB.length)
423
+ return false;
424
+ // 递归比较每个元素
425
+ for (let i = 0; i < a.length; i++) {
426
+ if (!deepEqual(a[i], b[i], compared))
427
+ return false;
428
+ }
429
+ // 比较数组对象的其他属性
430
+ return compareObjects(a, b, compared);
431
+ }
304
432
 
305
- export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectMap, objectAssign as objectMerge, objectOmit, objectPick };
433
+ export { cloneDeep, isEqual, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectMap, objectAssign as objectMerge, objectOmit, objectPick };
package/lib/es/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/string.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/tooltip.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -171,91 +171,6 @@ function searchTreeById(tree, nodeId, config) {
171
171
  };
172
172
  return getIds(toFlatArray(tree));
173
173
  }
174
- /**
175
- * 使用迭代函数转换数组
176
- * @param {T} array
177
- * @param {Function} callback 迭代函数
178
- * @returns {Array}
179
- */
180
- function flatMap(array, callback) {
181
- const result = [];
182
- array.forEach((value, index) => {
183
- result.push(...callback(value, index, array));
184
- });
185
- return result;
186
- }
187
- /**
188
- * 根据 idProp 与 parentIdProp 从对象数组中构建对应的树
189
- * 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。
190
- * 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
191
- * @param {string} idProp 元素ID
192
- * @param {string} parentIdProp 父元素ID
193
- * @param {object[]} items 一维数组
194
- * @returns {WithChildren<T>[]} 树
195
- * @example
196
- * const array = [
197
- * { id: 'node-1', parent: 'root' },
198
- * { id: 'node-2', parent: 'root' },
199
- * { id: 'node-3', parent: 'node-2' },
200
- * { id: 'node-4', parent: 'node-2' },
201
- * { id: 'node-5', parent: 'node-4' },
202
- * ]
203
- * const tree = buildTree('id', 'parent', array)
204
- * expect(tree).toEqual([
205
- * { id: 'node-1', parent: 'root' },
206
- * {
207
- * id: 'node-2',
208
- * parent: 'root',
209
- * children: [
210
- * { id: 'node-3', parent: 'node-2' },
211
- * {
212
- * id: 'node-4',
213
- * parent: 'node-2',
214
- * children: [{ id: 'node-5', parent: 'node-4' }],
215
- * },
216
- * ],
217
- * },
218
- * ])
219
- */
220
- function buildTree(idProp, parentIdProp, items) {
221
- const wrapperMap = new Map();
222
- const ensure = (id) => {
223
- if (wrapperMap.has(id)) {
224
- return wrapperMap.get(id);
225
- }
226
- //@ts-ignore
227
- const wrapper = { id, parent: null, item: null, children: [] };
228
- wrapperMap.set(id, wrapper);
229
- return wrapper;
230
- };
231
- for (const item of items) {
232
- const parentWrapper = ensure(item[parentIdProp]);
233
- const itemWrapper = ensure(item[idProp]);
234
- //@ts-ignore
235
- itemWrapper.parent = parentWrapper;
236
- //@ts-ignore
237
- parentWrapper.children.push(itemWrapper);
238
- //@ts-ignore
239
- itemWrapper.item = item;
240
- }
241
- const topLevelWrappers = flatMap(Array.from(wrapperMap.values()).filter(wrapper => wrapper.parent === null), wrapper => wrapper.children);
242
- return unwrapRecursively(topLevelWrappers);
243
- function unwrapRecursively(wrapperArray) {
244
- const result = [];
245
- for (const wrapper of wrapperArray) {
246
- if (wrapper.children.length === 0) {
247
- result.push(wrapper.item);
248
- }
249
- else {
250
- result.push({
251
- ...wrapper.item,
252
- children: unwrapRecursively(wrapper.children)
253
- });
254
- }
255
- }
256
- return result;
257
- }
258
- }
259
174
  /**
260
175
  * 扁平化数组转换成树(效率高于buildTree)
261
176
  * @param {any[]} list
@@ -369,4 +284,4 @@ function fuzzySearchTree(nodes, filterCondition, options = defaultSearchTreeOpti
369
284
  return result;
370
285
  }
371
286
 
372
- export { buildTree, flatTree, forEachDeep, formatTree, fuzzySearchTree, mapDeep, searchTreeById };
287
+ export { flatTree, forEachDeep, formatTree, fuzzySearchTree, mapDeep, searchTreeById };
package/lib/es/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -30,11 +30,17 @@ function arrayLike(any) {
30
30
  return objectHas(any, 'length');
31
31
  }
32
32
  /**
33
- * 判断任意值的数据类型
33
+ * 判断任意值的数据类型,检查非对象时不如typeof、instanceof的性能高
34
+ *
35
+ * 当检查类对象时是不可靠的,对象可以通过定义 Symbol.toStringTag 属性来更改检查结果
36
+ *
37
+ * 详见:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
34
38
  * @param {unknown} any
35
- * @returns {string}
39
+ * @returns
36
40
  */
37
- const typeIs = (any) => Object.prototype.toString.call(any).slice(8, -1);
41
+ function typeIs(any) {
42
+ return Object.prototype.toString.call(any).slice(8, -1);
43
+ }
38
44
  // 基本数据类型判断
39
45
  const isString = (any) => typeof any === 'string';
40
46
  const isBoolean = (any) => typeof any === 'boolean';
@@ -114,4 +120,4 @@ function isEmpty(value) {
114
120
  return !Object.keys(value).length;
115
121
  }
116
122
 
117
- export { arrayLike, typeIs as default, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, objectHas, typeIs };
123
+ export { arrayLike, typeIs as default, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, objectHas, typeIs };
package/lib/es/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.7.2
2
+ * sculp-js v1.8.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.7.2
2
+ * sculp-js v1.8.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.7.2
2
+ * sculp-js v1.8.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.7.2
2
+ * sculp-js v1.8.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.7.2
2
+ * sculp-js v1.8.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/index.d.ts CHANGED
@@ -24,11 +24,15 @@ declare function objectHas<T extends AnyObject>(obj: T, key: keyof T): boolean;
24
24
  */
25
25
  declare function arrayLike(any: unknown): boolean;
26
26
  /**
27
- * 判断任意值的数据类型
27
+ * 判断任意值的数据类型,检查非对象时不如typeof、instanceof的性能高
28
+ *
29
+ * 当检查类对象时是不可靠的,对象可以通过定义 Symbol.toStringTag 属性来更改检查结果
30
+ *
31
+ * 详见:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
28
32
  * @param {unknown} any
29
- * @returns {string}
33
+ * @returns
30
34
  */
31
- declare const typeIs: (any: unknown) => string;
35
+ declare function typeIs(any: unknown): 'Null' | 'Undefined' | 'Symbol' | 'Boolean' | 'Number' | 'String' | 'Function' | 'Date' | 'RegExp' | 'Map' | 'Set' | 'ArrayBuffer' | 'Object' | 'Array' | 'Error' | 'BigInt' | 'Promise' | 'AsyncFunction' | string;
32
36
  declare const isString: (any: unknown) => any is string;
33
37
  declare const isBoolean: (any: unknown) => any is boolean;
34
38
  declare const isSymbol: (any: unknown) => any is symbol;
@@ -38,6 +42,7 @@ declare const isUndefined: (any: unknown) => any is undefined;
38
42
  declare const isNull: (any: unknown) => any is null;
39
43
  declare const isPrimitive: (any: unknown) => boolean;
40
44
  declare function isNullOrUnDef(val: unknown): val is null | undefined;
45
+
41
46
  declare const isObject: (any: unknown) => any is Record<string, unknown>;
42
47
  declare const isArray: (any: unknown) => any is unknown[];
43
48
  /**
@@ -268,9 +273,6 @@ interface SmoothScrollOptions {
268
273
  easing: EasingName;
269
274
  }
270
275
  declare function smoothScroll(options?: Partial<SmoothScrollOptions>): Promise<void>;
271
- type ReadyCallback = () => void;
272
- declare function isDomReady(): boolean;
273
- declare function onDomReady(callback: ReadyCallback): void;
274
276
  /**
275
277
  * 获取元素样式属性的计算值
276
278
  * @param {HTMLElement} el
@@ -403,6 +405,13 @@ declare function objectAssign<R = AnyObject | AnyArray>(source: ObjectAssignItem
403
405
  * @returns {R}
404
406
  */
405
407
  declare function objectFill<R extends AnyObject = AnyObject>(source: Partial<R>, target: Partial<R>, fillable?: (s: typeof source, t: typeof target, key: keyof R) => boolean): R;
408
+ /**
409
+ * 获取对象指定层级下的属性值(现在可用ES6+的可选链?.来替代)
410
+ * @param {AnyObject} obj
411
+ * @param {string} path
412
+ * @param {boolean} strict
413
+ * @returns
414
+ */
406
415
  declare function objectGet(obj: AnyObject, path: string, strict?: boolean): {
407
416
  p: any | undefined;
408
417
  k: string | undefined;
@@ -419,6 +428,14 @@ declare function objectGet(obj: AnyObject, path: string, strict?: boolean): {
419
428
  * @returns {T}
420
429
  */
421
430
  declare function cloneDeep<T>(source: T, map?: WeakMap<any, any>): T;
431
+ type Comparable = null | undefined | boolean | number | string | Date | RegExp | Map<any, any> | Set<any> | ArrayBuffer | object | Array<any>;
432
+ /**
433
+ * 比较两值是否相等,适用所有数据类型
434
+ * @param {Comparable} a
435
+ * @param {Comparable} b
436
+ * @returns {boolean}
437
+ */
438
+ declare function isEqual(a: Comparable, b: Comparable): boolean;
422
439
 
423
440
  /**
424
441
  * 标准化路径
@@ -809,45 +826,6 @@ interface ITreeConf {
809
826
  * @returns {[IdLike[], ITreeItem<V>[]]} - 由parentId...childId, parentObject-childObject组成的二维数组
810
827
  */
811
828
  declare function searchTreeById<V>(tree: ArrayLike<V>, nodeId: IdLike, config?: ITreeConf): [IdLike[], ArrayLike<V>[]];
812
- type WithChildren<T> = T & {
813
- children?: WithChildren<T>[];
814
- };
815
- /**
816
- * 根据 idProp 与 parentIdProp 从对象数组中构建对应的树
817
- * 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。
818
- * 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
819
- * @param {string} idProp 元素ID
820
- * @param {string} parentIdProp 父元素ID
821
- * @param {object[]} items 一维数组
822
- * @returns {WithChildren<T>[]} 树
823
- * @example
824
- * const array = [
825
- * { id: 'node-1', parent: 'root' },
826
- * { id: 'node-2', parent: 'root' },
827
- * { id: 'node-3', parent: 'node-2' },
828
- * { id: 'node-4', parent: 'node-2' },
829
- * { id: 'node-5', parent: 'node-4' },
830
- * ]
831
- * const tree = buildTree('id', 'parent', array)
832
- * expect(tree).toEqual([
833
- * { id: 'node-1', parent: 'root' },
834
- * {
835
- * id: 'node-2',
836
- * parent: 'root',
837
- * children: [
838
- * { id: 'node-3', parent: 'node-2' },
839
- * {
840
- * id: 'node-4',
841
- * parent: 'node-2',
842
- * children: [{ id: 'node-5', parent: 'node-4' }],
843
- * },
844
- * ],
845
- * },
846
- * ])
847
- */
848
- declare function buildTree<ID extends string, PID extends string, T extends {
849
- [key in ID | PID]: string;
850
- }>(idProp: ID, parentIdProp: PID, items: T[]): WithChildren<T>[];
851
829
  /**
852
830
  * 扁平化数组转换成树(效率高于buildTree)
853
831
  * @param {any[]} list
@@ -1077,4 +1055,4 @@ declare function replaceVarFromString(sourceStr: string, targetObj: Record<strin
1077
1055
  */
1078
1056
  declare function executeInScope(code: string, scope?: Record<string, any>): any;
1079
1057
 
1080
- export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressOptions, type IFieldOptions, type IFilterCondition, IPV4_REGEX, IPV6_REGEX, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, PHONE_REGEX, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, URL_REGEX, type UniqueString, type Url, type WithChildren, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, decodeFromBase64, divide, downloadBlob, downloadData, downloadHref, downloadURL, encodeToBase64, escapeRegExp, executeInScope, flatTree, forEachDeep, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDigit, isDomReady, isEmail, isEmpty, isError, isFloat, isFunction, isIdNo, isInteger, isIpV4, isIpV6, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isNumerical, isObject, isPhone, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isUrl, isValidDate, mapDeep, multiply, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, parseQueryParams, parseVarFromString, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, replaceVarFromString, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, strip, subtract, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, uniqueSymbol, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };
1058
+ export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type Comparable, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressOptions, type IFieldOptions, type IFilterCondition, IPV4_REGEX, IPV6_REGEX, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, PHONE_REGEX, type Params, type PartialDeep, type RandomString, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, URL_REGEX, type UniqueString, type Url, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, decodeFromBase64, divide, downloadBlob, downloadData, downloadHref, downloadURL, encodeToBase64, escapeRegExp, executeInScope, flatTree, forEachDeep, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDigit, isEmail, isEmpty, isEqual, isError, isFloat, isFunction, isIdNo, isInteger, isIpV4, isIpV6, isJsonString, isNaN, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isNumerical, isObject, isPhone, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isUrl, isValidDate, mapDeep, multiply, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, once, parseQueryParams, parseVarFromString, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, replaceVarFromString, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, strip, subtract, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, uniqueSymbol, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };