enum-plus
Version:
A drop-in replacement for native enum. Like native enum but much better!
41 lines (40 loc) • 1.87 kB
TypeScript
import type { EnumInit, EnumInitOptions, EnumKey, EnumValue, IEnum, StandardEnumInit, ValueTypeFromSingleInit } from './types';
/**
* **EN:** Generate an enum collection, the enum value supports `number` and `string` types, and the
* enum name supports localization solutions
*
* **CN:** 生成一个枚举集合,枚举值支持`number`和`string`类型,枚举名称支持本地化方案
*
* @example
* const Week = Enum({
* Sunday: { value: 0, label: 'Sunday' },
* Monday: { value: 1, label: 'Monday' },
* } as const);
*
* @param init the init object, see usage examples for the way to pass values | 初始化对象,传值方式参见使用示例
*
* @returns Enum collection | 枚举集合
*/
export declare function Enum<T extends EnumInit<K, V>, K extends EnumKey<T> = EnumKey<T>, V extends EnumValue = ValueTypeFromSingleInit<T[K], K>>(init: T, options?: EnumInitOptions<T, K, V>): IEnum<T, K, V> & EnumExtension<T, K, V>;
/**
* **EN:** Generate an enum based on an object array
*
* **CN:** 基于对象数组生成枚举
*
* @example
* const Week = Enum([
* { value: 0, label: 'Sunday', key: 'Sun' },
* { value: 1, label: 'Monday', key: 'Mon' },
* ]);
*
* @param init Init objects array | 初始化对象数组
* @param options Generate options | 生成选项
*
* @returns Enum collection | 枚举集合
*/
export declare function Enum<T extends Record<string, any>, K extends EnumKey<T> = EnumKey<T>, V extends EnumValue = ValueTypeFromSingleInit<T[K], K>>(init: T[], options?: EnumInitOptions<T, K, V>): IEnum<StandardEnumInit<string, V>, string, V> & EnumExtension<T, K, V>;
export declare namespace Enum {
export var localize: (content: "enum-plus.options.all" | (string & {}) | undefined) => any;
var _a: (obj: Record<string, unknown> | undefined) => void;
export { _a as extends };
}