sculp-js 1.19.2 → 1.19.3

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 (62) hide show
  1. package/dist/cjs/array.cjs +1 -1
  2. package/dist/cjs/async.cjs +1 -1
  3. package/dist/cjs/base64.cjs +157 -71
  4. package/dist/cjs/clipboard.cjs +1 -1
  5. package/dist/cjs/cloneDeep.cjs +1 -1
  6. package/dist/cjs/cookie.cjs +1 -1
  7. package/dist/cjs/date.cjs +1 -1
  8. package/dist/cjs/dom.cjs +1 -1
  9. package/dist/cjs/download.cjs +1 -1
  10. package/dist/cjs/file.cjs +1 -1
  11. package/dist/cjs/func.cjs +1 -1
  12. package/dist/cjs/index.cjs +10 -1
  13. package/dist/cjs/isEqual.cjs +1 -1
  14. package/dist/cjs/math.cjs +1 -1
  15. package/dist/cjs/number.cjs +1 -1
  16. package/dist/cjs/object.cjs +1 -1
  17. package/dist/cjs/path.cjs +1 -1
  18. package/dist/cjs/qs.cjs +1 -1
  19. package/dist/cjs/random.cjs +1 -1
  20. package/dist/cjs/string.cjs +1 -1
  21. package/dist/cjs/tooltip.cjs +1 -1
  22. package/dist/cjs/tree.cjs +1 -1
  23. package/dist/cjs/type.cjs +71 -3
  24. package/dist/cjs/unicodeToolkit.cjs +1 -1
  25. package/dist/cjs/unique.cjs +1 -1
  26. package/dist/cjs/url.cjs +1 -1
  27. package/dist/cjs/validator.cjs +1 -1
  28. package/dist/cjs/variable.cjs +1 -1
  29. package/dist/cjs/watermark.cjs +1 -1
  30. package/dist/esm/array.mjs +1 -1
  31. package/dist/esm/async.mjs +1 -1
  32. package/dist/esm/base64.mjs +157 -71
  33. package/dist/esm/clipboard.mjs +1 -1
  34. package/dist/esm/cloneDeep.mjs +1 -1
  35. package/dist/esm/cookie.mjs +1 -1
  36. package/dist/esm/date.mjs +1 -1
  37. package/dist/esm/dom.mjs +1 -1
  38. package/dist/esm/download.mjs +1 -1
  39. package/dist/esm/file.mjs +1 -1
  40. package/dist/esm/func.mjs +1 -1
  41. package/dist/esm/index.mjs +10 -1
  42. package/dist/esm/isEqual.mjs +1 -1
  43. package/dist/esm/math.mjs +1 -1
  44. package/dist/esm/number.mjs +1 -1
  45. package/dist/esm/object.mjs +1 -1
  46. package/dist/esm/path.mjs +1 -1
  47. package/dist/esm/qs.mjs +1 -1
  48. package/dist/esm/random.mjs +1 -1
  49. package/dist/esm/string.mjs +1 -1
  50. package/dist/esm/tooltip.mjs +1 -1
  51. package/dist/esm/tree.mjs +1 -1
  52. package/dist/esm/type.mjs +71 -3
  53. package/dist/esm/unicodeToolkit.mjs +1 -1
  54. package/dist/esm/unique.mjs +1 -1
  55. package/dist/esm/url.mjs +1 -1
  56. package/dist/esm/validator.mjs +1 -1
  57. package/dist/esm/variable.mjs +1 -1
  58. package/dist/esm/watermark.mjs +1 -1
  59. package/dist/types/base64.d.ts +6 -6
  60. package/dist/types/type.d.ts +86 -3
  61. package/dist/umd/index.min.js +2 -2
  62. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -15,112 +15,198 @@ const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
15
15
  // eslint-disable-next-line
16
16
  const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
