UNPKG

enum-plus

Version:

A drop-in replacement for native enum. Like native enum but much better!

63 lines (62 loc) 3.42 kB
import { EnumItemsArray } from './enum-values'; import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, FindEnumKeyByValue, IEnumItems, MenuItemOption, ObjectFirstOptionConfig, ToSelectConfig, ValueTypeFromSingleInit } from './types'; import { ENUM_COLLECTION } from './utils'; /** * **EN:** Enum collection extension base class, used to extend the Enums * * **CN:** 枚举集合扩展基类,用于扩展枚举 */ export declare class EnumExtensionClass<T extends EnumInit<K, V>, K extends EnumKey<T> = EnumKey<T>, V extends EnumValue = ValueTypeFromSingleInit<T[K], K>> implements EnumExtension<T, K, V> { } /** * **EN:** Enum collection * * **CN:** 枚举项集合 */ export declare class EnumCollectionClass<T extends EnumInit<K, V>, K extends EnumKey<T> = EnumKey<T>, V extends EnumValue = ValueTypeFromSingleInit<T[K], K>> extends EnumExtensionClass<T, K, V> implements IEnumItems<T, K, V> { private _options; readonly items: EnumItemsArray<T, K, V>; readonly keys: K[]; /** * **EN:** A boolean value indicates that this is an enum collection instance. * * **CN:** 布尔值,表示这是一个枚举集合实例 */ readonly [ENUM_COLLECTION] = true; /** * The enum collection name, supports localization. Note that it usually returns a string, but if * a custom `localize` function is set, the return value may vary depending on the implementation * of the method. * * **CN:** 枚举集合显示名称,支持本地化。注意,通常情况下返回的是字符串,但如果设置了自定义的 `localize` 函数,则返回值可能有所不同,取决于方法的实现 * * @returns {string | undefined} The localized name of the enum collection, or undefined if not * set. */ get name(): string | undefined; constructor(init?: T, options?: EnumItemOptions); key(value?: string | V): K | undefined; label(keyOrValue?: string | V): string | undefined; has(keyOrValue?: string | V): boolean; toSelect(): EnumItemOptionData<K, V>[]; toSelect(config: ToSelectConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[]; toSelect<FK = never, FV = never>(config: ToSelectConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[]; /** @deprecated use `toSelect` instead */ options(): EnumItemOptionData<K, V>[]; options(config: object & BooleanFirstOptionConfig<V>): EnumItemOptionData<'' | K, '' | V>[]; options<FK, FV>(config: object & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[]; toMenu(): MenuItemOption<V>[]; /** @deprecated use `toMenu` instead */ menus(): MenuItemOption<V>[]; toFilter(): ColumnFilterItem<V>[]; /** @deprecated use `toFilter` instead */ filters(): ColumnFilterItem<V>[]; toValueMap(): import("./types").ValueMap<V>; /** @deprecated use `toValueMap` instead */ valuesEnum(): import("./types").ValueMap<V>; raw(): T; raw<IK extends V | K | Exclude<EnumValue, string> | (string & {})>(keyOrValue: IK): IK extends K ? T[IK] : IK extends V ? T[FindEnumKeyByValue<T, IK>] : T[K] | undefined; get valueType(): V; get keyType(): K; get rawType(): T[K]; }