@bhsd/common 0.1.1 → 0.3.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/.eslintrc.cjs +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +35 -0
- package/eslintrc.browser.cjs +15 -4
- package/eslintrc.cjs +2 -2
- package/eslintrc.dist.cjs +7 -5
- package/package.json +2 -1
package/.eslintrc.cjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,16 @@ export declare const CDN = "https://testingcf.jsdelivr.net";
|
|
|
2
2
|
declare global {
|
|
3
3
|
const define: unknown;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* 解码标题
|
|
7
|
+
* @param title 标题
|
|
8
|
+
*/
|
|
9
|
+
export declare const normalizeTitle: (title: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* 包含颜色时断开字符串
|
|
12
|
+
* @param str 字符串
|
|
13
|
+
*/
|
|
14
|
+
export declare const splitColors: (str: string) => [string, number, number, boolean][];
|
|
5
15
|
/**
|
|
6
16
|
* 使用传统方法加载脚本
|
|
7
17
|
* @param src 脚本地址
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
1
|
export const CDN = 'https://testingcf.jsdelivr.net';
|
|
2
|
+
const hexColor = String.raw `#(?:[\da-f]{3,4}|(?:[\da-f]{2}){3,4})(?![\p{L}\d_])`, rgbColor = String.raw `rgba?\(\s*(?:${String.raw `[\d.]+\s+[\d.]+\s+[\d.]+(?:\s*\/\s*[\d.]+%?)?`}|${String.raw `[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+(?:\s*,\s*[\d.]+%?)?`})\s*\)`, re = new RegExp(String.raw `(^|[^\p{L}\d_])(${hexColor}|${rgbColor})`, 'giu'), span = document.createElement('span');
|
|
3
|
+
/**
|
|
4
|
+
* 解码标题
|
|
5
|
+
* @param title 标题
|
|
6
|
+
*/
|
|
7
|
+
export const normalizeTitle = (title) => {
|
|
8
|
+
const decoded = decodeURIComponent(title.replace(/%(?![\da-f]{2})/giu, '%25'));
|
|
9
|
+
if (/[<>[\]|{}]/u.test(decoded)) {
|
|
10
|
+
return decoded;
|
|
11
|
+
}
|
|
12
|
+
span.innerHTML = decoded;
|
|
13
|
+
return span.textContent;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 包含颜色时断开字符串
|
|
17
|
+
* @param str 字符串
|
|
18
|
+
*/
|
|
19
|
+
export const splitColors = (str) => {
|
|
20
|
+
re.lastIndex = 0;
|
|
21
|
+
const pieces = [];
|
|
22
|
+
let mt = re.exec(str), lastIndex = 0;
|
|
23
|
+
while (mt) {
|
|
24
|
+
const index = mt.index + mt[1].length;
|
|
25
|
+
if (index > lastIndex) {
|
|
26
|
+
pieces.push([str.slice(lastIndex, index), lastIndex, index, false]);
|
|
27
|
+
}
|
|
28
|
+
({ lastIndex } = re);
|
|
29
|
+
pieces.push([mt[2], index, lastIndex, true]);
|
|
30
|
+
mt = re.exec(str);
|
|
31
|
+
}
|
|
32
|
+
if (str.length > lastIndex) {
|
|
33
|
+
pieces.push([str.slice(lastIndex), lastIndex, str.length, false]);
|
|
34
|
+
}
|
|
35
|
+
return pieces;
|
|
36
|
+
};
|
|
2
37
|
/**
|
|
3
38
|
* 使用传统方法加载脚本
|
|
4
39
|
* @param src 脚本地址
|
package/eslintrc.browser.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const config = require('
|
|
3
|
+
const config = require('./eslintrc.cjs');
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
6
|
...config,
|
|
@@ -16,13 +16,24 @@ module.exports = {
|
|
|
16
16
|
...config.rules,
|
|
17
17
|
'prefer-object-has-own': 0,
|
|
18
18
|
'es-x/no-array-prototype-at': 2,
|
|
19
|
-
'es-x/no-
|
|
20
|
-
'es-x/no-
|
|
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-object-groupby': 2,
|
|
21
27
|
'es-x/no-object-hasown': 2,
|
|
28
|
+
'es-x/no-promise-any': 2,
|
|
29
|
+
'es-x/no-promise-withresolvers': 2,
|
|
30
|
+
'es-x/no-regexp-d-flag': 2,
|
|
22
31
|
'es-x/no-regexp-lookbehind-assertions': 2,
|
|
32
|
+
'es-x/no-regexp-v-flag': 2,
|
|
23
33
|
'es-x/no-string-prototype-at': 2,
|
|
24
|
-
'es-x/no-string-prototype-
|
|
34
|
+
'es-x/no-string-prototype-iswellformed': 2,
|
|
25
35
|
'es-x/no-string-prototype-replaceall': 2,
|
|
36
|
+
'es-x/no-string-prototype-towellformed': 2,
|
|
26
37
|
},
|
|
27
38
|
settings: {
|
|
28
39
|
...config.settings,
|
package/eslintrc.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
root: true,
|
|
5
5
|
env: {
|
|
6
|
-
|
|
6
|
+
es2024: true,
|
|
7
7
|
},
|
|
8
8
|
plugins: [
|
|
9
9
|
'@stylistic',
|
|
@@ -19,7 +19,7 @@ module.exports = {
|
|
|
19
19
|
'plugin:eslint-comments/recommended',
|
|
20
20
|
],
|
|
21
21
|
parserOptions: {
|
|
22
|
-
ecmaVersion:
|
|
22
|
+
ecmaVersion: 'latest',
|
|
23
23
|
},
|
|
24
24
|
ignorePatterns: ['dist/'],
|
|
25
25
|
rules: {
|
package/eslintrc.dist.cjs
CHANGED
|
@@ -4,17 +4,19 @@ module.exports = {
|
|
|
4
4
|
root: true,
|
|
5
5
|
env: {
|
|
6
6
|
browser: true,
|
|
7
|
-
|
|
7
|
+
es2024: true,
|
|
8
8
|
},
|
|
9
9
|
plugins: ['es-x'],
|
|
10
|
-
extends: ['plugin:es-x/restrict-to-
|
|
10
|
+
extends: ['plugin:es-x/restrict-to-es2019'],
|
|
11
11
|
parserOptions: {
|
|
12
|
-
ecmaVersion:
|
|
12
|
+
ecmaVersion: 'latest',
|
|
13
13
|
},
|
|
14
14
|
rules: {
|
|
15
|
-
'es-x/no-
|
|
15
|
+
'es-x/no-global-this': 0,
|
|
16
|
+
'es-x/no-import-meta': 0,
|
|
17
|
+
'es-x/no-promise-all-settled': 0,
|
|
16
18
|
'es-x/no-regexp-lookbehind-assertions': 2,
|
|
17
|
-
'es-x/no-string-prototype-
|
|
19
|
+
'es-x/no-string-prototype-matchall': 0,
|
|
18
20
|
},
|
|
19
21
|
settings: {
|
|
20
22
|
'es-x': {
|