17
17
  /**
18
- * 字符串编码成Base64, 平替浏览器的btoa, 不包含中文的处理 (适用于任何环境,包括小程序)
18
+ * 高性能 UTF-8 字符串转 Uint8Array
19
+ */
20
+ function stringToUint8Array(str) {
21
+ const len = str.length;
22
+ const bytes = new Uint8Array(len * 3); // 最多 3 倍长度
23
+ let j = 0;
24
+ for (let i = 0; i < len; i++) {
25
+ let code = str.charCodeAt(i);
26
+ if (code < 0x80) {
27
+ bytes[j++] = code;
28
+ } else if (code < 0x800) {
29
+ bytes[j++] = 0xc0 | (code >> 6);
30
+ bytes[j++] = 0x80 | (code & 0x3f);
31
+ } else if (code < 0xd800 || code >= 0xe000) {
32
+ bytes[j++] = 0xe0 | (code >> 12);
33
+ bytes[j++] = 0x80 | ((code >> 6) & 0x3f);
34
+ bytes[j++] = 0x80 | (code & 0x3f);
35
+ } else {
36
+ // 处理代理对(emoji 等)
37
+ i++;
38
+ code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
39
+ bytes[j++] = 0xf0 | (code >> 18);
40
+ bytes[j++] = 0x80 | ((code >> 12) & 0x3f);
41
+ bytes[j++] = 0x80 | ((code >> 6) & 0x3f);
42
+ bytes[j++] = 0x80 | (code & 0x3f);
43
+ }
44
+ }
45
+ return bytes.subarray(0, j);
46
+ }
47
+ /**
48
+ * 高性能 Uint8Array 转 UTF-8 字符串
49
+ */
50
+ function uint8ArrayToString(bytes) {
51
+ const len = bytes.length;
52
+ let result = '';
53
+ let i = 0;
54
+ while (i < len) {
55
+ const byte1 = bytes[i++];
56
+ if (byte1 < 0x80) {
57
+ result += String.fromCharCode(byte1);
58
+ } else if (byte1 < 0xe0) {
59
+ const byte2 = bytes[i++] & 0x3f;
60
+ result += String.fromCharCode(((byte1 & 0x1f) << 6) | byte2);
61
+ } else if (byte1 < 0xf0) {
62
+ const byte2 = bytes[i++] & 0x3f;
63
+ const byte3 = bytes[i++] & 0x3f;
64
+ result += String.fromCharCode(((byte1 & 0x0f) << 12) | (byte2 << 6) | byte3);
65
+ } else {
66
+ const byte2 = bytes[i++] & 0x3f;
67
+ const byte3 = bytes[i++] & 0x3f;
68
+ const byte4 = bytes[i++] & 0x3f;
69
+ let code = ((byte1 & 0x07) << 18) | (byte2 << 12) | (byte3 << 6) | byte4;
70
+ code -= 0x10000;
71
+ result += String.fromCharCode(0xd800 + ((code >> 10) & 0x3ff), 0xdc00 + (code & 0x3ff));
72
+ }
73
+ }
74
+ return result;
75
+ }
76
+ /**
77
+ * 高性能 Base64 编码(二进制字符串转 Base64)
78
+ */
79
+ function binaryToBase64(binary) {
80
+ const len = binary.length;
81
+ let result = '';
82
+ let i = 0;
83
+ for (; i < len - 2; i += 3) {
84
+ const n = (binary.charCodeAt(i) << 16) | (binary.charCodeAt(i + 1) << 8) | binary.charCodeAt(i + 2);
85
+ result += b64.charAt(n >> 18) + b64.charAt((n >> 12) & 0x3f) + b64.charAt((n >> 6) & 0x3f) + b64.charAt(n & 0x3f);
86
+ }
87
+ // 处理剩余字节
88
+ const remaining = len - i;
89
+ if (remaining === 1) {
90
+ const n = binary.charCodeAt(i);
91
+ result += b64.charAt(n >> 2) + b64.charAt((n << 4) & 0x3f) + '==';
92
+ } else if (remaining === 2) {
93
+ const n = (binary.charCodeAt(i) << 8) | binary.charCodeAt(i + 1);
94
+ result += b64.charAt(n >> 10) + b64.charAt((n >> 4) & 0x3f) + b64.charAt((n << 2) & 0x3f) + '=';
95
+ }
96
+ return result;
97
+ }
98
+ /**
99
+ * 高性能 Base64 解码(Base64 转二进制字符串)
100
+ */
101
+ function base64ToBinary(base64Str) {
102
+ base64Str = String(base64Str).replace(/[\t\n\f\r ]+/g, '');
103
+ if (!b64re.test(base64Str)) {
104
+ throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
105
+ }
106
+ const len = base64Str.length;
107
+ const padding = base64Str.endsWith('==') ? 2 : base64Str.endsWith('=') ? 1 : 0;
108
+ const result = new Array(len * 0.75 - padding);
109
+ let j = 0;
110
+ for (let i = 0; i < len; i += 4) {
111
+ const n =
112
+ (b64.indexOf(base64Str.charAt(i)) << 18) |
113
+ (b64.indexOf(base64Str.charAt(i + 1)) << 12) |
114
+ ((b64.indexOf(base64Str.charAt(i + 2)) & 0x3f) << 6) |
115
+ (b64.indexOf(base64Str.charAt(i + 3)) & 0x3f);
116
+ result[j++] = String.fromCharCode((n >> 16) & 0xff);
117
+ if (i + 2 < len - padding || padding < 2) {
118
+ result[j++] = String.fromCharCode((n >> 8) & 0xff);
119
+ }
120
+ if (i + 3 < len - padding || padding < 1) {
121
+ result[j++] = String.fromCharCode(n & 0xff);
122
+ }
123
+ }
124
+ return result.join('');
125
+ }
126
+ /**
127
+ * 字符串编码成 Base64(适用于任何环境,包括小程序)
19
128
  * @param {string} string
20
129
  * @returns {string}
21
130
  */
