@bhsd/common 2.0.0 → 2.2.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.
- package/dist/index.d.ts +10 -0
- package/dist/index.js +12 -2
- package/package.json +15 -13
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export declare const wmf = "wiktionary|wiki(?:pedia|books|news|quote|source|vers
|
|
|
17
17
|
* @param str 要解码的字符串
|
|
18
18
|
*/
|
|
19
19
|
export declare const rawurldecode: (str: string) => string;
|
|
20
|
+
/**
|
|
21
|
+
* 将0~255之间的整数转换为十六进制
|
|
22
|
+
* @param d 0~255之间的整数
|
|
23
|
+
*/
|
|
24
|
+
export declare const intToHex: (d: number) => string;
|
|
20
25
|
/**
|
|
21
26
|
* 将0~1之间的数字转换为十六进制
|
|
22
27
|
* @param d 0~1之间的数字
|
|
@@ -66,4 +71,9 @@ export declare const lintJSON: (str: string) => JsonError[];
|
|
|
66
71
|
* @param str JSONC字符串
|
|
67
72
|
*/
|
|
68
73
|
export declare const lintJSONC: (str: string) => JsonError[];
|
|
74
|
+
/**
|
|
75
|
+
* 获取字符串开头的空白字符数量
|
|
76
|
+
* @param str 字符串
|
|
77
|
+
*/
|
|
78
|
+
export declare const numLeadingSpaces: (str: string) => number;
|
|
69
79
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -5,11 +5,16 @@ export const wmf = 'wiktionary|wiki(?:pedia|books|news|quote|source|versity|voya
|
|
|
5
5
|
* @param str 要解码的字符串
|
|
6
6
|
*/
|
|
7
7
|
export const rawurldecode = (str) => decodeURIComponent(str.replace(/%(?![\da-f]{2})/giu, '%25'));
|
|
8
|
+
/**
|
|
9
|
+
* 将0~255之间的整数转换为十六进制
|
|
10
|
+
* @param d 0~255之间的整数
|
|
11
|
+
*/
|
|
12
|
+
export const intToHex = (d) => Math.round(d).toString(16).padStart(2, '0');
|
|
8
13
|
/**
|
|
9
14
|
* 将0~1之间的数字转换为十六进制
|
|
10
15
|
* @param d 0~1之间的数字
|
|
11
16
|
*/
|
|
12
|
-
export const numToHex = (d) =>
|
|
17
|
+
export const numToHex = (d) => intToHex(d * 255);
|
|
13
18
|
const regex = /* #__PURE__ */ (() => {
|
|
14
19
|
const hexColor = String.raw `#(?:[\da-f]{3,4}|(?:[\da-f]{2}){3,4})(?![\p{L}\p{N}_])`, rgbValue = String.raw `(?:\d*\.)?\d+%?`, hue = String.raw `(?:\d*\.)?\d+(?:deg|grad|rad|turn)?`, rgbColor = String.raw `rgba?\(\s*(?:${String.raw `${new Array(3).fill(rgbValue).join(String.raw `\s+`)}(?:\s*\/\s*${rgbValue})?`}|${String.raw `${new Array(3).fill(rgbValue).join(String.raw `\s*,\s*`)}(?:\s*,\s*${rgbValue})?`})\s*\)`, hslColor = String.raw `hsla?\(\s*(?:${String.raw `${hue}\s+${rgbValue}\s+${rgbValue}(?:\s*\/\s*${rgbValue})?`}|${String.raw `${hue}${String.raw `\s*,\s*(?:\d*\.)?\d+%`.repeat(2)}(?:\s*,\s*${rgbValue})?`})\s*\)`;
|
|
15
20
|
return {
|
|
@@ -45,7 +50,7 @@ export const splitColors = (str, hsl = true) => {
|
|
|
45
50
|
* @param style 内联样式
|
|
46
51
|
*/
|
|
47
52
|
export const sanitizeInlineStyle = (style) => style.replace(/[{}]/gu, p => p === '{' ? '{' : '}')
|
|
48
|
-
.replace(/^[\s;]+/u, p => p.
|
|
53
|
+
.replace(/^[\s;]+/u, p => p.replaceAll(';', ' '));
|
|
49
54
|
export function getRegex(f) {
|
|
50
55
|
const map = new Map(), weakMap = new WeakMap();
|
|
51
56
|
return s => {
|
|
@@ -163,3 +168,8 @@ export const lintJSON = (str) => {
|
|
|
163
168
|
* @param str JSONC字符串
|
|
164
169
|
*/
|
|
165
170
|
export const lintJSONC = (str) => str.trim() ? lintJSONBase(str, jsonc_parse) : [];
|
|
171
|
+
/**
|
|
172
|
+
* 获取字符串开头的空白字符数量
|
|
173
|
+
* @param str 字符串
|
|
174
|
+
*/
|
|
175
|
+
export const numLeadingSpaces = (str) => str.search(/\S|$/u);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"homepage": "https://github.com/bhsd-harry/common#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/bhsd-harry/common/issues"
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"type": "module",
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"scripts": {
|
|
19
|
+
"ls": "npm i --package-lock-only && npm ls --package-lock-only --all --omit=dev",
|
|
19
20
|
"prepublishOnly": "npm run build",
|
|
20
21
|
"build": "tsc",
|
|
21
22
|
"lint:ts": "tsc --noEmit && eslint --cache .",
|
|
@@ -23,22 +24,23 @@
|
|
|
23
24
|
"test": "mocha"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@bhsd/code-standard": "^2.
|
|
27
|
+
"@bhsd/code-standard": "^2.4.0",
|
|
28
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.7.1",
|
|
27
29
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
28
30
|
"@types/mocha": "^10.0.10",
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
30
|
-
"@typescript-eslint/parser": "^8.
|
|
31
|
-
"esbuild": "^0.
|
|
32
|
-
"eslint": "^
|
|
33
|
-
"eslint-plugin-es-x": "^9.
|
|
34
|
-
"eslint-plugin-
|
|
35
|
-
"eslint-plugin-
|
|
36
|
-
"eslint-plugin-
|
|
37
|
-
"eslint-plugin-promise": "^7.2.1",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^8.59.1",
|
|
32
|
+
"@typescript-eslint/parser": "^8.59.1",
|
|
33
|
+
"esbuild": "^0.28.0",
|
|
34
|
+
"eslint": "^10.3.0",
|
|
35
|
+
"eslint-plugin-es-x": "^9.6.0",
|
|
36
|
+
"eslint-plugin-jsdoc": "^62.9.0",
|
|
37
|
+
"eslint-plugin-jsonc": "^3.1.2",
|
|
38
|
+
"eslint-plugin-promise": "^7.3.0",
|
|
38
39
|
"eslint-plugin-regexp": "^3.1.0",
|
|
39
|
-
"eslint-plugin-unicorn": "^
|
|
40
|
+
"eslint-plugin-unicorn": "^64.0.0",
|
|
41
|
+
"eslint-plugin-yml": "^3.3.2",
|
|
40
42
|
"mocha": "^11.7.5",
|
|
41
|
-
"typescript": "^
|
|
43
|
+
"typescript": "^6.0.3"
|
|
42
44
|
},
|
|
43
45
|
"engines": {
|
|
44
46
|
"node": "^20.19.0 || ^22.13.0 || >=24.11.0"
|