@peng_kai/kit 0.3.0-beta.7 → 0.3.0-beta.8

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.
@@ -0,0 +1,4 @@
1
+ import fingerprintjs from '@fingerprintjs/fingerprintjs';
2
+ export * from '@fingerprintjs/fingerprintjs';
3
+
4
+ export default fingerprintjs;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.3.0-beta.7",
4
+ "version": "0.3.0-beta.8",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",
@@ -14,25 +14,25 @@
14
14
  },
15
15
  "peerDependencies": {
16
16
  "ant-design-vue": "4.2.5",
17
- "vue": "3.5.11",
18
- "vue-router": "4.4.5"
17
+ "vue": "3.5.13",
18
+ "vue-router": "4.5.0"
19
19
  },
20
20
  "dependencies": {
21
21
  "@aws-sdk/client-s3": "^3.667.0",
22
22
  "@aws-sdk/lib-storage": "^3.667.0",
23
- "@babel/generator": "^7.25.7",
24
- "@babel/parser": "^7.25.7",
25
- "@babel/traverse": "^7.25.7",
26
- "@babel/types": "^7.25.7",
23
+ "@babel/generator": "^7.26.5",
24
+ "@babel/parser": "^7.26.7",
25
+ "@babel/traverse": "^7.26.7",
26
+ "@babel/types": "^7.26.7",
27
27
  "@ckeditor/ckeditor5-vue": "^5.1.0",
28
- "@fingerprintjs/fingerprintjs": "^4.5.0",
29
- "@tanstack/vue-query": "^5.59.1",
30
- "@vueuse/components": "^11.1.0",
31
- "@vueuse/core": "^11.1.0",
32
- "@vueuse/router": "^11.1.0",
28
+ "@fingerprintjs/fingerprintjs": "^4.5.1",
29
+ "@tanstack/vue-query": "^5.64.2",
30
+ "@vueuse/components": "^12.5.0",
31
+ "@vueuse/core": "^12.5.0",
32
+ "@vueuse/router": "^12.5.0",
33
33
  "a-calc": "^2.2.10",
34
34
  "archiver": "^7.0.1",
35
- "axios": "^1.7.7",
35
+ "axios": "^1.7.9",
36
36
  "bignumber.js": "^9.1.2",
37
37
  "chokidar": "^3.6.0",
38
38
  "crypto-es": "^2.1.0",
@@ -43,11 +43,11 @@
43
43
  "localstorage-slim": "^2.7.1",
44
44
  "lodash-es": "^4.17.21",
45
45
  "nprogress": "^0.2.0",
46
- "pinia": "^2.2.4",
46
+ "pinia": "^2.3.1",
47
47
  "tsx": "^4.16.00",
48
- "vue": "^3.5.11",
49
- "vue-i18n": "^10.0.4",
50
- "vue-router": "^4.4.5"
48
+ "vue": "^3.5.13",
49
+ "vue-i18n": "^11.0.1",
50
+ "vue-router": "^4.5.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@ckeditor/ckeditor5-adapter-ckfinder": "^41.1.0",
@@ -82,14 +82,14 @@
82
82
  "@ckeditor/ckeditor5-upload": "^41.1.0",
83
83
  "@ckeditor/ckeditor5-word-count": "^41.1.0",
84
84
  "@peng_kai/lint": "^0.1.0",
85
- "@types/archiver": "^6.0.2",
85
+ "@types/archiver": "^6.0.3",
86
86
  "@types/crypto-js": "^4.2.2",
87
87
  "@types/lodash-es": "^4.17.12",
88
- "@types/node": "^20.16.11",
88
+ "@types/node": "^20.17.16",
89
89
  "@types/nprogress": "^0.2.3",
90
90
  "ant-design-vue": "^4.2.5",
91
- "type-fest": "^4.26.1",
92
- "typescript": "^5.6.3",
93
- "vue-component-type-helpers": "^2.1.6"
91
+ "type-fest": "^4.33.0",
92
+ "typescript": "^5.7.3",
93
+ "vue-component-type-helpers": "^2.2.0"
94
94
  }
95
95
  }
@@ -1,3 +1,4 @@
1
+ // 废弃,转移至 ./locale/index.ts
1
2
  import { mapKeys } from 'lodash-es';