22
131
  function weBtoa(string) {
23
- // 同window.btoa: 字符串编码成Base64
24
132
  string = String(string);
25
- let bitmap,
26
- a,
27
- b,
28
- c,
29
- result = '',
30
- i = 0;
31
- const strLen = string.length;
32
- const rest = strLen % 3;
33
- for (; i < strLen; ) {
34
- if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255)
133
+ const len = string.length;
134
+ for (let i = 0; i < len; i++) {
135
+ if (string.charCodeAt(i) > 255) {
35
136
  throw new TypeError(
36
137
  "Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."
37
138
  );
38
- bitmap = (a << 16) | (b << 8) | c;
39
- result +=
40
- b64.charAt((bitmap >> 18) & 63) +
41
- b64.charAt((bitmap >> 12) & 63) +
42
- b64.charAt((bitmap >> 6) & 63) +
43
- b64.charAt(bitmap & 63);
139
+ }
44
140
  }
45
- return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
141
+ return binaryToBase64(string);
46
142
  }
47
143
  /**
48
- * Base64解码为原始字符串,平替浏览器的atob, 不包含中文的处理(适用于任何环境,包括小程序)
144
+ * Base64 解码为原始字符串(适用于任何环境,包括小程序)
49
145
  * @param {string} string
50
146
  * @returns {string}
51
147
  */
52
148
  function weAtob(string) {
53
- // 同window.atob: Base64解码为原始字符串
54
- string = String(string).replace(/[\t\n\f\r ]+/g, '');
55
- if (!b64re.test(string))
56
- throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
57
- string += '=='.slice(2 - (string.length & 3));
58
- let bitmap,
59
- result = '',
60
- r1,
61
- r2,
62
- i = 0;
63
- for (const strLen = string.length; i < strLen; ) {
64
- bitmap =
65
- (b64.indexOf(string.charAt(i++)) << 18) |
66
- (b64.indexOf(string.charAt(i++)) << 12) |
67
- ((r1 = b64.indexOf(string.charAt(i++))) << 6) |
68
- (r2 = b64.indexOf(string.charAt(i++)));
69
- result +=
70
- r1 === 64
71
- ? String.fromCharCode((bitmap >> 16) & 255)
72
- : r2 === 64
73
- ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
74
- : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
75
- }
76
- return result;
77
- }
78
- function stringToUint8Array(str) {
79
- const utf8 = encodeURIComponent(str); // 将字符串转换为 UTF-8 编码
80
- const uint8Array = new Uint8Array(utf8.length); // 创建 Uint8Array
81
- for (let i = 0; i < utf8.length; i++) {
82
- uint8Array[i] = utf8.charCodeAt(i); // 填充 Uint8Array
83
- }
84
- return uint8Array;
85
- }
86
- function uint8ArrayToString(uint8Array) {
87
- const utf8 = String.fromCharCode.apply(null, uint8Array); // 将 Uint8Array 转为字符串
88
- return decodeURIComponent(utf8); // 将 UTF-8 字符串解码回正常字符串
149
+ return base64ToBinary(string);
89
150
  }
