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