@tolki/enum 1.1.1 → 1.1.3

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/dist/enums.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AsEnum, CaseValue, DefineEnumResult, EnumConst, FromResult } from '../packages/types/src/index.ts';
1
+ import { AsEnum, 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()`
@@ -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;AAEtB,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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@@ -1,59 +1,60 @@
1
- function a(e, t) {
1
+ import { isArray as y } from "@tolki/utils";
2
+ function a(e, s) {
2
3
  const n = new Set(e._cases ?? []);
3
4
  let r;
4
- for (const s of n)
5
- if (e[s] === t) {
6
- r = s;
5
+ for (const t of n)
6
+ if (e[t] === s) {
7
+ r = t;
7
8
  break;
8
9
  }
9
10
  if (!r) {
10
- const s = Array.from(n).map((c) => e[c]);
11
+ const t = Array.from(n).map((c) => e[c]);
11
12
  throw new Error(
12
- `Value "${String(t)}" does not match any case in the enum. Values: ${s.join(", ")}, Cases: ${[...n].join(", ")}`
13
+ `Value "${String(s)}" does not match any case in the enum. Values: ${t.join(", ")}, Cases: ${[...n].join(", ")}`
13
14
  );
14
15
  }
15
- const o = { value: t }, h = new Set(e._methods ?? []), i = e._helpers, f = new Set(
16
- Array.isArray(i) ? i : []
16
+ const o = { value: s }, f = new Set(e._methods ?? []), i = e._helpers, h = new Set(
17
+ y(i) ? i : []
17
18
  ), l = /* @__PURE__ */ new Set([
18
19
  "_cases",
19
20
  "_methods",
20
21
  "_helpers",
21
22
  "_static"
22
23
  ]);
23
- for (const [s, c] of Object.entries(e))
24
- l.has(s) || n.has(s) || f.has(s) || (h.has(s) ? o[s] = c[r] : o[s] = c);
24
+ for (const [t, c] of Object.entries(e))
25
+ l.has(t) || n.has(t) || h.has(t) || (f.has(t) ? o[t] = c[r] : o[t] = c);
25
26
  return o.name = r, o;
26
27
  }
27
- function y(e, t) {
28
+ function p(e, s) {
28
29
  try {
29
- return a(e, t);
30
+ return a(e, s);
30
31
  } catch {
31
32
  return null;
32
33
  }
33
34
  }
34
- function p(e) {
35
+ function u(e) {
35
36
  return (e._cases ?? []).map(
36
- (t) => a(e, e[t])
37
+ (s) => a(e, e[s])
37
38
  );
38
39
  }
39
- function u(e) {
40
- const t = {
40
+ function m(e) {
41
+ const s = {
41
42
  from: (r) => a(e, r),
42
- tryFrom: (r) => y(e, r),
43
- cases: () => p(e)
44
- }, n = Object.keys(t);
43
+ tryFrom: (r) => p(e, r),
44
+ cases: () => u(e)
45
+ }, n = Object.keys(s);
45
46
  return Object.assign(
46
47
  /* @__PURE__ */ Object.create(null),
47
48
  e,
48
- t,
49
+ s,
49
50
  {
50
51
  _helpers: n
51
52
  }
52
53
  );
53
54
  }
54
55
  export {
55
- p as cases,
56
- u as defineEnum,
56
+ u as cases,
57
+ m as defineEnum,
57
58
  a as from,
58
- y as tryFrom
59
+ p as tryFrom
59
60
  };
@@ -1,4 +1,4 @@
1
- import { DefineEnumResult } from '../packages/ts/src/index.ts';
1
+ import { DefineEnumResult } from '@tolki/ts';
2
2
  export declare const SortDirection: DefineEnumResult<{
3
3
  readonly Ascending: "Ascending";
4
4
  readonly Descending: "Descending";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/enum",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
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",
@@ -37,7 +37,8 @@
37
37
  "tolki"
38
38
  ],
39
39
  "dependencies": {
40
- "@tolki/types": "^1.4.0"
40
+ "@tolki/types": "^1.9.0",
41
+ "@tolki/utils": "^1.6.0"
41
42
  },
42
43
  "peerDependencies": {
43
44
  "vite": "^8.0.0||^7.0.0"