90
151
  /**
91
- * 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
92
- * @param base64 base64编码的字符串
152
+ * 将 base64 编码的字符串转换为原始字符串,包括对中文内容的处理 (高性能,且支持 Web、Node、小程序等任意平台)
153
+ * @param base64 base64 编码的字符串
93
154
  * @returns 原始字符串,包括中文内容
94
155
  */
95
156
  function b64decode(base64) {
96
- const binaryString = !type.isNullOrUnDef(func.getGlobal('atob')) ? func.getGlobal('atob')(base64) : weAtob(base64);
157
+ // 优先使用原生方法(性能最优)
158
+ if (!type.isNullOrUnDef(func.getGlobal('atob')) && !type.isNullOrUnDef(func.getGlobal('TextDecoder'))) {
159
+ try {
160
+ const binaryString = func.getGlobal('atob')(base64);
161
+ const len = binaryString.length;
162
+ const bytes = new Uint8Array(len);
163
+ for (let i = 0; i < len; i++) {
164
+ bytes[i] = binaryString.charCodeAt(i);
165
+ }
166
+ return new (func.getGlobal('TextDecoder'))('utf-8').decode(bytes);
167
+ } catch (e) {
168
+ // 如果原生方法失败,使用降级方案
169
+ }
170
+ }
171
+ // 降级方案:使用自定义实现
172
+ const binaryString = base64ToBinary(base64);
97
173
  const len = binaryString.length;
98
174
  const bytes = new Uint8Array(len);
99
175
  for (let i = 0; i < len; i++) {
100
176
  bytes[i] = binaryString.charCodeAt(i);
101
177
  }
102
- // 使用TextDecoder将Uint8Array转换为原始字符串,包括中文内容
103
- return !type.isNullOrUnDef(func.getGlobal('TextDecoder'))
104
- ? new (func.getGlobal('TextDecoder'))('utf-8').decode(bytes)
105
- : uint8ArrayToString(bytes);
178
+ return uint8ArrayToString(bytes);
106
179
  }
107
180
  /**
108
- * 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
181
+ * 将原始字符串,包括中文内容,转换为 base64 编码的字符串 (高性能,且支持 Web、Node、小程序等任意平台)
109
182
  * @param rawStr 原始字符串,包括中文内容
110
- * @returns base64编码的字符串
183
+ * @returns base64 编码的字符串
111
184
  */
112
185
  function b64encode(rawStr) {
113
- const utf8Array = !type.isNullOrUnDef(func.getGlobal('TextEncoder'))
114
- ? new (func.getGlobal('TextEncoder'))().encode(rawStr)
115
- : stringToUint8Array(rawStr);
186
+ // 优先使用原生方法(性能最优)
187
+ if (!type.isNullOrUnDef(func.getGlobal('btoa')) && !type.isNullOrUnDef(func.getGlobal('TextEncoder'))) {
188
+ try {
189
+ const utf8Array = new (func.getGlobal('TextEncoder'))().encode(rawStr);
190
+ let binaryString = '';
191
+ const len = utf8Array.length;
192
+ for (let i = 0; i < len; i++) {
193
+ binaryString += String.fromCharCode(utf8Array[i]);
194
+ }
195
+ return func.getGlobal('btoa')(binaryString);
196
+ } catch (e) {
197
+ // 如果原生方法失败,使用降级方案
198
+ }
199
+ }
200
+ // 降级方案:使用自定义实现
201
+ const utf8Array = stringToUint8Array(rawStr);
116
202
  // 将 Uint8Array 转换为二进制字符串
117
203
  let binaryString = '';
118
204
  const len = utf8Array.length;
119
205
  for (let i = 0; i < len; i++) {
120
206
  binaryString += String.fromCharCode(utf8Array[i]);
121
207
  }
122
- // 将二进制字符串转换为base64编码的字符串
123
- return !type.isNullOrUnDef(func.getGlobal('btoa')) ? func.getGlobal('btoa')(binaryString) : weBtoa(binaryString);
208
+ // 将二进制字符串转换为 base64 编码
209
+ return binaryToBase64(binaryString);
124
210
  }
