@bhsd/common 0.1.1 → 0.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/.eslintrc.cjs CHANGED
@@ -5,6 +5,7 @@ const config = require('./eslintrc.browser.cjs');
5
5
  module.exports = {
6
6
  ...config,
7
7
  overrides: [
8
+ ...config.overrides,
8
9
  {
9
10
  files: '**/*.cjs',
10
11
  env: {
package/dist/index.d.ts CHANGED
@@ -2,6 +2,11 @@ export declare const CDN = "https://testingcf.jsdelivr.net";
2
2
  declare global {
3
3
  const define: unknown;
4
4
  }
5
+ /**
6
+ * 包含颜色时断开字符串
7
+ * @param str 字符串
8
+ */
9
+ export declare const splitColors: (str: string) => [string, number, number, boolean][];
5
10
  /**
6
11
  * 使用传统方法加载脚本
7
12
  * @param src 脚本地址
package/dist/index.js CHANGED
@@ -1,4 +1,27 @@
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');
3
+ /**
4
+ * 包含颜色时断开字符串
5
+ * @param str 字符串
6
+ */
7
+ export const splitColors = (str) => {
8
+ re.lastIndex = 0;
9
+ const pieces = [];
10
+ let mt = re.exec(str), lastIndex = 0;
11
+ while (mt) {
12
+ const index = mt.index + mt[1].length;
13
+ if (index > lastIndex) {
14
+ pieces.push([str.slice(lastIndex, index), lastIndex, index, false]);
15
+ }
16
+ ({ lastIndex } = re);
17
+ pieces.push([mt[2], index, lastIndex, true]);
18
+ mt = re.exec(str);
19
+ }
20
+ if (str.length > lastIndex) {
21
+ pieces.push([str.slice(lastIndex), lastIndex, str.length, false]);
22
+ }
23
+ return pieces;
24
+ };
2
25
  /**
3
26
  * 使用传统方法加载脚本
4
27
  * @param src 脚本地址
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const config = require('@bhsd/common/eslintrc.cjs');
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-global-this': 2,
20
- 'es-x/no-object-fromentries': 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-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-matchall': 2,
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
- es2022: true,
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: 13,
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
- es2022: true,
7
+ es2024: true,
8
8
  },
9
9
  plugins: ['es-x'],
10
- extends: ['plugin:es-x/restrict-to-es2018'],
10
+ extends: ['plugin:es-x/restrict-to-es2019'],
11
11
  parserOptions: {
12
- ecmaVersion: 13,
12
+ ecmaVersion: 'latest',
13
13
  },
14
14
  rules: {
15
- 'es-x/no-array-prototype-flat': 0,
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-trimstart-trimend': 0,
19
+ 'es-x/no-string-prototype-matchall': 0,
18
20
  },
19
21
  settings: {
20
22
  'es-x': {
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@bhsd/common",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "license": "GPL-2.0",
5
+ "type": "module",
5
6
  "files": [
6
7
  "/dist/",
7
8
  "*.cjs"