extra-utils 5.5.2 → 5.6.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 +5 -0
- package/lib/enum/get-enum-key.d.ts +1 -0
- package/lib/enum/get-enum-key.js +10 -0
- package/lib/enum/get-enum-key.js.map +1 -0
- package/lib/enum/index.d.ts +1 -0
- package/lib/enum/index.js +1 -0
- package/lib/enum/index.js.map +1 -1
- package/package.json +1 -1
- package/src/enum/get-enum-key.ts +14 -0
- package/src/enum/index.ts +1 -0
package/README.md
CHANGED
|
@@ -209,6 +209,11 @@ function enumValues<T extends Record<string, string | number>>(
|
|
|
209
209
|
function enumEntries<T extends Record<string, string | number>>(
|
|
210
210
|
_enum: T
|
|
211
211
|
): Array<{ [Key in keyof T]: [Key, T[Key]] }[keyof T]>
|
|
212
|
+
|
|
213
|
+
function getEnumKey<T extends Record<string, string | number>>(
|
|
214
|
+
_enum: T
|
|
215
|
+
, enumValue: T[keyof T]
|
|
216
|
+
): keyof T
|
|
212
217
|
```
|
|
213
218
|
|
|
214
219
|
### Date
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEnumKey<T extends Record<string, string | number>>(_enum: T, enumValue: T[keyof T]): keyof T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { enumEntries } from './enum-entries.js';
|
|
2
|
+
export function getEnumKey(_enum, enumValue) {
|
|
3
|
+
for (const [key, value] of enumEntries(_enum)) {
|
|
4
|
+
if (value === enumValue) {
|
|
5
|
+
return key;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
throw new Error('There are no enumeration items matching the given value.');
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=get-enum-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-enum-key.js","sourceRoot":"","sources":["../../src/enum/get-enum-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,MAAM,UAAU,UAAU,CACxB,KAAQ,EACR,SAAqB;IAErB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE;QAC7C,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,GAAG,CAAA;SACX;KACF;IAED,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAA;AAC7E,CAAC"}
|
package/lib/enum/index.d.ts
CHANGED
package/lib/enum/index.js
CHANGED
package/lib/enum/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/enum/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/enum/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { enumEntries } from './enum-entries.js'
|
|
2
|
+
|
|
3
|
+
export function getEnumKey<T extends Record<string, string | number>>(
|
|
4
|
+
_enum: T
|
|
5
|
+
, enumValue: T[keyof T]
|
|
6
|
+
): keyof T {
|
|
7
|
+
for (const [key, value] of enumEntries(_enum)) {
|
|
8
|
+
if (value === enumValue) {
|
|
9
|
+
return key
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
throw new Error('There are no enumeration items matching the given value.')
|
|
14
|
+
}
|
package/src/enum/index.ts
CHANGED