@matterbridge/utils 3.7.1-dev-20260324-7b86640 → 3.7.1-dev-20260324-9c29691

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,7 @@
1
+ type EnumValue = string | number;
2
+ export type EnumLike = Record<string, EnumValue>;
3
+ export interface EnumDescriptionOptions {
4
+ fallback?: string;
5
+ }
6
+ export declare function getEnumDescription<T extends EnumLike>(enumType: T, value: T[keyof T] | null | undefined, options?: EnumDescriptionOptions): string;
7
+ export {};
@@ -0,0 +1,15 @@
1
+ export function getEnumDescription(enumType, value, options = {}) {
2
+ const fallback = options.fallback ?? 'Invalid';
3
+ if (value === undefined || value === null)
4
+ return fallback;
5
+ const enumKey = getEnumKey(enumType, value);
6
+ return enumKey ?? fallback;
7
+ }
8
+ function getEnumKey(enumType, value) {
9
+ return Object.keys(enumType)
10
+ .filter((key) => !isNumericEnumReverseKey(key))
11
+ .find((key) => enumType[key] === value);
12
+ }
13
+ function isNumericEnumReverseKey(key) {
14
+ return /^-?\d+$/.test(key);
15
+ }
package/dist/export.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './copyDirectory.js';
4
4
  export * from './createDirectory.js';
5
5
  export * from './deepCopy.js';
6
6
  export * from './deepEqual.js';
7
+ export * from './enumDescription.js';
7
8
  export * from './error.js';
8
9
  export * from './format.js';
9
10
  export * from './githubVersion.js';
package/dist/export.js CHANGED
@@ -4,6 +4,7 @@ export * from './copyDirectory.js';
4
4
  export * from './createDirectory.js';
5
5
  export * from './deepCopy.js';
6
6
  export * from './deepEqual.js';
7
+ export * from './enumDescription.js';
7
8
  export * from './error.js';
8
9
  export * from './format.js';
9
10
  export * from './githubVersion.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matterbridge/utils",
3
- "version": "3.7.1-dev-20260324-7b86640",
3
+ "version": "3.7.1-dev-20260324-9c29691",
4
4
  "description": "Matterbridge utils library",
5
5
  "author": "https://github.com/Luligu",
6
6
  "homepage": "https://matterbridge.io/",
@@ -133,7 +133,7 @@
133
133
  "CHANGELOG.md"
134
134
  ],
135
135
  "dependencies": {
136
- "@matterbridge/jest-utils": "3.7.1-dev-20260324-7b86640",
136
+ "@matterbridge/jest-utils": "3.7.1-dev-20260324-9c29691",
137
137
  "node-ansi-logger": "3.2.0"
138
138
  }
139
139
  }