sculp-js 1.18.0 → 1.18.1

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/dist/cjs/array.js +3 -1
  2. package/dist/cjs/async.js +3 -1
  3. package/dist/cjs/base64.js +3 -1
  4. package/dist/cjs/clipboard.js +3 -1
  5. package/dist/cjs/cloneDeep.js +3 -1
  6. package/dist/cjs/cookie.js +3 -1
  7. package/dist/cjs/date.js +3 -1
  8. package/dist/cjs/dom.js +3 -1
  9. package/dist/cjs/download.js +3 -1
  10. package/dist/cjs/file.js +3 -1
  11. package/dist/cjs/func.js +3 -1
  12. package/dist/cjs/index.js +6 -4
  13. package/dist/cjs/isEqual.js +3 -1
  14. package/dist/cjs/math.js +3 -1
  15. package/dist/cjs/number.js +3 -1
  16. package/dist/cjs/object.js +5 -3
  17. package/dist/cjs/path.js +3 -1
  18. package/dist/cjs/qs.js +3 -1
  19. package/dist/cjs/random.js +3 -1
  20. package/dist/cjs/string.js +3 -1
  21. package/dist/cjs/tooltip.js +3 -1
  22. package/dist/cjs/tree.js +3 -1
  23. package/dist/cjs/type.js +2 -2
  24. package/dist/cjs/unicodeToolkit.js +79 -37
  25. package/dist/cjs/unique.js +3 -1
  26. package/dist/cjs/url.js +3 -1
  27. package/dist/cjs/validator.js +3 -1
  28. package/dist/cjs/variable.js +3 -1
  29. package/dist/cjs/watermark.js +3 -1
  30. package/dist/esm/array.js +1 -1
  31. package/dist/esm/async.js +1 -1
  32. package/dist/esm/base64.js +1 -1
  33. package/dist/esm/clipboard.js +1 -1
  34. package/dist/esm/cloneDeep.js +1 -1
  35. package/dist/esm/cookie.js +1 -1
  36. package/dist/esm/date.js +1 -1
  37. package/dist/esm/dom.js +2 -2
  38. package/dist/esm/download.js +2 -2
  39. package/dist/esm/file.js +1 -1
  40. package/dist/esm/func.js +1 -1
  41. package/dist/esm/index.js +4 -4
  42. package/dist/esm/isEqual.js +1 -1
  43. package/dist/esm/math.js +1 -1
  44. package/dist/esm/number.js +1 -1
  45. package/dist/esm/object.js +2 -2
  46. package/dist/esm/path.js +1 -1
  47. package/dist/esm/qs.js +1 -1
  48. package/dist/esm/random.js +1 -1
  49. package/dist/esm/string.js +1 -1
  50. package/dist/esm/tooltip.js +1 -1
  51. package/dist/esm/tree.js +1 -1
  52. package/dist/esm/type.js +1 -1
  53. package/dist/esm/unicodeToolkit.js +77 -37
  54. package/dist/esm/unique.js +1 -1
  55. package/dist/esm/url.js +1 -1
  56. package/dist/esm/validator.js +1 -1
  57. package/dist/esm/variable.js +1 -1
  58. package/dist/esm/watermark.js +1 -1
  59. package/dist/sculp-js.d.ts +1515 -0
  60. package/dist/types/tsdoc-metadata.json +11 -0
  61. package/dist/types/unicodeToolkit.d.ts +35 -11
  62. package/dist/umd/index.min.js +2 -2
  63. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/dom.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  import { objectEach } from './object.js';
8
8
  import { stringKebabCase } from './string.js';
9
- import { isObject, isString } from './type.js';
9
+ import { isString, isObject } from './type.js';
10
10
 
