@bhsd/common 0.4.2 → 0.4.4
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/index.d.ts +10 -0
- package/dist/index.js +5 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,21 @@ export declare const CDN = "https://testingcf.jsdelivr.net";
|
|
|
2
2
|
declare global {
|
|
3
3
|
const define: unknown;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* PHP的`rawurldecode`函数的JavaScript实现
|
|
7
|
+
* @param str 要解码的字符串
|
|
8
|
+
*/
|
|
9
|
+
export declare const rawurldecode: (str: string) => string;
|
|
5
10
|
/**
|
|
6
11
|
* 解码标题
|
|
7
12
|
* @param title 标题
|
|
8
13
|
*/
|
|
9
14
|
export declare const normalizeTitle: (title: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* 将0~1之间的数字转换为十六进制
|
|
17
|
+
* @param d 0~1之间的数字
|
|
18
|
+
*/
|
|
19
|
+
export declare const numToHex: (d: number) => string;
|
|
10
20
|
/**
|
|
11
21
|
* 包含颜色时断开字符串
|
|
12
22
|
* @param str 字符串
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,9 @@ __export(src_exports, {
|
|
|
22
22
|
getObject: () => getObject,
|
|
23
23
|
loadScript: () => loadScript,
|
|
24
24
|
normalizeTitle: () => normalizeTitle,
|
|
25
|
+
numToHex: () => numToHex,
|
|
25
26
|
parseVersion: () => parseVersion,
|
|
27
|
+
rawurldecode: () => rawurldecode,
|
|
26
28
|
setObject: () => setObject,
|
|
27
29
|
splitColors: () => splitColors
|
|
28
30
|
});
|
|
@@ -33,14 +35,16 @@ let span;
|
|
|
33
35
|
if (typeof document === "object") {
|
|
34
36
|
span = document.createElement("span");
|
|
35
37
|
}
|
|
38
|
+
const rawurldecode = (str) => decodeURIComponent(str.replace(/%(?![\da-f]{2})/giu, "%25"));
|
|
36
39
|
const normalizeTitle = (title) => {
|
|
37
|
-
const decoded =
|
|
40
|
+
const decoded = rawurldecode(title);
|
|
38
41
|
if (/[<>[\]|{}]/u.test(decoded)) {
|
|
39
42
|
return decoded;
|
|
40
43
|
}
|
|
41
44
|
span.innerHTML = decoded;
|
|
42
45
|
return span.textContent;
|
|
43
46
|
};
|
|
47
|
+
const numToHex = (d) => Math.round(d * 255).toString(16).padStart(2, "0");
|
|
44
48
|
const splitColors = (str, hsl = true) => {
|
|
45
49
|
const pieces = [], re = hsl ? reFull : reRGB;
|
|
46
50
|
re.lastIndex = 0;
|