2
3
 
3
4
  interface ILocaleMeta {
@@ -1,4 +1,5 @@
1
1
  import { mapKeys } from 'lodash-es';
2
+ import { normalizeLocaleCode } from './helpers';
2
3
 
3
4
  interface ILocaleMeta {
4
5
  label: string
@@ -110,6 +111,26 @@ export class LocaleManager {
110
111
  return meta;
111
112
  }
112
113
 
114
+ /**
115
+ * 获取可用的区域
116
+ */
117
+ public findMatchingLocale(targetLocale: string) {
118
+ targetLocale = normalizeLocaleCode(targetLocale);
119
+ const codeMatrix = this.localesAvailable.map(locale => [locale, ...this.localeMetas[locale].codes]);
120
+ let matchedLocale = '';
121
+
122
+ for (const codes of codeMatrix) {
123
+ const matched = codes.some(code => code.toUpperCase().startsWith(targetLocale.toUpperCase()));
124
+
125
+ if (matched) {
126
+ matchedLocale = codes[0];
127
+ break;
128
+ }
129
+ }
130
+
131
+ return matchedLocale;
132
+ }
133
+
113
134
  private clearUrlLocale() {
114
135
  const url = new URL(location.href);
115
136
  url.searchParams.delete('locale');
@@ -1,3 +1,4 @@
1
+ import type { I18nOptions } from 'vue-i18n';
1
2
  import { omitBy } from '../../libs/lodash-es';
2
3
 
3
4
  /**
@@ -5,7 +6,7 @@ import { omitBy } from '../../libs/lodash-es';
5
6
  */
6
7
  export function normalizeLocaleCode(code: string) {
7
8
  // 移除所有空白字符并转换为小写
8
- const normalized = code.replace(/\s/g, '').toLowerCase();
9
+ const normalized = code.replace(/\s/g, '').replace('_', '-').toLowerCase();
9
10
 
10
11
  // 处理特殊情况:中文
11
12
  if (normalized === 'zh-cn' || normalized === 'zh-hans')
@@ -32,6 +33,14 @@ export function omitLocale(modules: Record<string, any>, excludes: string[] = []
32
33
  return omitBy(modules, (_, path) => excludes.some(locale => path.includes(locale)));
33
34
  }
34
35
 
36
+ /** 添加语言格式 */
37
+ export function addDatetimeFormat<T extends string>(name: T, config: NonNullable<I18nOptions['datetimeFormats']>[string][string]) {
38
+ return {
39
+ [name]: config,
40
+ [`${name}-utc`]: { ...config, timeZone: 'UTC' },
41
+ } as Record<T | `${T}-utc`, typeof config>;
42
+ }
43
+
35
44
  /**
36
45
  * 加密 JSON 消息
37
46
  */
@@ -0,0 +1,31 @@
1
+ import { type MaybeRefOrGetter, computed, isReactive, reactive, toValue } from 'vue';
2
+
3
+ export class StorageKey<F extends Record<string, string | number>> {
4
+ public factors: F;
5
+ private split = '_';
6
+
7
+ public constructor(factors: F, private order: Array<keyof F>) {
8
+ this.factors = isReactive(factors) ? factors : reactive(factors) as F;
9
+ }
10
+
11
+ /**
12
+ * 构建存储键
13
+ * @param parts 键的部分
14
+ * @param excludeFactors 排除键的因素
15
+ */
16
+ public build(parts: Array<MaybeRefOrGetter<F[string]>>, excludeFactors: Array<keyof F> | boolean = false) {
17
+ const finalKey = computed(() => {
18
+ const thisKeys = parts.map(k => String(toValue(k)));
19
+ const factorKeys = Array.isArray(excludeFactors)
20
+ ? this.order.filter(k => !excludeFactors?.includes(k)).map(k => this.factors[k])
21
+ : excludeFactors
22
+ ? []
23
+ : this.order.map(k => this.factors[k]);
24
+ const thisStr = thisKeys.join(this.split);
25
+ const factorStr = factorKeys.join(this.split);
26
+ return `${factorStr}${factorStr ? this.split : ''}${thisStr}`;
27
+ });
28
+
29
+ return finalKey;
30
+ }
31
+ }