@wzyjs/utils 0.2.57 → 0.2.59

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.
@@ -10398,6 +10398,7 @@ __export(exports_browser, {
10398
10398
  consola: () => import_consola.default,
10399
10399
  coerce: () => coerce,
10400
10400
  classnames: () => import_classnames.default,
10401
+ chinaDayjs: () => chinaDayjs,
10401
10402
  calcJsText: () => calcJsText,
10402
10403
  boolean: () => booleanType,
10403
10404
  bigint: () => bigIntType,
@@ -10457,6 +10458,7 @@ __export(exports_browser, {
10457
10458
  OK: () => OK,
10458
10459
  NEVER: () => NEVER,
10459
10460
  INVALID: () => INVALID,
10461
+ Enum: () => Enum,
10460
10462
  EMPTY_PATH: () => EMPTY_PATH,
10461
10463
  Dayjs: () => import_dayjs2.Dayjs,
10462
10464
  DIRTY: () => DIRTY,
@@ -19455,6 +19457,53 @@ async function imageToBase64(url) {
19455
19457
  throw error;
19456
19458
  }
19457
19459
  }
19460
+ // src/common/enum.ts
19461
+ class EnumItem {
19462
+ label;
19463
+ value;
19464
+ extra;
19465
+ constructor(config2) {
19466
+ this.value = config2.value;
19467
+ this.label = config2.label;
19468
+ this.extra = config2.extra;
19469
+ }
19470
+ }
19471
+ var Enum = {
19472
+ create: (members) => {
19473
+ const usedValues = new Set;
19474
+ const enumObj = {};
19475
+ const map = new Map;
19476
+ const options = [];
19477
+ const extras = new Map;
19478
+ const labels = new Map;
19479
+ const enums = {};
19480
+ for (const key in members) {
19481
+ const member = members[key];
19482
+ if (!member)
19483
+ continue;
19484
+ if (usedValues.has(member.value)) {
19485
+ throw new Error(`Duplicate enum value detected: ${member.value}`);
19486
+ }
19487
+ usedValues.add(member.value);
19488
+ const item = new EnumItem(member);
19489
+ enumObj[key] = item;
19490
+ map.set(item.value, item);
19491
+ labels.set(item.value, item.label);
19492
+ options.push(item);
19493
+ enums[item.value] = { text: item.label, status: item.extra?.status };
19494
+ if (member.extra !== undefined) {
19495
+ extras.set(item.value, { ...member.extra });
19496
+ }
19497
+ }
19498
+ enumObj.map = map;
19499
+ enumObj.options = options;
19500
+ enumObj.extras = extras;
19501
+ enumObj.source = members;
19502
+ enumObj.labels = labels;
19503
+ enumObj.enums = enums;
19504
+ return enumObj;
19505
+ }
19506
+ };
19458
19507
  // src/common/dayjs.ts
19459
19508
  var import_dayjs = __toESM(require_dayjs_min());
19460
19509
  var import_isBetween = __toESM(require_isBetween());
@@ -19493,6 +19542,7 @@ var initChinaDayjs = () => {
19493
19542
  });
19494
19543
  return import_dayjs.default;
19495
19544
  };
19545
+ var chinaDayjs = initChinaDayjs();
19496
19546
  var dayjs_default = import_dayjs.default;
19497
19547
  // src/browser/index.ts
19498
19548
  var import_md5 = __toESM(require_md5());
@@ -19272,6 +19272,53 @@ async function imageToBase64(url) {
19272
19272
  throw error;
19273
19273
  }
19274
19274
  }
19275
+ // src/common/enum.ts
19276
+ class EnumItem {
19277
+ label;
19278
+ value;
19279
+ extra;
19280
+ constructor(config2) {
19281
+ this.value = config2.value;
19282
+ this.label = config2.label;
19283
+ this.extra = config2.extra;
19284
+ }
19285
+ }
19286
+ var Enum = {
19287
+ create: (members) => {
19288
+ const usedValues = new Set;
19289
+ const enumObj = {};
19290
+ const map = new Map;
19291
+ const options = [];
19292
+ const extras = new Map;
19293
+ const labels = new Map;
19294
+ const enums = {};
19295
+ for (const key in members) {
19296
+ const member = members[key];
19297
+ if (!member)
19298
+ continue;
19299
+ if (usedValues.has(member.value)) {
19300
+ throw new Error(`Duplicate enum value detected: ${member.value}`);
19301
+ }
19302
+ usedValues.add(member.value);
19303
+ const item = new EnumItem(member);
19304
+ enumObj[key] = item;
19305
+ map.set(item.value, item);
19306
+ labels.set(item.value, item.label);
19307
+ options.push(item);
19308
+ enums[item.value] = { text: item.label, status: item.extra?.status };
19309
+ if (member.extra !== undefined) {
19310
+ extras.set(item.value, { ...member.extra });
19311
+ }
19312
+ }
19313
+ enumObj.map = map;
19314
+ enumObj.options = options;
19315
+ enumObj.extras = extras;
19316
+ enumObj.source = members;
19317
+ enumObj.labels = labels;
19318
+ enumObj.enums = enums;
19319
+ return enumObj;
19320
+ }
19321
+ };
19275
19322
  // src/common/dayjs.ts