11
11
  /**
12
12
  * 判断元素是否包含某个样式名
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- import { isFunction, isNullOrUnDef, isString } from './type.js';
7
+ import { isNullOrUnDef, isFunction, isString } from './type.js';
8
8
  import { urlSetParams } from './url.js';
9
9
 
10
10
  /**
package/dist/esm/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -76,7 +76,7 @@ export {
76
76
  isSymbol,
77
77
  isUndefined,
78
78
  objectHas,
79
- typeIs
79
+ default as typeIs
80
80
  } from './type.js';
81
81
  export { urlDelParams, urlParse, urlSetParams, urlStringify } from './url.js';
82
82
  export { asyncMap, safeAwait, wait } from './async.js';
@@ -86,8 +86,8 @@ export { debounce, getGlobal, once, setGlobal, throttle } from './func.js';
86
86
  export { STRING_POOL, randomNumber, randomString, randomUuid } from './random.js';
87
87
  export {
88
88
  HEX_POOL,
89
- formatNumber as formatMoney,
90
- formatNumber,
89
+ formatMoney,
90
+ formatMoney as formatNumber,
91
91
  humanFileSize,
92
92
  numberAbbr,
93
93
  numberToHex
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/math.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
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.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- import { isObject, objectHas, isNumber, isUndefined, typeIs, isArray } from './type.js';
7
+ import typeIs, { isObject, objectHas, isNumber, isUndefined, isArray } from './type.js';
8
8
 
9
9
  /**
10
10
  * 判断对象是否为纯对象
package/dist/esm/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
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.18.0
2
+ * sculp-js v1.18.1
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.18.0
2
+ * sculp-js v1.18.1
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.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,42 +1,65 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  /**
8
- * 高效 Unicode/HTML/UTF-8 编码解码工具
8
+ * 增强型 Unicode/HTML/UTF-8 编码解码工具
9
9
  */
