@wzyjs/utils 0.2.56 → 0.2.58

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.
@@ -1,2 +1 @@
1
1
  export declare const readClipboard: () => Promise<string>;
2
- export declare const printConsoleLog: (type: string, path: string, params: any, response: any) => void;
@@ -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,
@@ -19335,6 +19337,21 @@ var performDecimalOperation = (num1, num2, operator) => {
19335
19337
  return NaN;
19336
19338
  }
19337
19339
  };
19340
+ var printConsoleLog = (type, path, params, response) => {
19341
+ const styles = {
19342
+ header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
19343
+ value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
19344
+ separator: "color: #409EFF; margin: 0 4px;"
19345
+ };
19346
+ console.groupCollapsed(`666 %c${type}%c${path}`, styles.header, styles.value);
19347
+ if (params) {
19348
+ console.table(params);
19349
+ }
19350
+ if (response) {
19351
+ console.table(response);
19352
+ }
19353
+ console.groupEnd();
19354
+ };
19338
19355
  // src/common/number.ts
19339
19356
  var getRandomNum = (min2, max2) => {
19340
19357
  return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
@@ -19440,6 +19457,53 @@ async function imageToBase64(url) {
19440
19457
  throw error;
19441
19458
  }
19442
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
+ };
19443
19507
  // src/common/dayjs.ts
19444
19508
  var import_dayjs = __toESM(require_dayjs_min());
19445
19509
  var import_isBetween = __toESM(require_isBetween());
@@ -19478,6 +19542,7 @@ var initChinaDayjs = () => {
19478
19542
  });
19479
19543
  return import_dayjs.default;
19480
19544
  };
19545
+ var chinaDayjs = initChinaDayjs();
19481
19546
  var dayjs_default = import_dayjs.default;
19482
19547
  // src/browser/index.ts
19483
19548
  var import_md5 = __toESM(require_md5());
@@ -20957,21 +21022,6 @@ var readClipboard = async () => {
20957
21022
  return "";
20958
21023
  }
20959
21024
  };
20960
- var printConsoleLog = (type, path, params, response) => {
20961
- const styles = {
20962
- header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
20963
- value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
20964
- separator: "color: #409EFF; margin: 0 4px;"
20965
- };
20966
- console.groupCollapsed(`666 %c${type}%c${path}`, styles.header, styles.value);
20967
- if (params) {
20968
- console.table(params);
20969
- }
20970
- if (response) {
20971
- console.table(response);
20972
- }
20973
- console.groupEnd();
20974
- };
20975
21025
  // src/browser/location.ts
20976
21026
  var import_lodash2 = __toESM(require_lodash());
20977
21027
  var url2Params = (url = location.href) => {
@@ -19152,6 +19152,21 @@ var performDecimalOperation = (num1, num2, operator) => {
19152
19152
  return NaN;
19153
19153
  }
19154
19154
  };
19155
+ var printConsoleLog = (type, path, params, response) => {
19156
+ const styles = {
19157
+ header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
19158
+ value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
19159
+ separator: "color: #409EFF; margin: 0 4px;"
19160
+ };
19161
+ console.groupCollapsed(`666 %c${type}%c${path}`, styles.header, styles.value);
19162
+ if (params) {
19163
+ console.table(params);
19164
+ }
19165
+ if (response) {
19166
+ console.table(response);
19167
+ }
19168
+ console.groupEnd();
19169
+ };
19155
19170
  // src/common/number.ts
19156
19171
  var getRandomNum = (min2, max2) => {
19157
19172
  return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
@@ -19257,6 +19272,53 @@ async function imageToBase64(url) {
19257
19272
  throw error;
19258
19273
  }
19259
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
+ };
19260
19322
  // src/common/dayjs.ts
19261
19323
  var import_dayjs = __toESM(require_dayjs_min(), 1);
19262
19324
  var import_isBetween = __toESM(require_isBetween(), 1);
@@ -19295,6 +19357,7 @@ var initChinaDayjs = () => {
19295
19357
  });
19296
19358
  return import_dayjs.default;
19297
19359
  };
19360
+ var chinaDayjs = initChinaDayjs();
19298
19361
  var dayjs_default = import_dayjs.default;
19299
19362
  // src/browser/index.ts
19300
19363
  var import_md5 = __toESM(require_md5(), 1);
@@ -20774,21 +20837,6 @@ var readClipboard = async () => {
20774
20837
  return "";
20775
20838
  }
20776
20839
  };
20777
- var printConsoleLog = (type, path, params, response) => {
20778
- const styles = {
20779
- header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
20780
- value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
20781
- separator: "color: #409EFF; margin: 0 4px;"
20782
- };
20783
- console.groupCollapsed(`666 %c${type}%c${path}`, styles.header, styles.value);
20784
- if (params) {
20785
- console.table(params);
20786
- }
20787
- if (response) {
20788
- console.table(response);
20789
- }
20790
- console.groupEnd();
20791
- };
20792
20840
  // src/browser/location.ts
20793
20841
  var import_lodash2 = __toESM(require_lodash(), 1);
20794
20842
  var url2Params = (url = location.href) => {
@@ -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';
@@ -2,3 +2,4 @@ export declare const delay: (time?: number) => Promise<unknown>;
2
2
  export declare const calcJsText: (expr: string, context: Record<string, any>) => any;
3
3
  export declare const optionsToEnum: (options: any[], text: string, key: string) => any;
4
4
  export declare const performDecimalOperation: (num1?: number, num2?: number, operator?: string) => number | undefined;
5
+ export declare const printConsoleLog: (type: string, path: string, params: any, response: any) => void;
@@ -0,0 +1,2 @@
1
+ export declare const interval: (intervalMinutes: number, immediately: boolean, fn: () => (void | Promise<void>)) => void;
2
+ export declare const schedule: (cronExpression: string, immediately: boolean, fn: () => (void | Promise<void>)) => void;
@@ -1,5 +1,6 @@
1
1
  export * from './mail';
2
2
  export * from './file';
3
3
  export * from './oss';
4
+ export * from './cron';
4
5
  export { default as DataStore, DataStoreOptions } from 'nedb';
5
6
  export * as cheerio from 'cheerio';