@tolki/enum 1.1.5 → 1.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/README.md CHANGED
@@ -6,7 +6,7 @@ This package provides enum utility functions similar to a PHP enum class.
6
6
 
7
7
  ## Documentation
8
8
 
9
- The full documentation for the enum utilities can be found at [https://tolki.abe.dev](https://tolki.abe.dev/enums/).
9
+ The full documentation for the enum utilities can be found at [https://tolki.abe.dev/ts/enums.html](https://tolki.abe.dev/ts/enums.html).
10
10
 
11
11
  <!-- AUTO-GENERATED-DOCS:START -->
12
12
 
package/dist/enums.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AsEnum, CaseValue, DefineEnumResult, EnumConst, FromResult } from '@tolki/types';
1
+ import { AsEnum, CaseKeys, CaseValue, DefineEnumResult, EnumConst, FromResult } from '@tolki/types';
2
2
  export type { AsEnum, CaseValue, DefineEnumResult, EnumConst, FromResult };
3
3
  /**
4
4
  * Creates an enum instance from a case value similar to PHP's `BackedEnum::from()`
@@ -9,8 +9,8 @@ export type { AsEnum, CaseValue, DefineEnumResult, EnumConst, FromResult };
9
9
  *
10
10
  * The enumObj is the published enum from the Laravel TypeScript Publish package.
11
11
  *
12
- * @see https://github.com/abetwothree/laravel-ts-publish#enum-metadata--tolki-enum-package
13
- * @see https://tolki.abe.dev/enums/enum-utilities-list.html#from
12
+ * @see https://tolki.abe.dev/ts/enums.html#metadata-the-defineenum-wrapper
13
+ * @see https://tolki.abe.dev/ts/enums.html#from
14
14
  *
15
15
  * @param enumObj - The enum const object to resolve from.
16
16
  * @param value - The case value to resolve. Must be one of the values defined in the enum const's cases.
@@ -23,7 +23,7 @@ export declare function from<TEnum extends EnumConst, const TValue extends CaseV
23
23
  *
24
24
  * Mirrors PHP's `BackedEnum::tryFrom()`.
25
25
  *
26
- * @see https://tolki.abe.dev/enums/enum-utilities-list.html#tryfrom
26
+ * @see https://tolki.abe.dev/ts/enums.html#tryfrom
27
27
  *
28
28
  * @param enumObj - The enum const object to resolve from.
29
29
  * @param value - The case value to resolve.
@@ -35,12 +35,34 @@ export declare function tryFrom<TEnum extends EnumConst, const TValue extends Ca
35
35
  *
36
36
  * Mirrors PHP's `BackedEnum::cases()`, returning one resolved instance per case defined in the enum const.
37
37
  *
38
- * @see https://tolki.abe.dev/enums/enum-utilities-list.html#cases
38
+ * @see https://tolki.abe.dev/ts/enums.html#cases
39
39
  *
40
40
  * @param enumObj - The enum const object to resolve all cases from.
41
41
  * @returns An array of resolved enum instances, one for each case.
42
42
  */
43
43
  export declare function cases<TEnum extends EnumConst>(enumObj: TEnum): Array<FromResult<TEnum, CaseValue<TEnum>>>;
44
+ /**
45
+ * Returns the backing values of all enum cases, in case order.
46
+ *
47
+ * Mirrors PHP's `array_column(Enum::cases(), 'value')`. A unit enum's values are its case names.
48
+ *
49
+ * @see https://tolki.abe.dev/ts/enums.html#values
50
+ *
51
+ * @param enumObj - The enum const object to read the case values from.
52
+ * @returns A new array with one value per case, or an empty array when the enum has no `_cases`.
53
+ */
54
+ export declare function values<TEnum extends EnumConst>(enumObj: TEnum): ReadonlyArray<CaseValue<TEnum>>;
55
+ /**
56
+ * Returns the names of all enum cases, in case order.
57
+ *
58
+ * Mirrors PHP's `array_column(Enum::cases(), 'name')`.
59
+ *
60
+ * @see https://tolki.abe.dev/ts/enums.html#keys
61
+ *
62
+ * @param enumObj - The enum const object to read the case names from.
63
+ * @returns A new array with one name per case, or an empty array when the enum has no `_cases`.
64
+ */
65
+ export declare function keys<TEnum extends EnumConst>(enumObj: TEnum): ReadonlyArray<CaseKeys<TEnum>>;
44
66
  /**
45
67
  * Factory function that creates an enriched enum object
46
68
  *
@@ -50,7 +72,7 @@ export declare function cases<TEnum extends EnumConst>(enumObj: TEnum): Array<Fr
50
72
  *
51
73
  * The original enum data is preserved and the PHP like enum methods are attached directly to the returned object.
52
74
  *
53
- * @see https://tolki.abe.dev/enums/enum-utilities-list.html#defineenum
75
+ * @see https://tolki.abe.dev/ts/enums.html#defineenum
54
76
  *
55
77
  * @param enumObj - The raw enum const object to enrich.
56
78
  * @returns The enum object with `from`, `tryFrom`, and `cases` methods bound to it.
@@ -1 +1 @@
1
- {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,MAAM,EACN,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACb,MAAM,cAAc,CAAC;AAGtB,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AAE3E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAChB,KAAK,SAAS,SAAS,EACvB,KAAK,CAAC,MAAM,SAAS,SAAS,CAAC,KAAK,CAAC,EACvC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CA8C1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CACnB,KAAK,SAAS,SAAS,EACvB,KAAK,CAAC,MAAM,SAAS,SAAS,CAAC,KAAK,CAAC,EACvC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAMjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,KAAK,SAAS,SAAS,EACzC,OAAO,EAAE,KAAK,GACf,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAI5C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,KAAK,SAAS,SAAS,EACpD,OAAO,EAAE,KAAK,GACf,gBAAgB,CAAC,KAAK,CAAC,CA2BzB"}
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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2BzB"}
package/dist/enums.js CHANGED
@@ -30,6 +30,12 @@ function r(e) {
30
30
  return (e._cases ?? []).map((n) => t(e, e[n]));
31
31
  }
32
32
  function i(e) {
33
+ return (e._cases ?? []).map((t) => e[t]);
34
+ }
35
+ function a(e) {
36
+ return [...e._cases ?? []];
37
+ }
38
+ function o(e) {
33
39
  let i = {
34
40
  from: (n) => t(e, n),
35
41
  tryFrom: (t) => n(e, t),
@@ -37,4 +43,4 @@ function i(e) {
37
43
  }, a = Object.keys(i);
38
44
  return Object.assign(Object.create(null), e, i, { _helpers: a });
39
45
  }
40
- export { r as cases, i as defineEnum, t as from, n as tryFrom };
46
+ export { r as cases, o as defineEnum, t as from, a as keys, n as tryFrom, i as values };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { cases as e, defineEnum as t, from as n, tryFrom as r } from "./enums.js";
2
- import { SortDirection as i } from "./php-enums.js";
3
- export { i as SortDirection, e as cases, t as defineEnum, n as from, r as tryFrom };
1
+ import { cases as e, defineEnum as t, from as n, keys as r, tryFrom as i, values as a } from "./enums.js";
2
+ import { SortDirection as o } from "./php-enums.js";
3
+ export { o as SortDirection, e as cases, t as defineEnum, n as from, r as keys, i as tryFrom, a as values };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@tolki/enum",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "A set of enum utilities for the Laravel TypeScript Publish PHP package.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
7
- "homepage": "https://tolki.abe.dev/enums/",
7
+ "homepage": "https://tolki.abe.dev/ts/enums.html",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/abetwothree/tolki.git",
@@ -37,7 +37,7 @@
37
37
  "tolki"
38
38
  ],
39
39
  "dependencies": {
40
- "@tolki/types": "^1.11.0",
40
+ "@tolki/types": "^1.12.0",
41
41
  "@tolki/utils": "^1.6.3"
42
42
  },
43
43
  "devDependencies": {