@bhsd/common 0.15.0 → 1.0.1

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/cm.js DELETED
@@ -1,83 +0,0 @@
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 cm_exports = {};
20
- __export(cm_exports, {
21
- getConfig: () => getConfig,
22
- getKeywords: () => getKeywords,
23
- getParserConfig: () => getParserConfig,
24
- getVariants: () => getVariants,
25
- otherParserFunctions: () => otherParserFunctions
26
- });
27
- module.exports = __toCommonJS(cm_exports);
28
- const otherParserFunctions = /* @__PURE__ */ new Set(["msg", "raw", "subst", "safesubst"]);
29
- const getConfig = (magicWords, rule, flip) => {
30
- const words = magicWords.filter(rule);
31
- return Object.fromEntries(
32
- (flip === void 0 ? words : words.filter(({ "case-sensitive": i }) => i !== flip)).flatMap(({ aliases, name: n, "case-sensitive": i }) => aliases.map((alias) => ({
33
- alias: (i ? alias : alias.toLowerCase()).replace(/:$/u, ""),
34
- name: n
35
- }))).map(({ alias, name: n }) => [alias, n])
36
- );
37
- };
38
- const getParserConfig = (minConfig, mwConfig) => {
39
- const {
40
- tags,
41
- doubleUnderscore,
42
- urlProtocols,
43
- functionSynonyms,
44
- variableIDs,
45
- functionHooks,
46
- redirection
47
- } = mwConfig, [insensitive, sensitive] = functionSynonyms, behaviorSwitch = doubleUnderscore.map(
48
- (obj, i) => Object.entries(obj).map(([k, v]) => [
49
- k.slice(2, -2),
50
- i && typeof v === "string" ? v.toUpperCase() : v
51
- ])
52
- );
53
- for (const [k, v] of Object.entries(insensitive)) {
54
- if (k in sensitive) {
55
- delete insensitive[k];
56
- } else {
57
- insensitive[k] = v.toLowerCase();
58
- }
59
- }
60
- return {
61
- ...minConfig,
62
- ext: Object.keys(tags),
63
- parserFunction: [{ ...insensitive }, { ...sensitive, "=": "=" }, [], []],
64
- doubleUnderscore: [
65
- ...behaviorSwitch.map((entries) => entries.map(([k]) => k)),
66
- ...behaviorSwitch.map(Object.fromEntries)
67
- ],
68
- protocol: urlProtocols.replace(/\|\\?\/\\?\/$|\\(?=[:/])/gu, ""),
69
- ...variableIDs && { variable: [.../* @__PURE__ */ new Set([...variableIDs, "="])] },
70
- ...functionHooks && { functionHook: [.../* @__PURE__ */ new Set([...functionHooks.map((s) => s.toLowerCase()), "msgnw"])] },
71
- ...redirection && { redirection: redirection.map((s) => s.toLowerCase()) }
72
- };
73
- };
74
- const getVariants = (variants) => variants?.map(({ code }) => code) ?? [];
75
- const getKeywords = (magicwords, web) => ({
76
- img: Object.fromEntries(
77
- magicwords.filter(({ name: n }) => n.startsWith("img_") && n !== "img_lossy").flatMap(({ name: n, aliases }) => {
78
- const k = web ? n : n.slice(4).replace(/_/gu, "-");
79
- return (n === "img_alt" ? aliases.filter((alias) => alias.includes("$1")) : aliases).map((alias) => [alias, k]);
80
- })
81
- ),
82
- redirection: magicwords.find(({ name: n }) => n === "redirect").aliases.map((s) => s.toLowerCase())
83
- });
package/dist/cm.mjs DELETED
@@ -1,63 +0,0 @@
1
- const otherParserFunctions = /* @__PURE__ */ new Set(["msg", "raw", "subst", "safesubst"]);
2
- const getConfig = (magicWords, rule, flip) => {
3
- const words = magicWords.filter(rule);
4
- return Object.fromEntries(
5
- (flip === void 0 ? words : words.filter(({ "case-sensitive": i }) => i !== flip)).flatMap(({ aliases, name: n, "case-sensitive": i }) => aliases.map((alias) => ({
6
- alias: (i ? alias : alias.toLowerCase()).replace(/:$/u, ""),
7
- name: n
8
- }))).map(({ alias, name: n }) => [alias, n])
9
- );
10
- };
11
- const getParserConfig = (minConfig, mwConfig) => {
12
- const {
13
- tags,
14
- doubleUnderscore,
15
- urlProtocols,
16
- functionSynonyms,
17
- variableIDs,
18
- functionHooks,
19
- redirection
20
- } = mwConfig, [insensitive, sensitive] = functionSynonyms, behaviorSwitch = doubleUnderscore.map(
21
- (obj, i) => Object.entries(obj).map(([k, v]) => [
22
- k.slice(2, -2),
23
- i && typeof v === "string" ? v.toUpperCase() : v
24
- ])
25
- );
26
- for (const [k, v] of Object.entries(insensitive)) {
27
- if (k in sensitive) {
28
- delete insensitive[k];
29
- } else {
30
- insensitive[k] = v.toLowerCase();
31
- }
32
- }
33
- return {
34
- ...minConfig,
35
- ext: Object.keys(tags),
36
- parserFunction: [{ ...insensitive }, { ...sensitive, "=": "=" }, [], []],
37
- doubleUnderscore: [
38
- ...behaviorSwitch.map((entries) => entries.map(([k]) => k)),
39
- ...behaviorSwitch.map(Object.fromEntries)
40
- ],
41
- protocol: urlProtocols.replace(/\|\\?\/\\?\/$|\\(?=[:/])/gu, ""),
42
- ...variableIDs && { variable: [.../* @__PURE__ */ new Set([...variableIDs, "="])] },
43
- ...functionHooks && { functionHook: [.../* @__PURE__ */ new Set([...functionHooks.map((s) => s.toLowerCase()), "msgnw"])] },
44
- ...redirection && { redirection: redirection.map((s) => s.toLowerCase()) }
45
- };
46
- };
47
- const getVariants = (variants) => variants?.map(({ code }) => code) ?? [];
48
- const getKeywords = (magicwords, web) => ({
49
- img: Object.fromEntries(
50
- magicwords.filter(({ name: n }) => n.startsWith("img_") && n !== "img_lossy").flatMap(({ name: n, aliases }) => {
51
- const k = web ? n : n.slice(4).replace(/_/gu, "-");
52
- return (n === "img_alt" ? aliases.filter((alias) => alias.includes("$1")) : aliases).map((alias) => [alias, k]);
53
- })
54
- ),
55
- redirection: magicwords.find(({ name: n }) => n === "redirect").aliases.map((s) => s.toLowerCase())
56
- });
57
- export {
58
- getConfig,
59
- getKeywords,
60
- getParserConfig,
61
- getVariants,
62
- otherParserFunctions
63
- };
@@ -1,10 +0,0 @@
1
- import type { PublicApi, Warning, Config } from 'stylelint';
2
- /**
3
- * 使用Stylelint检查CSS代码
4
- * @param stylelint Stylelint实例
5
- * @param code CSS代码
6
- * @param additionalConfig 额外的规则
7
- * @param fix 是否修正
8
- */
9
- export declare function styleLint(stylelint: PublicApi, code: string, additionalConfig?: Config | Config['rules'] | null, fix: true): Promise<string>;
10
- export declare function styleLint(stylelint: PublicApi, code: string, additionalConfig?: Config | Config['rules'] | null): Promise<Warning[]>;
package/dist/stylelint.js DELETED
@@ -1,39 +0,0 @@
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
- async function styleLint(stylelint, code, additionalConfig, fix) {
26
- const isConfig = additionalConfig && ("extends" in additionalConfig || "rules" in additionalConfig), additionalRules = isConfig ? additionalConfig.rules : additionalConfig, rules = isConfig && "extends" in additionalConfig && additionalConfig.extends !== "stylelint-config-recommended" && !(Array.isArray(additionalConfig.extends) && additionalConfig.extends.includes("stylelint-config-recommended")) ? additionalRules ?? {} : { ...import_stylelint_config_recommended.rules, ...additionalRules }, config = {
27
- rules,
28
- computeEditInfo: true,
29
- fix: fix || false
30
- };
31
- if (isConfig) {
32
- additionalConfig.rules = rules;
33
- }
34
- if (fix) {
35
- return (await stylelint.lint({ code, config })).code;
36
- }
37
- const [result] = (await stylelint.lint({ code, config })).results;
38
- return result.warnings.filter(({ text }) => !text.startsWith("Unknown rule "));
39
- }
@@ -1,19 +0,0 @@
1
- import { rules as recommended } from "stylelint-config-recommended";
2
- async function styleLint(stylelint, code, additionalConfig, fix) {
3
- const isConfig = additionalConfig && ("extends" in additionalConfig || "rules" in additionalConfig), additionalRules = isConfig ? additionalConfig.rules : additionalConfig, rules = isConfig && "extends" in additionalConfig && additionalConfig.extends !== "stylelint-config-recommended" && !(Array.isArray(additionalConfig.extends) && additionalConfig.extends.includes("stylelint-config-recommended")) ? additionalRules ?? {} : { ...recommended, ...additionalRules }, config = {
4
- rules,
5
- computeEditInfo: true,
6
- fix: fix || false
7
- };
8
- if (isConfig) {
9
- additionalConfig.rules = rules;
10
- }
11
- if (fix) {
12
- return (await stylelint.lint({ code, config })).code;
13
- }
14
- const [result] = (await stylelint.lint({ code, config })).results;
15
- return result.warnings.filter(({ text }) => !text.startsWith("Unknown rule "));
16
- }
17
- export {
18
- styleLint
19
- };
package/dist/test.d.ts DELETED
@@ -1,38 +0,0 @@
1
- declare interface MediaWikiPage {
2
- readonly pageid: number;
3
- readonly title: string;
4
- readonly ns: number;
5
- readonly revisions?: {
6
- readonly content: string;
7
- readonly contentmodel: string;
8
- }[];
9
- }
10
- export interface SimplePage extends Pick<MediaWikiPage, 'pageid' | 'title' | 'ns'> {
11
- readonly content: string;
12
- }
13
- export interface Test {
14
- desc: string;
15
- wikitext?: string;
16
- parsed?: string;
17
- html?: string;
18
- print?: string;
19
- render?: string;
20
- }
21
- /**
22
- * 获取最近更改的页面源代码
23
- * @param url api.php网址
24
- * @param site 站点名称
25
- * @param grclimit 页面数上限
26
- */
27
- export declare const getPages: (url: string, site?: string, grclimit?: string) => Promise<SimplePage[]>;
28
- /** 重置请求 */
29
- export declare const reset: () => void;
30
- /**
31
- * 执行解析测试
32
- * @param parse 解析函数
33
- * @param retry 重试次数
34
- * @param grclimit 页面数上限
35
- */
36
- export declare const execute: (parse: (wikitext: string) => unknown, retry?: number, grclimit?: string) => Promise<void>;
37
- export declare const mochaTest: (results: unknown, parse: (wikitext: string) => string, beforeFn?: Mocha.Func | Mocha.AsyncFunc) => void;
38
- export {};
package/dist/test.js DELETED
@@ -1,172 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // test/test.ts
31
- var test_exports = {};
32
- __export(test_exports, {
33
- execute: () => execute,
34
- getPages: () => getPages,
35
- mochaTest: () => mochaTest,
36
- reset: () => reset
37
- });
38
- module.exports = __toCommonJS(test_exports);
39
- var import_fs = __toESM(require("fs"));
40
- var import_assert = __toESM(require("assert"));
41
- var import_perf_hooks = require("perf_hooks");
42
-
43
- // src/index.ts
44
- var refreshStdout = (str) => {
45
- process.stdout.write(`\x1B[K\x1B[?7l${str}\x1B[?7h\r`);
46
- };
47
-
48
- // test/test.ts
49
- var apis = [
50
- ["维基百科", "https://zh.wikipedia.org/w"],
51
- ["Wikipedia", "https://en.wikipedia.org/w"],
52
- ["ウィキペディア", "https://ja.wikipedia.org/w"]
53
- ];
54
- var c;
55
- var getPages = async (url, site, grclimit = "max") => {
56
- const qs = {
57
- action: "query",
58
- format: "json",
59
- formatversion: "2",
60
- errorformat: "plaintext",
61
- generator: "recentchanges",
62
- grcnamespace: site === "MediaWiki" ? "0|10|12|100|102|104|106" : "0|10",
63
- grclimit,
64
- grctype: "edit|new",
65
- grctoponly: "1",
66
- prop: "revisions",
67
- rvprop: "contentmodel|content",
68
- ...c
69
- }, response = await (await fetch(`${url}?${String(new URLSearchParams(qs))}`)).json();
70
- c = response.continue;
71
- return response.query.pages.map(({ pageid, title, ns, revisions }) => ({
72
- pageid,
73
- title,
74
- ns,
75
- content: revisions?.[0]?.contentmodel === "wikitext" && revisions[0].content
76
- })).filter((page) => page.content !== false);
77
- };
78
- var reset = () => {
79
- c = void 0;
80
- };
81
- var execute = async (parse, retry = 10, grclimit) => {
82
- const failures = /* @__PURE__ */ new Map();
83
- for (const [site, url] of apis) {
84
- console.log(`开始检查${site}:`);
85
- let worst;
86
- reset();
87
- try {
88
- let failed = 0, i = 0;
89
- for (let j = 0; j < retry; j++) {
90
- for (const { content, title } of await getPages(`${url}/api.php`, site, grclimit)) {
91
- refreshStdout(`${i++} ${title}`);
92
- try {
93
- const start = import_perf_hooks.performance.now();
94
- parse(content);
95
- const duration = import_perf_hooks.performance.now() - start;
96
- if (!worst || duration > worst.duration) {
97
- worst = { title, duration };
98
- }
99
- } catch (e) {
100
- console.error(`
101
- 解析 ${title} 页面时出错!`, e);
102
- failed++;
103
- }
104
- }
105
- }
106
- if (failed) {
107
- failures.set(site, failed);
108
- }
109
- console.log(`
110
- 最耗时页面:${worst.title} (${worst.duration.toFixed(3)}ms)`);
111
- } catch (e) {
112
- console.error(`访问${site}的API端口时出错!`, e);
113
- }
114
- }
115
- if (failures.size > 0) {
116
- let total = 0;
117
- for (const [site, failed] of failures) {
118
- console.error(`${site}:${failed} 个页面解析失败!`);
119
- total += failed;
120
- }
121
- throw new Error(`共有 ${total} 个页面解析失败!`);
122
- }
123
- };
124
- var tests = require("wikiparser-node/test/parserTests.json");
125
- var split = (test) => test?.parsed?.split(/(?<=<\/>)(?!$)|(?<!^)(?=<\w)/u);
126
- var mochaTest = (results, parse, beforeFn) => {
127
- describe("Parser tests", () => {
128
- for (let i = tests.length - 1; i >= 0; i--) {
129
- const test = tests[i], { wikitext, desc } = test;
130
- if (wikitext) {
131
- it(desc, () => {
132
- try {
133
- delete test.html;
134
- delete test.print;
135
- delete test.render;
136
- test.parsed = parse(wikitext);
137
- import_assert.default.deepStrictEqual(
138
- split(test),
139
- split(results.find(({ desc: d }) => d === desc))
140
- );
141
- } catch (e) {
142
- if (!(e instanceof import_assert.default.AssertionError)) {
143
- tests.splice(i, 1);
144
- }
145
- if (e instanceof Error) {
146
- Object.assign(e, { cause: { message: `
147
- ${wikitext}` } });
148
- }
149
- throw e;
150
- }
151
- });
152
- }
153
- }
154
- if (beforeFn) {
155
- before(beforeFn);
156
- }
157
- after(() => {
158
- import_fs.default.writeFileSync(
159
- "test/parserTests.json",
160
- `${JSON.stringify(tests, null, " ")}
161
- `
162
- );
163
- });
164
- });
165
- };
166
- // Annotate the CommonJS export names for ESM import in node:
167
- 0 && (module.exports = {
168
- execute,
169
- getPages,
170
- mochaTest,
171
- reset
172
- });
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- const config = require('./eslintrc.cjs');
4
-
5
- module.exports = {
6
- ...config,
7
- env: {
8
- ...config.env,
9
- browser: true,
10
- },
11
- plugins: [
12
- ...config.plugins,
13
- 'es-x',
14
- ],
15
- rules: {
16
- ...config.rules,
17
- 'prefer-object-has-own': 0,
18
- 'es-x/no-array-prototype-at': 2,
19
- 'es-x/no-array-prototype-findlast-findlastindex': 2,
20
- 'es-x/no-array-prototype-toreversed': 2,
21
- 'es-x/no-array-prototype-tosorted': 2,
22
- 'es-x/no-array-prototype-tospliced': 2,
23
- 'es-x/no-array-prototype-with': 2,
24
- 'es-x/no-error-cause': 2,
25
- 'es-x/no-map-groupby': 2,
26
- 'es-x/no-math-f16round': 2,
27
- 'es-x/no-object-groupby': 2,
28
- 'es-x/no-object-hasown': 2,
29
- 'es-x/no-promise-any': 2,
30
- 'es-x/no-promise-try': 2,
31
- 'es-x/no-promise-withresolvers': 2,
32
- 'es-x/no-regexp-d-flag': 2,
33
- 'es-x/no-regexp-escape': 2,
34
- 'es-x/no-regexp-lookbehind-assertions': 2,
35
- 'es-x/no-regexp-v-flag': 2,
36
- 'es-x/no-set-prototype-difference': 2,
37
- 'es-x/no-set-prototype-intersection': 2,
38
- 'es-x/no-set-prototype-isdisjointfrom': 2,
39
- 'es-x/no-set-prototype-issubsetof': 2,
40
- 'es-x/no-set-prototype-issupersetof': 2,
41
- 'es-x/no-set-prototype-symmetricdifference': 2,
42
- 'es-x/no-set-prototype-union': 2,
43
- 'es-x/no-string-prototype-at': 2,
44
- 'es-x/no-string-prototype-iswellformed': 2,
45
- 'es-x/no-string-prototype-replaceall': 2,
46
- 'es-x/no-string-prototype-towellformed': 2,
47
- },
48
- settings: {
49
- ...config.settings,
50
- 'es-x': {
51
- aggressive: true,
52
- },
53
- },
54
- };