125
211
  var base64 = {
126
212
  weBtoa,
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/date.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/dom.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/file.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/func.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -123,14 +123,20 @@ exports.stringFill = string.stringFill;
123
123
  exports.stringFormat = string.stringFormat;
124
124
  exports.stringKebabCase = string.stringKebabCase;
125
125
  exports.arrayLike = type.arrayLike;
126
+ exports.is = type.is;
127
+ exports.isArguments = type.isArguments;
126
128
  exports.isArray = type.isArray;
129
+ exports.isArrayBuffer = type.isArrayBuffer;
130
+ exports.isAsyncFunction = type.isAsyncFunction;
127
131
  exports.isBigInt = type.isBigInt;
128
132
  exports.isBoolean = type.isBoolean;
133
+ exports.isDataView = type.isDataView;
129
134
  exports.isDate = type.isDate;
130
135
  exports.isEmpty = type.isEmpty;
131
136
  exports.isError = type.isError;
132
137
  exports.isFunction = type.isFunction;
133
138
  exports.isJsonString = type.isJsonString;
139
+ exports.isMap = type.isMap;
134
140
  exports.isNaN = type.isNaN;
135
141
  exports.isNodeList = type.isNodeList;
136
142
  exports.isNull = type.isNull;
@@ -139,9 +145,12 @@ exports.isNullish = type.isNullOrUnDef;
139
145
  exports.isNumber = type.isNumber;
140
146
  exports.isObject = type.isObject;
141
147
  exports.isPrimitive = type.isPrimitive;
148
+ exports.isPromise = type.isPromise;
142
149
  exports.isRegExp = type.isRegExp;
150
+ exports.isSet = type.isSet;
143
151
  exports.isString = type.isString;
144
152
  exports.isSymbol = type.isSymbol;
153
+ exports.isTypedArray = type.isTypedArray;
145
154
  exports.isUndefined = type.isUndefined;
146
155
  exports.objectHas = type.objectHas;
147
156
  exports.typeIs = type.typeIs;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/math.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/path.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/qs.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/tree.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/type.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -32,17 +32,37 @@ function arrayLike(any) {
32
32
  return objectHas(any, 'length');
33
33
  }
34
34
  /**
35
- * 判断任意值的数据类型,检查非对象时不如typeof、instanceof的性能高
35
+ * 判断任意值的数据类型,检查非对象时不如 typeof、instanceof 的性能高
36
36
  *
37
37
  * 当检查类对象时是不可靠的,对象可以通过定义 Symbol.toStringTag 属性来更改检查结果
38
38
  *
39
39
  * 详见:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
40
40
  * @param {unknown} any
41
- * @returns
41
+ * @returns {TypeTag} 类型标签字符串
42
42
  */
43
43
  function typeIs(any) {
44
44
  return toString.call(any).slice(8, -1);
45
45
  }
46
+ /**
47
+ * 判断值是否为指定类型(带类型守卫)
48
+ * @param {unknown} value - 要检查的值
49
+ * @param {TypeTag} type - 期望的类型
50
+ * @returns {boolean} 如果值是指定类型则返回 true
51
+ * @example
52
+ * is(value, 'String')
53
+ * is(value, 'Array')
54
+ * is(value, 'Date')
55
+ *
56
+ * @example
57
+ * // 使用类型守卫
58
+ * if (is(value, 'String')) {
59
+ * // value 在这里被推断为 string 类型
60
+ * console.log(value.toUpperCase());
61
+ * }
62
+ */
63
+ function is(value, type) {
64
+ return typeIs(value) === type;
65
+ }
46
66
  // 基本数据类型判断
47
67
  const isString = any => typeof any === 'string';
48
68
  const isBoolean = any => typeof any === 'boolean';
@@ -69,6 +89,34 @@ const isNaN = any => Number.isNaN(any);
69
89
  const isDate = any => typeIs(any) === 'Date';
70
90
  const isError = any => typeIs(any) === 'Error';
71
91
  const isRegExp = any => typeIs(any) === 'RegExp';
92
+ const isPromise = any => typeIs(any) === 'Promise';
93
+ const isMap = any => typeIs(any) === 'Map';
94
+ const isSet = any => typeIs(any) === 'Set';
95
+ /**
96
+ * 判断是否为 TypedArray
97
+ * @param {unknown} any
98
+ * @returns {boolean}
99
+ */
100
+ const isTypedArray = any => {
101
+ const tag = typeIs(any);
102
+ return (
103
+ tag === 'Int8Array' ||
104
+ tag === 'Uint8Array' ||
105
+ tag === 'Uint8ClampedArray' ||
106
+ tag === 'Int16Array' ||
107
+ tag === 'Uint16Array' ||
108
+ tag === 'Int32Array' ||
109
+ tag === 'Uint32Array' ||
110
+ tag === 'Float32Array' ||
111
+ tag === 'Float64Array' ||
112
+ tag === 'BigInt64Array' ||
113
+ tag === 'BigUint64Array'
114
+ );
115
+ };
116
+ const isDataView = any => typeIs(any) === 'DataView';
117
+ const isArrayBuffer = any => typeIs(any) === 'ArrayBuffer';
118
+ const isArguments = any => typeIs(any) === 'Arguments';
119
+ const isAsyncFunction = any => typeIs(any) === 'AsyncFunction';
72
120
  /**
73
121
  * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
74
122
  * @param {string} str
@@ -132,6 +180,9 @@ function isNodeList(value) {
132
180
  }
133
181
  var type = {
134
182
  typeIs,
183
+ is,
184
+ TypeMapping: undefined,
185
+ TypeTag: undefined,
135
186
  objectHas,
136
187
  arrayLike,
137
188
  isString,
@@ -151,6 +202,14 @@ var type = {
151
202
  isDate,
152
203
  isError,
153
204
  isRegExp,
205
+ isPromise,
206
+ isMap,
207
+ isSet,
208
+ isTypedArray,
209
+ isDataView,
210
+ isArrayBuffer,
211
+ isArguments,
212
+ isAsyncFunction,
154
213
  isJsonString,
155
214
  isEmpty,
156
215
  isNodeList
@@ -158,14 +217,20 @@ var type = {
158
217
 
159
218
  exports.arrayLike = arrayLike;
160
219
  exports.default = type;
220
+ exports.is = is;
221
+ exports.isArguments = isArguments;
161
222
  exports.isArray = isArray;
223
+ exports.isArrayBuffer = isArrayBuffer;
224
+ exports.isAsyncFunction = isAsyncFunction;
162
225
  exports.isBigInt = isBigInt;
163
226
  exports.isBoolean = isBoolean;
227
+ exports.isDataView = isDataView;
164
228
  exports.isDate = isDate;
165
229
  exports.isEmpty = isEmpty;
166
230
  exports.isError = isError;
167
231
  exports.isFunction = isFunction;
168
232
  exports.isJsonString = isJsonString;
233
+ exports.isMap = isMap;
169
234
  exports.isNaN = isNaN;
170
235
  exports.isNodeList = isNodeList;
171
236
  exports.isNull = isNull;
@@ -174,9 +239,12 @@ exports.isNullish = isNullOrUnDef;
174
239
  exports.isNumber = isNumber;
175
240
  exports.isObject = isObject;
176
241
  exports.isPrimitive = isPrimitive;
242
+ exports.isPromise = isPromise;
177
243
  exports.isRegExp = isRegExp;
244
+ exports.isSet = isSet;
178
245
  exports.isString = isString;
179
246
  exports.isSymbol = isSymbol;
247
+ exports.isTypedArray = isTypedArray;
180
248
  exports.isUndefined = isUndefined;
181
249
  exports.objectHas = objectHas;
182
250
  exports.typeIs = typeIs;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/cjs/url.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
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.19.2
2
+ * sculp-js v1.19.3
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */