@bhsd/common 0.6.7 → 0.7.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
@@ -1,3 +1,4 @@
1
+ import type { LanguageServiceBase } from 'wikiparser-node/extensions/typings';
1
2
  export declare const CDN = "https://testingcf.jsdelivr.net";
2
3
  declare global {
3
4
  const define: unknown;
@@ -43,3 +44,14 @@ export declare const setObject: (key: string, value: unknown) => void;
43
44
  * @param baseVersion 基础版本号
44
45
  */
45
46
  export declare const compareVersion: (version: string, baseVersion: string) => boolean;
47
+ /**
48
+ * 获取LSP
49
+ * @param obj 关联对象
50
+ * @param include 是否嵌入
51
+ */
52
+ export declare const getLSP: (obj: object, include?: boolean) => LanguageServiceBase | undefined;
53
+ /**
54
+ * 清理内联样式中的`{`和`}`
55
+ * @param style 内联样式
56
+ */
57
+ export declare const sanitizeInlineStyle: (style: string) => string;
package/dist/index.js CHANGED
@@ -21,11 +21,13 @@ __export(index_exports, {
21
21
  CDN: () => CDN,
22
22
  compareVersion: () => compareVersion,
23
23
  decodeHTML: () => decodeHTML,
24
+ getLSP: () => getLSP,
24
25
  getObject: () => getObject,
25
26
  loadScript: () => loadScript,
26
27
  normalizeTitle: () => normalizeTitle,
27
28
  numToHex: () => numToHex,
28
29
  rawurldecode: () => rawurldecode,
30
+ sanitizeInlineStyle: () => sanitizeInlineStyle,
29
31
  setObject: () => setObject,
30
32
  splitColors: () => splitColors
31
33
  });
@@ -108,3 +110,16 @@ const compareVersion = (version, baseVersion) => {
108
110
  const [major, minor] = parseVersion(version), [baseMajor, baseMinor] = parseVersion(baseVersion);
109
111
  return major > baseMajor || major === baseMajor && minor >= baseMinor;
110
112
  };
113
+ const lsps = /* @__PURE__ */ new WeakMap();
114
+ const getLSP = (obj, include) => {
115
+ const path = "npm/wikiparser-node/extensions/dist";
116
+ void loadScript(`${path}/base.min.js`, "wikiparse");
117
+ void loadScript(`${path}/lsp.min.js`, "wikiparse.LanguageService");
118
+ if (typeof wikiparse !== "object" || !wikiparse.LanguageService || lsps.has(obj)) {
119
+ return lsps.get(obj);
120
+ }
121
+ const lsp = new wikiparse.LanguageService(include);
122
+ lsps.set(obj, lsp);
123
+ return lsp;
124
+ };
125
+ const sanitizeInlineStyle = (style) => style.replace(/[{}]/gu, (p) => p === "{" ? "{" : "}");
package/dist/index.mjs CHANGED
@@ -76,15 +76,30 @@ const compareVersion = (version, baseVersion) => {
76
76
  const [major, minor] = parseVersion(version), [baseMajor, baseMinor] = parseVersion(baseVersion);
77
77
  return major > baseMajor || major === baseMajor && minor >= baseMinor;
78
78
  };
79
+ const lsps = /* @__PURE__ */ new WeakMap();
80
+ const getLSP = (obj, include) => {
81
+ const path = "npm/wikiparser-node/extensions/dist";
82
+ void loadScript(`${path}/base.min.js`, "wikiparse");
83
+ void loadScript(`${path}/lsp.min.js`, "wikiparse.LanguageService");
84
+ if (typeof wikiparse !== "object" || !wikiparse.LanguageService || lsps.has(obj)) {
85
+ return lsps.get(obj);
86
+ }
87
+ const lsp = new wikiparse.LanguageService(include);
88
+ lsps.set(obj, lsp);
89
+ return lsp;
90
+ };
91
+ const sanitizeInlineStyle = (style) => style.replace(/[{}]/gu, (p) => p === "{" ? "{" : "}");
79
92
  export {
80
93
  CDN,
81
94
  compareVersion,
82
95
  decodeHTML,
96
+ getLSP,
83
97
  getObject,
84
98
  loadScript,
85
99
  normalizeTitle,
86
100
  numToHex,
87
101
  rawurldecode,
102
+ sanitizeInlineStyle,
88
103
  setObject,
89
104
  splitColors
90
105
  };
@@ -0,0 +1,8 @@
1
+ import type { PublicApi, Warning } from 'stylelint';
2
+ /**
3
+ * 使用Stylelint检查CSS代码
4
+ * @param stylelint Stylelint实例
5
+ * @param code CSS代码
6
+ * @param additionalRules 额外的规则
7
+ */
8
+ export declare const styleLint: (stylelint: PublicApi, code: string, additionalRules?: Record<string, unknown>) => Promise<Warning[]>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var stylelint_exports = {};
20
+ __export(stylelint_exports, {
21
+ styleLint: () => styleLint
22
+ });
23
+ module.exports = __toCommonJS(stylelint_exports);
24
+ var import_stylelint_config_recommended = require("stylelint-config-recommended");
25
+ const styleLint = async (stylelint, code, additionalRules) => {
26
+ const config = {
27
+ rules: { ...import_stylelint_config_recommended.rules, ...additionalRules }
28
+ };
29
+ return (await stylelint.lint({ code, config })).results.flatMap(({ warnings }) => warnings).filter(({ text }) => !text.startsWith("Unknown rule "));
30
+ };
@@ -0,0 +1,10 @@
1
+ import { rules } from "stylelint-config-recommended";
2
+ const styleLint = async (stylelint, code, additionalRules) => {
3
+ const config = {
4
+ rules: { ...rules, ...additionalRules }
5
+ };
6
+ return (await stylelint.lint({ code, config })).results.flatMap(({ warnings }) => warnings).filter(({ text }) => !text.startsWith("Unknown rule "));
7
+ };
8
+ export {
9
+ styleLint
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/common",
3
- "version": "0.6.7",
3
+ "version": "0.7.0",
4
4
  "license": "MIT",
5
5
  "author": "Bhsd",
6
6
  "files": [
@@ -14,6 +14,11 @@
14
14
  "import": "./dist/index.mjs",
15
15
  "require": "./dist/index.js"
16
16
  },
17
+ "./dist/stylelint": {
18
+ "types": "./dist/stylelint.d.ts",
19
+ "import": "./dist/stylelint.mjs",
20
+ "require": "./dist/stylelint.js"
21
+ },
17
22
  "./*.cjs": "./*.cjs",
18
23
  "./package.json": "./package.json"
19
24
  },
@@ -24,10 +29,15 @@
24
29
  },
