@avstantso/utils-enum-simple 1.1.3 → 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/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.2.0] - 2026-01-18
9
+
10
+ ### Changed
11
+
12
+ - Updated all dependencies
13
+
14
+ ## [1.1.4] - 2026-01-16
15
+
16
+ ### Changed
17
+
18
+ - Updated `@avstantso/core` dependency (fix `process is not defined` error in Vite build)
19
+
8
20
  ## [1.1.3] - 2026-01-16
9
21
 
10
22
  ### Changed
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@avstantso/utils-enum-simple",
3
3
  "license": "MIT",
4
4
  "author": "avstantso",
5
- "version": "1.1.3",
5
+ "version": "1.2.0",
6
6
  "description": "AVStantso framework utils: EnumSimple",
7
7
  "keywords": [
8
8
  "EnumSimple"
@@ -23,12 +23,12 @@
23
23
  "test": "NODE_ENV=test jest --coverage"
24
24
  },
25
25
  "dependencies": {
26
- "@avstantso/concepts": "1.0.3",
27
- "@avstantso/core": "1.0.3",
28
- "@avstantso/errors": "1.0.4",
29
- "@avstantso/js": "1.0.3",
30
- "@avstantso/std-ext": "1.0.2",
31
- "@avstantso/ts": "1.0.3"
26
+ "@avstantso/concepts": "1.1.0",
27
+ "@avstantso/core": "1.1.0",
28
+ "@avstantso/errors": "1.1.0",
29
+ "@avstantso/js": "1.1.0",
30
+ "@avstantso/std-ext": "1.1.0",
31
+ "@avstantso/ts": "1.1.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@avstantso/dev-basic": "1.0.0"
@@ -1,160 +0,0 @@
1
- declare namespace AVStantso {
2
- /**
3
- * @summary [`E`]num[`K`]ey[`M`]ap
4
- */
5
- type EKM<Values extends ReadonlyArray<string>, K2K extends TS.Array.ToKey2Key<Values> = TS.Array.ToKey2Key<Values>> = Pick<K2K, TS.Func.Restrict<keyof K2K>>;
6
- /**
7
- * @summary Array of const wrapper enum
8
- * @example
9
- * const [Enum, Def] = SimpleEnum.Factory(
10
- * 'ProgLang',
11
- * ['JS', 'TS', 'C', 'C++'] as const
12
- * );
13
- *
14
- * type Def = typeof Def;
15
- *
16
- * export const ProgLang = Enum;
17
- * export type ProgLang = Def['Key'];
18
- *
19
- * export namespace ProgLang {
20
- * export type Values = Def['Values'];
21
- * export type Map = Def['Map'];
22
- *
23
- * export type Record<T> = globalThis.Record<Def['Key'], T>;
24
- * }
25
- * @example
26
- * const [Enum, Def] = SimpleEnum.Factory.Raw(
27
- * 'FileFormat',
28
- * ['TXT', 'JSON', 'XLS'] as const
29
- * );
30
- *
31
- * type Def = typeof Def;
32
- *
33
- * function isBinary(ff: FileFormat) {
34
- * return 'XLS' === ff;
35
- * }
36
- * for (const ff of Enum)
37
- * Object.defineProperty(isBinary, ff, { get: isBinary.bind(null, ff) });
38
- *
39
- * const Caption = Enum.RecValid<string>().withFreeze({
40
- * TXT: 'Text file',
41
- * JSON: 'JavaScript Object Notation file',
42
- * XLS: 'Excel < 2007 file'
43
- * } as const);
44
- *
45
- * export const FileFormat = Object.freeze(
46
- * Object.assign(
47
- * Enum,
48
- * { isBinary, Caption }
49
- * ) as typeof Enum & {
50
- * isBinary: typeof isBinary & {
51
- * [K in Def['Key']]: boolean;
52
- * },
53
- * Caption: typeof Caption
54
- * }
55
- * );
56
- * export type FileFormat = Def['Key'];
57
- *
58
- * export namespace FileFormat {
59
- * export type Values = Def['Values'];
60
- * export type Map = Def['Map'];
61
- *
62
- * export type Record<T> = globalThis.Record<Def['Key'], T>;
63
- * }
64
- */
65
- export namespace SimpleEnum {
66
- /**
67
- * @summary Object is `SimpleEnum` check
68
- */
69
- type Is<Values extends ReadonlyArray<string>, EnumKeyMap extends EKM<Values> = EKM<Values>, EnumKey extends keyof EnumKeyMap = keyof EnumKeyMap> = {
70
- (candidate: unknown): candidate is EnumKey;
71
- } & {
72
- [K in EnumKey]: (candidate: unknown) => candidate is K;
73
- };
74
- /**
75
- * @summary Record validator
76
- */
77
- type RecValid<Values extends ReadonlyArray<string>, EnumKeyMap extends EKM<Values> = EKM<Values>, EnumKey extends keyof EnumKeyMap = keyof EnumKeyMap, T = unknown> = {
78
- /**
79
- * @summary Record validator
80
- */
81
- <R extends Record<EnumKey, T>>(rec: R): R;
82
- /**
83
- * @summary Record validator with `Object.freeze`
84
- */
85
- withFreeze<R extends Record<EnumKey, T>>(rec: R): Readonly<R>;
86
- };
87
- /**
88
- * @summary `[Enum, Def]`: enum controller & definition for use `typeof Def`
89
- */
90
- type Definition<TypeName extends string, Values extends ReadonlyArray<string>, EnumKeyMap extends EKM<Values> = EKM<Values>, EnumKey extends keyof EnumKeyMap = keyof EnumKeyMap> = [
91
- EnumKeyMap & {
92
- (value: string, defaultValue: EnumKey): EnumKey;
93
- (value: string): EnumKey;
94
- values: Values;
95
- Set: new <T extends EnumKey = EnumKey>(values?: readonly T[] | null) => Set<T>;
96
- is: Is<Values, EnumKeyMap, EnumKey>;
97
- map: Values['map'];
98
- indexOf: Values['indexOf'];
99
- [Symbol.iterator]: Values[typeof Symbol.iterator];
100
- RecValid<T>(): RecValid<Values, EnumKeyMap, EnumKey, T>;
101
- },
102
- {
103
- Name: TypeName;
104
- Values: Values;
105
- Key: EnumKey;
106
- Map: EnumKeyMap;
107
- Set: Set<EnumKey>;
108
- }?
109
- ];
110
- }
111
- export namespace Code {
112
- namespace SimpleEnum {
113
- /**
114
- * Create simple enum
115
- * @param typeName Enum name
116
- * @param values Enum values
117
- * @param unfreezed D'nt freeze result
118
- * @returns `[Enum, Def]`: enum controller & definition for use `typeof Def`
119
- */
120
- type Factory = {
121
- /**
122
- * Create simple enum
123
- * @param typeName Enum name
124
- * @param values Enum values
125
- * @param unfreezed D'nt freeze result
126
- * @returns `[Enum, Def]`: enum controller & definition for use `typeof Def`
127
- */
128
- <TypeName extends string, Values extends ReadonlyArray<string>>(typeName: TypeName, values: Values, unfreezed?: boolean): AVStantso.SimpleEnum.Definition<TypeName, Values>;
129
- /**
130
- * @summary Create simple enum. Keep result unfreezed
131
- * @param typeName Enum name
132
- * @param values Enum values
133
- * @returns `[Enum, Def]`: enum controller & definition for use `typeof Def`
134
- */
135
- Raw<TypeName extends string, Values extends ReadonlyArray<string>>(typeName: TypeName, values: Values): AVStantso.SimpleEnum.Definition<TypeName, Values>;
136
- };
137
- }
138
- /**
139
- * @summary SimpleEnum utilities
140
- */
141
- interface SimpleEnum {
142
- /**
143
- * Create simple enum
144
- * @param typeName Enum name
145
- * @param values Enum values
146
- * @param unfreezed D'nt freeze result
147
- * @returns `[Enum, Def]`: enum controller & definition for use `typeof Def`
148
- */
149
- Factory: SimpleEnum.Factory;
150
- }
151
- }
152
- export interface Code {
153
- /**
154
- * @summary SimpleEnum utilities
155
- */
156
- SimpleEnum: Code.SimpleEnum;
157
- }
158
- export const SimpleEnum: Code.SimpleEnum;
159
- export {};
160
- }
@@ -1 +0,0 @@
1
- import './_register';
package/dist/export.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import SimpleEnum = AVStantso.SimpleEnum;
2
- export { SimpleEnum };
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import '@avstantso/errors';
2
- import '@avstantso/js';
3
- import './_global';
4
- export * from './export';
package/dist/index.js DELETED
@@ -1,55 +0,0 @@
1
- 'use strict';
2
-
3
- require('@avstantso/errors');
4
- require('@avstantso/js');
5
-
6
- var AVStantso$1;
7
- (function (AVStantso) {
8
- AVStantso.SimpleEnum = avstantso._reg.SimpleEnum(({ Func, Generic, TS }) => {
9
- function SimpleEnumFactory(typeName, values, unfreezed) {
10
- Object.freeze(values);
11
- const map = TS.Array.ToKey2Key(values);
12
- function is(canditate) {
13
- return values.includes(canditate);
14
- }
15
- Object.assign(is, Object.fromEntries(values.filter(Func.isPropAllowed).map((k) => [
16
- k,
17
- (canditate) => canditate === k
18
- ])));
19
- function validateAndCast(value, ...params) {
20
- if (!value && params.length)
21
- return params[0];
22
- if (undefined === value || null === value)
23
- return value;
24
- if (!is(value)) {
25
- if (params.length)
26
- return params[0];
27
- throw new AVStantso_InvalidArgumentError(typeName, validateAndCast, { value }, `${typeName} must be one of [${values.join(',')}] but it's ${value}`);
28
- }
29
- return value;
30
- }
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- const result = Object.assign(validateAndCast, map, {
33
- values,
34
- Set,
35
- is,
36
- map: values.map.bind(values),
37
- indexOf: values.indexOf.bind(values),
38
- [Symbol.iterator]: values[Symbol.iterator].bind(values),
39
- RecValid: Generic.Validator
40
- });
41
- return [
42
- unfreezed ? result : Object.freeze(result)
43
- ];
44
- }
45
- SimpleEnumFactory.Raw = function SimpleEnumFactoryRaw(typeName, values) {
46
- return SimpleEnumFactory(typeName, values, true);
47
- };
48
- return { Factory: SimpleEnumFactory };
49
- });
50
- })(AVStantso$1 || (AVStantso$1 = {}));
51
-
52
- var SimpleEnum = AVStantso.SimpleEnum;
53
-
54
- exports.SimpleEnum = SimpleEnum;
55
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/_global/_register.ts","../src/export.ts"],"sourcesContent":["namespace AVStantso {\n /**\n * @summary [`E`]num[`K`]ey[`M`]ap\n */\n type EKM<\n Values extends ReadonlyArray<string>,\n K2K extends TS.Array.ToKey2Key<Values> = TS.Array.ToKey2Key<Values>\n > = Pick<K2K, TS.Func.Restrict<keyof K2K>>;\n\n /**\n * @summary Array of const wrapper enum\n * @EXAMPLE(@SimpleEnum)\n * @EXAMPLE(@SimpleEnum.Raw)\n */\n export namespace SimpleEnum {\n /**\n * @summary Object is `SimpleEnum` check\n */\n export type Is<\n Values extends ReadonlyArray<string>,\n EnumKeyMap extends EKM<Values> = EKM<Values>,\n EnumKey extends keyof EnumKeyMap = keyof EnumKeyMap\n > = {\n (candidate: unknown): candidate is EnumKey;\n } & {\n [K in EnumKey]: (candidate: unknown) => candidate is K;\n };\n\n /**\n * @summary Record validator\n */\n export type RecValid<\n Values extends ReadonlyArray<string>,\n EnumKeyMap extends EKM<Values> = EKM<Values>,\n EnumKey extends keyof EnumKeyMap = keyof EnumKeyMap,\n T = unknown\n > = {\n /**\n * @summary Record validator\n */\n <R extends Record<EnumKey, T>>(rec: R): R;\n\n /**\n * @summary Record validator with `Object.freeze`\n */\n withFreeze<R extends Record<EnumKey, T>>(rec: R): Readonly<R>;\n };\n\n /**\n * @summary `[Enum, Def]`: enum controller & definition for use `typeof Def`\n */\n export type Definition<\n TypeName extends string,\n Values extends ReadonlyArray<string>,\n EnumKeyMap extends EKM<Values> = EKM<Values>,\n EnumKey extends keyof EnumKeyMap = keyof EnumKeyMap\n > = [\n EnumKeyMap & {\n (value: string, defaultValue: EnumKey): EnumKey;\n (value: string): EnumKey;\n values: Values;\n Set: new <T extends EnumKey = EnumKey>(values?: readonly T[] | null) => Set<T>;\n is: Is<Values, EnumKeyMap, EnumKey>,\n map: Values['map'];\n indexOf: Values['indexOf'];\n [Symbol.iterator]: Values[typeof Symbol.iterator];\n RecValid<T>(): RecValid<Values, EnumKeyMap, EnumKey, T>;\n },\n {\n Name: TypeName;\n Values: Values;\n Key: EnumKey;\n Map: EnumKeyMap;\n Set: Set<EnumKey>;\n }? // 👈used for typeof only\n ];\n }\n\n export namespace Code {\n export namespace SimpleEnum {\n /**\n * Create simple enum\n * @param typeName Enum name\n * @param values Enum values\n * @param unfreezed D'nt freeze result\n * @returns `[Enum, Def]`: enum controller & definition for use `typeof Def`\n */\n export type Factory = {\n /**\n * Create simple enum\n * @param typeName Enum name\n * @param values Enum values\n * @param unfreezed D'nt freeze result\n * @returns `[Enum, Def]`: enum controller & definition for use `typeof Def`\n */\n <\n TypeName extends string,\n Values extends ReadonlyArray<string>\n >(typeName: TypeName, values: Values, unfreezed?: boolean): AVStantso.SimpleEnum.Definition<\n TypeName,\n Values\n >;\n\n /**\n * @summary Create simple enum. Keep result unfreezed\n * @param typeName Enum name\n * @param values Enum values\n * @returns `[Enum, Def]`: enum controller & definition for use `typeof Def`\n */\n Raw<\n TypeName extends string,\n Values extends ReadonlyArray<string>\n >(typeName: TypeName, values: Values): AVStantso.SimpleEnum.Definition<\n TypeName,\n Values\n >;\n };\n }\n\n /**\n * @summary SimpleEnum utilities\n */\n export interface SimpleEnum {\n /**\n * Create simple enum\n * @param typeName Enum name\n * @param values Enum values\n * @param unfreezed D'nt freeze result\n * @returns `[Enum, Def]`: enum controller & definition for use `typeof Def`\n */\n Factory: SimpleEnum.Factory;\n }\n }\n\n export interface Code {\n /**\n * @summary SimpleEnum utilities\n */\n SimpleEnum: Code.SimpleEnum;\n }\n\n export const SimpleEnum: Code.SimpleEnum = avstantso._reg.SimpleEnum(({ Func, Generic, TS }) => {\n function SimpleEnumFactory<\n TypeName extends string,\n Values extends ReadonlyArray<string>,\n EnumKeyMap extends EKM<Values> = EKM<Values>,\n EnumKey extends keyof EnumKeyMap = keyof EnumKeyMap\n >(typeName: TypeName, values: Values, unfreezed?: boolean): AVStantso.SimpleEnum.Definition<\n TypeName, Values, EnumKeyMap, EnumKey\n > {\n Object.freeze(values);\n\n const map = TS.Array.ToKey2Key(values);\n\n function is(canditate: unknown) {\n return values.includes(canditate as string);\n }\n\n Object.assign(\n is,\n Object.fromEntries(\n values.filter(Func.isPropAllowed).map((k) => [\n k,\n (canditate: unknown) => canditate === k\n ])\n )\n );\n\n function validateAndCast(value: string, ...params: [EnumKey?]) {\n if (!value && params.length) return params[0];\n\n if (undefined === value || null === value) return value as EnumKey;\n\n if (!is(value)) {\n if (params.length) return params[0];\n\n throw new AVStantso_InvalidArgumentError(\n typeName,\n validateAndCast,\n { value },\n `${typeName} must be one of [${values.join(',')}] but it's ${value}`\n );\n }\n\n return value as EnumKey;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: any = Object.assign(\n validateAndCast,\n map,\n {\n values,\n Set,\n is,\n map: values.map.bind(values),\n indexOf: values.indexOf.bind(values),\n [Symbol.iterator]: values[Symbol.iterator].bind(values),\n RecValid: Generic.Validator\n }\n );\n\n return [\n unfreezed ? result : Object.freeze(result)\n ];\n }\n\n SimpleEnumFactory.Raw = function SimpleEnumFactoryRaw<\n TypeName extends string,\n Values extends ReadonlyArray<string>\n >(typeName: TypeName, values: Values) {\n return SimpleEnumFactory(typeName, values, true);\n };\n\n return { Factory: SimpleEnumFactory };\n });\n}\n","import SimpleEnum = AVStantso.SimpleEnum;\n\nexport {\n SimpleEnum\n};\n"],"names":["AVStantso"],"mappings":";;;;;AAAA,IAAUA,WAAS;AAAnB,CAAA,UAAU,SAAS,EAAA;AA6IJ,IAAA,SAAA,CAAA,UAAU,GAAoB,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,KAAI;AAC7F,QAAA,SAAS,iBAAiB,CAKxB,QAAkB,EAAE,MAAc,EAAE,SAAmB,EAAA;AAGvD,YAAA,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;YAErB,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC;YAEtC,SAAS,EAAE,CAAC,SAAkB,EAAA;AAC5B,gBAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAmB,CAAC;YAC7C;YAEA,MAAM,CAAC,MAAM,CACX,EAAE,EACF,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK;gBAC3C,CAAC;AACD,gBAAA,CAAC,SAAkB,KAAK,SAAS,KAAK;aACvC,CAAC,CACH,CACF;AAED,YAAA,SAAS,eAAe,CAAC,KAAa,EAAE,GAAG,MAAkB,EAAA;AAC3D,gBAAA,IAAI,CAAC,KAAK,IAAI,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