@tstdl/base 0.92.28 → 0.92.29
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.
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Tagged } from 'type-fest';
|
|
2
|
+
import type { EnumerationObject } from '../types.js';
|
|
3
|
+
export type EnumType<T extends EnumerationObject> = T[keyof T];
|
|
4
|
+
export declare function defineEnum<const Name extends string, const T extends EnumerationObject>(name: Name, enumObject: T): {
|
|
5
|
+
[P in keyof T]: Tagged<T[P], Name>;
|
|
6
|
+
};
|
|
7
|
+
export declare function tryGetEnumName(enumeration: EnumerationObject): string | undefined;
|
|
8
|
+
export declare function getEnumName(enumeration: EnumerationObject): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isUndefined } from '../utils/type-guards.js';
|
|
2
|
+
const registry = new WeakMap();
|
|
3
|
+
export function defineEnum(name, enumObject) {
|
|
4
|
+
registry.set(enumObject, name);
|
|
5
|
+
return enumObject;
|
|
6
|
+
}
|
|
7
|
+
export function tryGetEnumName(enumeration) {
|
|
8
|
+
return registry.get(enumeration);
|
|
9
|
+
}
|
|
10
|
+
export function getEnumName(enumeration) {
|
|
11
|
+
const name = tryGetEnumName(enumeration);
|
|
12
|
+
if (isUndefined(name)) {
|
|
13
|
+
throw new Error('Unknown enumeration');
|
|
14
|
+
}
|
|
15
|
+
return name;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './enumeration.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './enumeration.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.92.
|
|
3
|
+
"version": "0.92.29",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"./distributed-loop": "./distributed-loop/index.js",
|
|
48
48
|
"./dom": "./dom/index.js",
|
|
49
49
|
"./document-management": "./document-management/index.js",
|
|
50
|
+
"./enumeration": "./enumeration/index.js",
|
|
50
51
|
"./enumerable": "./enumerable/index.js",
|
|
51
52
|
"./errors": "./errors/index.js",
|
|
52
53
|
"./file": "./file/index.js",
|