25
30
  "scripts": {
26
31
  "prepublishOnly": "npm run build",
27
- "build": "tsc --emitDeclarationOnly && esbuild src/index.ts --charset=utf8 --target=es2024 --format=cjs --outfile=dist/index.js && esbuild src/index.ts --charset=utf8 --target=es2024 --format=esm --outfile=dist/index.mjs",
32
+ "build": "tsc --emitDeclarationOnly && esbuild src/index.ts src/stylelint.ts --charset=utf8 --target=es2024 --format=cjs --outdir=dist && esbuild src/index.ts src/stylelint.ts --charset=utf8 --target=es2024 --format=esm --outdir=dist --out-extension:.js=.mjs",
28
33
  "lint:ts": "tsc --noEmit && eslint --cache .",
29
34
  "lint": "npm run lint:ts"
30
35
  },
36
+ "dependencies": {
37
+ "stylelint": "^16.14.1",
38
+ "stylelint-config-recommended": "^15.0.0",
39
+ "wikiparser-node": "^1.17.0"
40
+ },
31
41
  "devDependencies": {
32
42
  "@stylistic/eslint-plugin": "^3.1.0",
33
43
  "@stylistic/stylelint-plugin": "^3.1.2",
@@ -48,8 +58,6 @@
48
58
  "eslint-plugin-unicorn": "^56.0.1",
49
59
  "http-server": "^14.1.1",
50
60
  "mocha": "^11.1.0",
51
- "stylelint": "^16.14.1",
52
- "stylelint-config-recommended": "^15.0.0",
53
61
  "typescript": "^5.7.3"
54
62
  }
55
63
  }