19276
19323
  var import_dayjs = __toESM(require_dayjs_min(), 1);
19277
19324
  var import_isBetween = __toESM(require_isBetween(), 1);
@@ -19310,6 +19357,7 @@ var initChinaDayjs = () => {
19310
19357
  });
19311
19358
  return import_dayjs.default;
19312
19359
  };
19360
+ var chinaDayjs = initChinaDayjs();
19313
19361
  var dayjs_default = import_dayjs.default;
19314
19362
  // src/browser/index.ts
19315
19363
  var import_md5 = __toESM(require_md5(), 1);
@@ -20949,6 +20997,7 @@ export {
20949
20997
  export_consola as consola,
20950
20998
  coerce,
20951
20999
  export_classnames as classnames,
21000
+ chinaDayjs,
20952
21001
  calcJsText,
20953
21002
  booleanType as boolean,
20954
21003
  bigIntType as bigint,
@@ -21008,6 +21057,7 @@ export {
21008
21057
  OK,
21009
21058
  NEVER,
21010
21059
  INVALID,
21060
+ Enum,
21011
21061
  EMPTY_PATH,
21012
21062
  export_Dayjs as Dayjs,
21013
21063
  DIRTY,
@@ -13,6 +13,7 @@ export declare enum Timezone {
13
13
  EuropeBerlin = "Europe/Berlin"
14
14
  }
15
15
  export declare const initChinaDayjs: () => typeof dayjs;
16
+ export declare const chinaDayjs: typeof dayjs;
16
17
  export { Dayjs } from 'dayjs';
17
18
  declare const _default: typeof dayjs & {
18
19
  isBetween: typeof isBetween;
@@ -0,0 +1,34 @@
1
+ interface Option<V, L extends string, E> {
2
+ value: V;
3
+ label?: L;
4
+ extra?: E;
5
+ }
6
+ declare class EnumItem<V, L extends string, E> {
7
+ readonly label: L;
8
+ readonly value: V;
9
+ readonly extra?: E;
10
+ constructor(config: Readonly<Option<V, L, E>>);
11
+ }
12
+ type EnumExtras<V, L extends string, E, S> = {
13
+ source: S;
14
+ map: Map<V, EnumItem<V, L, E>>;
15
+ enums: Record<string, {
16
+ text: string;
17
+ status?: string;
18
+ }>;
19
+ extras: Map<V, E>;
20
+ labels: Map<V, string>;
21
+ options: (Option<V, L, E>)[];
22
+ };
23
+ type EnumWithKeys<T extends Record<string, Readonly<Option<any, any, Record<string, any>>>>> = {
24
+ [K in keyof T]: EnumItem<T[K]['value'], T[K]['label'], T[K]['extra']>;
25
+ } & EnumExtras<T[keyof T]['value'], T[keyof T]['label'], T[keyof T]['extra'], T>;
26
+ declare global {
27
+ export type EnumKey<T extends Record<string, Option<any, any, Record<string, any>>>> = keyof T;
28
+ export type EnumLabel<T extends Record<string, Option<any, any, Record<string, any>>>> = T[keyof T]['label'];
29
+ export type EnumValue<T extends Record<string, Option<any, any, Record<string, any>>>> = T[keyof T]['value'];
30
+ }
31
+ export declare const Enum: {
32
+ create: <T extends Record<string, Readonly<Option<any, any, Record<string, any>>>>>(members: T) => EnumWithKeys<T>;
33
+ };
34
+ export {};
@@ -9,4 +9,5 @@ export * from './other';
9
9
  export * from './number';
10
10
  export * from './array';
11
11
  export * from './image';
12
- export { default as dayjs, Dayjs, Timezone, initChinaDayjs } from './dayjs';
12
+ export * from './enum';
13
+ export { default as dayjs, Dayjs, Timezone, initChinaDayjs, chinaDayjs } from './dayjs';
@@ -1,6 +1,5 @@
1
1
  export * from './mail';
2
2
  export * from './file';
3
3
  export * from './oss';
4
- export * from './cron';
5
4
  export { default as DataStore, DataStoreOptions } from 'nedb';
6
5
  export * as cheerio from 'cheerio';