10
10
  class UnicodeToolkit {
11
- static ENTITY_REV_MAP = {
12
- '"': '"',
11
+ // 基础 HTML 实体映射
12
+ static ENTITY_MAP = {
13
13
  '&': '&',
14
14
  '<': '&lt;',
15
15
  '>': '&gt;',
16
- '\u00A0': '&nbsp;',
17
- '©': '&copy;'
16
+ '"': '&quot;',
17
+ "'": '&#39;'
18
+ };
19
+ static NAMED_ENTITIES = {
20
+ '&quot;': '"',
21
+ '&amp;': '&',
22
+ '&lt;': '<',
23
+ '&gt;': '>',
24
+ '&nbsp;': '\u00A0',
25
+ '&copy;': '©',
26
+ '&trade;': '™',
27
+ '&reg;': '®'
18
28
  };
19
29
  /**
20
- * 1. 综合编码方法
21
- * @param mode 'unicode' (转义为 \uXXXX) | 'html' (转义为 &#...;)
30
+ * 编码函数
31
+ * @param str 原始字符串
32
+ * @param mode 'unicode' (\uXXXX) | 'html' (&#123;) | 'entities' (命名实体)
33
+ * @param encodeAll 是否编码 ASCII 可见字符 (默认 false,仅编码非 ASCII 和特殊字符)
34
+ * * @example
35
+ * // Unicode 编码 (默认仅编码非 ASCII)
36
+ * UnicodeToolkit.encode('Hi 你好 😀')
37
+ * // => 'Hi \\u4F60\\u597D \\u{1F600}'
38
+ * * @example
39
+ * // 全部Unicode 编码
40
+ * UnicodeToolkit.encode('Hi 你好 😀','unicode', true)
41
+ * // => '\\u0048\\u0069\\u0020\\u4F60\\u597D\\u0020\\u{1F600}'
42
+ * * @example
43
+ * // HTML 实体编码
44
+ * UnicodeToolkit.encode('<script>', 'html',true)
45
+ * // => '&lt;&#115;&#99;&#114;&#105;&#112;&#116;&gt;&amp;'
22
46
  */
23
- static encode(str, mode = 'unicode') {
47
+ static encode(str, mode = 'unicode', encodeAll = false) {
24
48
  const result = [];
25
- // 使用 for...of 正确处理代理对(Emoji)
26
49
  for (const char of str) {
27
50
  const codePoint = char.codePointAt(0);
28
- // ASCII 范围内字符不编码(除了 HTML 必需的特殊字符)
29
- if (codePoint <= 127) {
30
- if (mode === 'html' && this.ENTITY_REV_MAP[char]) {
31
- result.push(this.ENTITY_REV_MAP[char]);
32
- } else {
33
- result.push(char);
34
- }
51
+ // 1. 处理特殊 HTML 基础字符
52
+ if (mode === 'html' && this.ENTITY_MAP[char]) {
53
+ result.push(this.ENTITY_MAP[char]);
35
54
  continue;
36
55
  }
37
- // 处理非 ASCII 字符
56
+ // 2. ASCII 范围 (32-126) 且不强制全编码时,保持原样
57
+ if (!encodeAll && codePoint >= 32 && codePoint <= 126) {
58
+ result.push(char);
59
+ continue;
60
+ }
61
+ // 3. 根据模式转换
38
62
  if (mode === 'unicode') {
39
- // 如果码点超过 0xFFFF,说明是代理对,转义为 \u{XXXXXX} 或拆分为两个 \uXXXX
40
63
  if (codePoint > 0xffff) {
41
64
  result.push(`\\u{${codePoint.toString(16).toUpperCase()}}`);
42
65
  } else {
@@ -49,25 +72,42 @@ class UnicodeToolkit {
49
72
  return result.join('');
50
73
  }
51
74
  /**
52
- * 2. 混合解码 (支持 \uXXXX, \u{XXXX}, HTML 实体)
75
+ * 综合解码 (支持 \uXXXX, \u{XXXX}, HTML 实体, 十六进制实体)
76
+ * @param normalizeSpace 是否将 \u00A0 (&nbsp;) 转换为普通空格 \u0020
77
+ * * @example
78
+ * // 解码 Unicode 和 Emoji
79
+ * UnicodeToolkit.decode('\\u4F60\\u597D\\u{1F680}')
80
+ * // => '你好🚀'
81
+ * * @example
82
+ * // 解码 HTML 实体 (支持十进制、十六进制和命名实体)
83
+ * UnicodeToolkit.decode('Price: &#163;10 &amp; &copy;')
84
+ * // => 'Price: £10 & ©'
85
+ * * @example
86
+ * // 空格归一化 (将 &nbsp; 转为标准空格)
87
+ * UnicodeToolkit.decode('A&nbsp;B', true)
88
+ * // => 'A B' (charCodeAt 为 32 而不是 160)
53
89
  */
54
- static decode(str) {
55
- return (
56
- str
57
- // 处理 \u{XXXX} 这种 ES6 风格编码
58
- .replace(/\\u\{([0-9a-fA-F]+)\}/g, (_, hex) => String.fromCodePoint(parseInt(hex, 16)))
59
- // 处理标准 \uXXXX
60
- .replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
61
- // 处理 HTML 实体
62
- .replace(/&#(x?)([0-9a-fA-F]+);/g, (_, isHex, code) => String.fromCodePoint(parseInt(code, isHex ? 16 : 10)))
63
- .replace(/&[a-z]+;/g, e => Object.entries(this.ENTITY_REV_MAP).find(x => x[1] === e)?.[0] || e)
64
- );
65
- }
66
- /**
67
- * 3. 高性能 UTF-8 转码
68
- */
69
- static toUTF8(str) {
70
- return new TextEncoder().encode(str);
90
+ static decode(str, normalizeSpace = false) {
91
+ if (!str) return '';
92
+ let decoded = str
93
+ // 1. Unicode: \uXXXX 和 \u{XXXX}
94
+ .replace(/\\u(?:\{([0-9a-fA-F]+)\}|([0-9a-fA-F]{4}))/g, (_, hexLong, hexShort) => {
95
+ return String.fromCodePoint(parseInt(hexLong || hexShort, 16));
96
+ })
97
+ // 2. HTML 实体: &#123; 和 &#x7B;
98
+ .replace(/&#(x?)([0-9a-fA-F]+);/g, (_, isHex, code) => {
99
+ return String.fromCodePoint(parseInt(code, isHex ? 16 : 10));
100
+ })
101
+ // 3. 命名实体
102
+ .replace(/&[a-z0-9]+;/gi, entity => {
103
+ return this.NAMED_ENTITIES[entity] || entity;
104
+ });
105
+ // 4. 空格归一化处理
106
+ if (normalizeSpace) {
107
+ // 将 \u00A0 替换为标准半角空格 \u0020
108
+ decoded = decoded.replace(/\u00A0/g, ' ');
109
+ }
110
+ return decoded;
71
111
  }
72
112
  }
73
113
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.18.0
2
+ * sculp-js v1.18.1
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.18.0
2
+ * sculp-js v1.18.1
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.18.0
2
+ * sculp-js v1.18.1
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.18.0
2
+ * sculp-js v1.18.1
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */