@tolki/enum 1.1.5 → 1.2.1

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,9 +9,10 @@ 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
+ * @sideEffects asserts - Throws when the value matches no case.
15
16
  * @param enumObj - The enum const object to resolve from.
16
17
  * @param value - The case value to resolve. Must be one of the values defined in the enum const's cases.
17
18
  * @returns The resolved enum case with its associated methods and properties for the value provided.
@@ -23,7 +24,7 @@ export declare function from<TEnum extends EnumConst, const TValue extends CaseV
23
24
  *
24
25
  * Mirrors PHP's `BackedEnum::tryFrom()`.
25
26
  *
26
- * @see https://tolki.abe.dev/enums/enum-utilities-list.html#tryfrom
27
+ * @see https://tolki.abe.dev/ts/enums.html#tryfrom
27
28
  *
28
29
  * @param enumObj - The enum const object to resolve from.
29
30
  * @param value - The case value to resolve.
@@ -35,12 +36,34 @@ export declare function tryFrom<TEnum extends EnumConst, const TValue extends Ca
35
36
  *
36
37
  * Mirrors PHP's `BackedEnum::cases()`, returning one resolved instance per case defined in the enum const.
37
38
  *
38
- * @see https://tolki.abe.dev/enums/enum-utilities-list.html#cases
39
+ * @see https://tolki.abe.dev/ts/enums.html#cases
39
40
  *
40
41
  * @param enumObj - The enum const object to resolve all cases from.
41
42
  * @returns An array of resolved enum instances, one for each case.
42
43
  */
43
44
  export declare function cases<TEnum extends EnumConst>(enumObj: TEnum): Array<FromResult<TEnum, CaseValue<TEnum>>>;
45
+ /**
46
+ * Returns the backing values of all enum cases, in case order.
47
+ *
48
+ * Mirrors PHP's `array_column(Enum::cases(), 'value')`. A unit enum's values are its case names.
49
+ *
50
+ * @see https://tolki.abe.dev/ts/enums.html#values
51
+ *
52
+ * @param enumObj - The enum const object to read the case values from.
53
+ * @returns A new array with one value per case, or an empty array when the enum has no `_cases`.
54
+ */
55
+ export declare function values<TEnum extends EnumConst>(enumObj: TEnum): ReadonlyArray<CaseValue<TEnum>>;
56
+ /**
57
+ * Returns the names of all enum cases, in case order.
58
+ *
59
+ * Mirrors PHP's `array_column(Enum::cases(), 'name')`.
60
+ *
61
+ * @see https://tolki.abe.dev/ts/enums.html#keys
62
+ *
63
+ * @param enumObj - The enum const object to read the case names from.
64
+ * @returns A new array with one name per case, or an empty array when the enum has no `_cases`.
65
+ */
66
+ export declare function keys<TEnum extends EnumConst>(enumObj: TEnum): ReadonlyArray<CaseKeys<TEnum>>;
44
67
  /**
45
68
  * Factory function that creates an enriched enum object
46
69
  *
@@ -50,7 +73,7 @@ export declare function cases<TEnum extends EnumConst>(enumObj: TEnum): Array<Fr
50
73
  *
51
74
  * The original enum data is preserved and the PHP like enum methods are attached directly to the returned object.
52
75
  *
53
- * @see https://tolki.abe.dev/enums/enum-utilities-list.html#defineenum
76
+ * @see https://tolki.abe.dev/ts/enums.html#defineenum
54
77
  *
55
78
  * @param enumObj - The raw enum const object to enrich.
56
79
  * @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,"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C,KAAK,SAAS,SAAS,EACpD,OAAO,EAAE,KAAK,GACf,gBAAgB,CAAC,KAAK,CAAC,CA2BzB"}
package/dist/enums.js CHANGED
@@ -19,6 +19,7 @@ function t(t, n) {
19
19
  for (let [e, n] of Object.entries(t)) l.has(e) || r.has(e) || c.has(e) || (a[e] = o.has(e) ? n[i] : n);
20
20
  return a.name = i, a;
21
21
  }
22
+ /* @__NO_SIDE_EFFECTS__ */
22
23
  function n(e, n) {
23
24
  try {
24
25
  return t(e, n);
@@ -26,15 +27,25 @@ function n(e, n) {
26
27
  return null;
27
28
  }
28
29
  }
30
+ /* @__NO_SIDE_EFFECTS__ */
29
31
  function r(e) {
30
32
  return (e._cases ?? []).map((n) => t(e, e[n]));
31
33
  }
34
+ /* @__NO_SIDE_EFFECTS__ */
32
35
  function i(e) {
36
+ return (e._cases ?? []).map((t) => e[t]);
37
+ }
38
+ /* @__NO_SIDE_EFFECTS__ */
39
+ function a(e) {
40
+ return [...e._cases ?? []];
41
+ }
42
+ /* @__NO_SIDE_EFFECTS__ */
43
+ function o(e) {
33
44
  let i = {
34
45
  from: (n) => t(e, n),
35
- tryFrom: (t) => n(e, t),
36
- cases: () => r(e)
46
+ tryFrom: (t) => /* @__PURE__ */ n(e, t),
47
+ cases: () => /* @__PURE__ */ r(e)
37
48
  }, a = Object.keys(i);
38
49
  return Object.assign(Object.create(null), e, i, { _helpers: a });
39
50
  }
40
- export { r as cases, i as defineEnum, t as from, n as tryFrom };
51
+ 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/dist/php-enums.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineEnum as e } from "./enums.js";
2
2
  // src/php-enums.ts
3
- var t = e({
3
+ var t = /* @__PURE__ */ e({
4
4
  Ascending: "Ascending",
5
5
  Descending: "Descending",
6
6
  backed: !1,
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId,MAAM,WAAW,uBAAuB;IACpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,GAAE,uBAA4B,GACtC,MAAM,CAmPR"}
1
+ {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId,MAAM,WAAW,uBAAuB;IACpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,wBAAgB,gBAAgB,CAC5B,OAAO,GAAE,uBAA4B,GACtC,MAAM,CAmPR"}
@@ -4,7 +4,8 @@ import n from "node:path";
4
4
  import { promisify as r } from "node:util";
5
5
  import { normalizePath as i } from "vite";
6
6
  // src/vite-plugin.ts
7
- var a = r(e);
7
+ var a = /* @__PURE__ */ r(e);
8
+ /* @__NO_SIDE_EFFECTS__ */
8
9
  function o(e = {}) {
9
10
  let { command: r = "php artisan ts:publish", filename: o = "laravel-ts-collected-files.json", directory: s = "resources/js/types/data/", runOnDevStart: c = !1, runOnBuildStart: l = !0, reload: u = !0, failOnError: d, sourceCommand: f, onBuildOnlyEnums: p = !0, quiet: m = !0 } = e, h = f === !1 ? !1 : f ?? `${r} --source="{file}"`, g, _, v = /* @__PURE__ */ new Map(), y = "", b = !1, x = [], S = "[laravel-ts-publish]", C = async () => {
10
11
  v.clear();
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@tolki/enum",
3
- "version": "1.1.5",
3
+ "version": "1.2.1",
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,8 +37,8 @@
37
37
  "tolki"
38
38
  ],
39
39
  "dependencies": {
40
- "@tolki/types": "^1.11.0",
41
- "@tolki/utils": "^1.6.3"
40
+ "@tolki/utils": "^1.6.4",
41
+ "@tolki/types": "^1.12.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "vite": "^8.3.5"