@ceale/util 1.21.1 → 1.22.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/README.md CHANGED
@@ -47,10 +47,13 @@
47
47
  - `type` anyobject
48
48
  - `type` AnyClass
49
49
  - `type` RequireOne
50
- - `enum_v2.ts`:
50
+ - `enum_v3.ts`
51
51
  - Enum()
52
52
  - EnumOf<>
53
- - `enum_v1.ts`
53
+ - namespace: `EnumV2`
54
+ - Enum()
55
+ - EnumOf<>
56
+ - namespace: `EnumV1`
54
57
  - defineEnum()
55
58
  - Enum()
56
59
  - EnumKeys<>
package/dist/cjs/index.js CHANGED
@@ -22,8 +22,9 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  ClassUtil: () => ClassUtil,
24
24
  CubicBezier: () => CubicBezier,
25
- Enum: () => Enum2,
25
+ Enum: () => Enum3,
26
26
  EnumV1: () => enum_v1_exports,
27
+ EnumV2: () => enum_v2_exports,
27
28
  QuadraticBezier: () => QuadraticBezier,
28
29
  assert: () => assert,
29
30
  css: () => css,
@@ -455,6 +456,10 @@ var Enum = (keys) => ({
455
456
  });
456
457
 
457
458
  // src/enum_v2.ts
459
+ var enum_v2_exports = {};
460
+ __export(enum_v2_exports, {
461
+ Enum: () => Enum2
462
+ });
458
463
  var Enum2 = (...values) => {
459
464
  const obj = {};
460
465
  values.forEach((value) => obj[value.toUpperCase()] = value);
@@ -462,3 +467,17 @@ var Enum2 = (...values) => {
462
467
  obj.includes = (value) => values.includes(value);
463
468
  return obj;
464
469
  };
470
+
471
+ // src/enum_v3.ts
472
+ var Enum3 = (definition) => {
473
+ const values = Object.values(definition);
474
+ const methods = {
475
+ values: () => values,
476
+ includes: (value) => values.includes(value)
477
+ };
478
+ Object.defineProperties(methods, {
479
+ values: { enumerable: false },
480
+ includes: { enumerable: false }
481
+ });
482
+ return Object.freeze(Object.assign(definition, methods));
483
+ };
package/dist/esm/index.js CHANGED
@@ -418,6 +418,10 @@ var Enum = (keys) => ({
418
418
  });
419
419
 
420
420
  // src/enum_v2.ts
421
+ var enum_v2_exports = {};
422
+ __export(enum_v2_exports, {
423
+ Enum: () => Enum2
424
+ });
421
425
  var Enum2 = (...values) => {
422
426
  const obj = {};
423
427
  values.forEach((value) => obj[value.toUpperCase()] = value);
@@ -425,11 +429,26 @@ var Enum2 = (...values) => {
425
429
  obj.includes = (value) => values.includes(value);
426
430
  return obj;
427
431
  };
432
+
433
+ // src/enum_v3.ts
434
+ var Enum3 = (definition) => {
435
+ const values = Object.values(definition);
436
+ const methods = {
437
+ values: () => values,
438
+ includes: (value) => values.includes(value)
439
+ };
440
+ Object.defineProperties(methods, {
441
+ values: { enumerable: false },
442
+ includes: { enumerable: false }
443
+ });
444
+ return Object.freeze(Object.assign(definition, methods));
445
+ };
428
446
  export {
429
447
  ClassUtil,
430
448
  CubicBezier,
431
- Enum2 as Enum,
449
+ Enum3 as Enum,
432
450
  enum_v1_exports as EnumV1,
451
+ enum_v2_exports as EnumV2,
433
452
  QuadraticBezier,
434
453
  assert,
435
454
  css,
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 提取枚举对象中的枚举值
3
+ */
4
+ export type EnumOf<T extends Record<string, any>> = Extract<T[keyof T], string | number>;
5
+ /**
6
+ * 创建一个枚举对象
7
+ * @param 一个枚举定义对象,键为枚举名,值为字符串或数字
8
+ * @returns 枚举对象,包含原始键值对和枚举方法
9
+ * @example
10
+ * const Example = Enum({ ValueA: "value_a", ValueB: "value_b" })
11
+ * // {
12
+ * // ValueA: "value_a",
13
+ * // ValueB: "value_b",
14
+ * // values(): ["value_a", "value_b"],
15
+ * // includes(value: any): boolean
16
+ * // }
17
+ * */
18
+ export declare const Enum: <const T extends Record<string, string | number>>(definition: T) => Readonly<T & {
19
+ values: () => T[keyof T][];
20
+ includes: (value: any) => value is T[keyof T];
21
+ }>;
@@ -9,4 +9,5 @@ export * from "./error";
9
9
  export * from "./type";
10
10
  export * from "./object";
11
11
  export * as EnumV1 from "./enum_v1";
12
- export * from "./enum_v2";
12
+ export * as EnumV2 from "./enum_v2";
13
+ export * from "./enum_v3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ceale/util",
3
- "version": "1.21.1",
3
+ "version": "1.22.0",
4
4
  "author": "Ceale",
5
5
  "description": "小工具集",
6
6
  "repository": {