@bhsd/common 2.0.0 → 2.1.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 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之间的数字
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) => Math.round(d * 255).toString(16).padStart(2, '0');
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.replace(/;/gu, ' '));
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 => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/common",
3
- "version": "2.0.0",
3
+ "version": "2.1.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,25 @@
23
24
  "test": "mocha"
24
25
  },
25
26
  "devDependencies": {
26
- "@bhsd/code-standard": "^2.1.1",
27
+ "@bhsd/code-standard": "^2.3.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.57.0",
30
- "@typescript-eslint/parser": "^8.57.0",
31
- "esbuild": "^0.27.4",
32
- "eslint": "^9.39.4",
33
- "eslint-plugin-es-x": "^9.5.0",
34
- "eslint-plugin-eslint-comments": "^3.2.0",
35
- "eslint-plugin-jsdoc": "^62.7.1",
36
- "eslint-plugin-jsonc": "^3.1.1",
31
+ "@typescript-eslint/eslint-plugin": "^8.59.0",
32
+ "@typescript-eslint/parser": "^8.59.0",
33
+ "esbuild": "^0.28.0",
34
+ "eslint": "^10.2.1",
35
+ "eslint-plugin-es-x": "^9.6.0",
36
+ "eslint-plugin-jsdoc": "^62.9.0",
37
+ "eslint-plugin-jsonc": "^3.1.2",
37
38
  "eslint-plugin-promise": "^7.2.1",
38
39
  "eslint-plugin-regexp": "^3.1.0",
39
- "eslint-plugin-unicorn": "^63.0.0",
40
+ "eslint-plugin-unicorn": "^64.0.0",
40
41
  "mocha": "^11.7.5",
41
- "typescript": "^5.9.3"
42
+ "typescript": "^6.0.3"
43
+ },
44
+ "overrides": {
45
+ "eslint": "^10.2.1"
42
46
  },
43
47
  "engines": {
44
48
  "node": "^20.19.0 || ^22.13.0 || >=24.11.0"