New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

enum-plus

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enum-plus - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0-beta.1

es/归档 2.zip

23

CHANGELOG.md

@@ -5,2 +5,11 @@ <!-- markdownlint-disable MD009 MD024 -->

## 2.2.0
2025-2-9
### Features
- 🔥 Support initializing Enum with native enums
- 🔥 Adds `items` array, deprecated the _`values`_ array. Reduces package size.
## 2.1.1

@@ -18,12 +27,12 @@

> **Note:** this version has a typing issue, please use `v2.1.1`
### Features
- 🔥 Adds `toSelect` method, deprecated ~~`options`~~ method
- 🔥 Adds `toMenu` method, deprecated ~~`menus`~~ method
- 🔥 Adds `toFilter` method, deprecated ~~`filters`~~ method
- 🔥 Adds `toValueMap` method, ~~`valuesEnum`~~ method
- 🔥 Support global extending, you can add custom methods to Enums
- 🔥 Adds `toSelect` method, deprecated the _`options`_ method
- 🔥 Adds `toMenu` method, deprecated the _`menus`_ method
- 🔥 Adds `toFilter` method, deprecated the _`filters`_ method
- 🔥 Adds `toValueMap` method, the _`valuesEnum`_ method
- 🔥 Support global extension, custom methods can be added to Enums
> **Note:** this version has typing problem, please use `v2.1.1`
## 2.0.3

@@ -30,0 +39,0 @@

import { EnumValuesArray } from './enum-values';
import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, IEnumValues, MenuItemOption, ObjectFirstOptionConfig, OptionsConfig, ValueTypeFromSingleInit } from './types';
import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, IEnumValues, MenuItemOption, ObjectFirstOptionConfig, ToSelectConfig, ValueTypeFromSingleInit } from './types';
/**

@@ -16,3 +16,3 @@ * **EN:** Enum collection extension base class, used to extend the Enums

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 IEnumValues<T, K, V> {
readonly values: EnumValuesArray<T, K, V>;
readonly items: EnumValuesArray<T, K, V>;
readonly keys: K[];

@@ -24,4 +24,4 @@ constructor(init?: T, options?: EnumItemOptions);

toSelect(): EnumItemOptionData<K, V>[];
toSelect(config: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
toSelect<FK = never, FV = never>(config: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
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 */

@@ -28,0 +28,0 @@ options(): EnumItemOptionData<K, V>[];

import { EnumItemClass } from './enum-item';
import { EnumValuesArray } from './enum-values';
import { KEYS, VALUES } from './index';
import { ITEMS, KEYS, VALUES } from './index';
/**

@@ -20,3 +20,4 @@ * **EN:** Enum collection extension base class, used to extend the Enums

super();
const keys = Object.keys(init);
// exclude number keys with a "reverse mapping" value, it means those "reverse mapping" keys of number enums
const keys = Object.keys(init).filter((k) => { var _a; return !(/^-?\d+$/.test(k) && k === `${(_a = init[init[k]]) !== null && _a !== void 0 ? _a : ''}`); });
const parsed = keys.map((key) => parseEnumItem(init[key], key, { typeInit: init, keys }));

@@ -28,11 +29,14 @@ keys.forEach((key, index) => {

});
Object.freeze(keys);
// @ts-expect-error: because use KEYS to avoid naming conflicts in case of 'keys' field name is taken
this[Object.keys(init).some((k) => k === 'keys') ? KEYS : 'keys'] = keys;
// Build enum item data
const values = new EnumValuesArray(init, options, ...keys.map((key, index) => {
const items = new EnumValuesArray(init, options, ...keys.map((key, index) => {
const { value, label } = parsed[index];
return new EnumItemClass(key, value, label, init[key], options).readonly();
}));
// @ts-expect-error: because use ITEMS to avoid naming conflicts in case of 'items' field name is taken
this[Object.keys(init).some((k) => k === 'items') ? ITEMS : 'items'] = items;
// @ts-expect-error: because use VALUES to avoid naming conflicts in case of 'values' field name is taken
this[Object.keys(init).some((k) => k === 'values') ? VALUES : 'values'] = values;
this[Object.keys(init).some((k) => k === 'values') ? VALUES : 'values'] = items;
// Override some system methods

@@ -45,3 +49,3 @@ // @ts-expect-error: because override Object.toString method for better type display

// intentionally use == to support both number and string format value
return this.values.some(
return this.items.some(
// eslint-disable-next-line eqeqeq

@@ -51,57 +55,57 @@ (i) => instance == i.value || instance === i.key);

Object.freeze(this);
Object.freeze(this.values);
Object.freeze(this.items);
Object.freeze(this.keys);
}
key(value) {
return this.values.key(value);
return this.items.key(value);
}
label(keyOrValue) {
return this.values.label(keyOrValue);
return this.items.label(keyOrValue);
}
has(keyOrValue) {
return this.values.has(keyOrValue);
return this.items.has(keyOrValue);
}
toSelect(config) {
return this.values.toSelect(config);
return this.items.toSelect(config);
}
options(config) {
return this.values.options(config);
return this.items.options(config);
}
toMenu() {
return this.values.toMenu();
return this.items.toMenu();
}
/** @deprecated use `toMenu` instead */
menus() {
return this.values.menus();
return this.items.menus();
}
toFilter() {
return this.values.toFilter();
return this.items.toFilter();
}
/** @deprecated use `toFilter` instead */
filters() {
return this.values.filters();
return this.items.filters();
}
toValueMap() {
return this.values.toValueMap();
return this.items.toValueMap();
}
/** @deprecated use `toValueMap` instead */
valuesEnum() {
return this.values.valuesEnum();
return this.items.valuesEnum();
}
raw(value) {
if (value !== undefined) {
return this.values.raw(value);
return this.items.raw(value);
}
else {
return this.values.raw();
return this.items.raw();
}
}
get valueType() {
return this.values.valueType;
return this.items.valueType;
}
get keyType() {
return this.values.keyType;
return this.items.keyType;
}
get rawType() {
return this.values.rawType;
return this.items.rawType;
}

@@ -153,45 +157,7 @@ }

else {
return inferFromNull(key, options);
}
return { value, label };
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function inferFromNull(key, options) {
const { typeInit, keys } = options;
let value;
const label = key;
// If the value is empty, first check the number incrementing enumeration, otherwise use the key as the value
const index = keys.indexOf(key);
const prev = typeInit[keys[index - 1]];
// Only pure number and empty enumeration will be incremented
if (keys.some((k) => typeInit[k] != null && typeof typeInit[k] !== 'number')) {
value = key;
label = key;
}
else if (index === 0) {
value = 0;
}
else if (typeof prev === 'number') {
value = (prev + 1);
}
else {
// only nulls
let seed = 0;
let count = 0;
// find seed
for (let i = index - 1; i >= 0; i--) {
const val = typeInit[keys[i]];
count++;
if (typeof val === 'number') {
seed = val;
break;
}
else {
// only nulls
continue;
}
}
value = (seed + count);
}
return { value, label };
}
//# sourceMappingURL=enum-collection.js.map
import type { EnumItemClass } from './enum-item';
import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, IEnumValues, MenuItemOption, ObjectFirstOptionConfig, OptionsConfig, ValueTypeFromSingleInit } from './types';
import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, IEnumValues, MenuItemOption, ObjectFirstOptionConfig, ToSelectConfig, ValueTypeFromSingleInit } from './types';
/**

@@ -31,10 +31,10 @@ * Enum items array, mostly are simple wrappers for EnumCollectionClass

toSelect(): EnumItemOptionData<K, V>[];
toSelect(config?: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
toSelect<FK = never, FV = never>(config?: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
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>[];
/** @deprecated Use `toSelect` instead */
options(config?: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
options(config?: ToSelectConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
/** @deprecated Use `toSelect` instead */
options<FK = never, FV = never>(config?: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
options<FK = never, FV = never>(config?: ToSelectConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
toValueMap(): Record<V, {

@@ -41,0 +41,0 @@ text: string;

@@ -11,2 +11,9 @@ import type { EnumInit, EnumInitOptions, EnumItemOptions, EnumKey, EnumValue, IEnum, StandardEnumInit, ValueTypeFromSingleInit } from './types';

/**
* **EN:** Alias of `items`. If the enum contains a field with the same name as `items`, you can
* access it by this Symbol as the field name
*
* **CN:** 枚举`items`集合的别名。如果枚举中包含了`items`的同名字段,可以通过此Symbol作为字段名来访问
*/
export declare const ITEMS: unique symbol;
/**
* **EN:** Alias of `keys`. If the enum contains a field with the same name as `keys`, you can

@@ -13,0 +20,0 @@ * access it by this Symbol as the field name

@@ -10,2 +10,9 @@ import { EnumCollectionClass, EnumExtensionClass } from './enum-collection';

/**
* **EN:** Alias of `items`. If the enum contains a field with the same name as `items`, you can
* access it by this Symbol as the field name
*
* **CN:** 枚举`items`集合的别名。如果枚举中包含了`items`的同名字段,可以通过此Symbol作为字段名来访问
*/
export const ITEMS = Symbol('[items]');
/**
* **EN:** Alias of `keys`. If the enum contains a field with the same name as `keys`, you can

@@ -12,0 +19,0 @@ * access it by this Symbol as the field name

import type { EnumItemClass } from './enum-item';
import type { KEYS, VALUES } from './index';
import type { ITEMS, KEYS, VALUES } from './index';
/**

@@ -57,5 +57,5 @@ * **EN:** Enum initialization options

} & (T extends {
values: unknown;
items: any;
} ? {
[VALUES]: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;
[ITEMS]: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;
} : {

@@ -73,2 +73,9 @@ /**

*/
items: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;
}) & (T extends {
values: any;
} ? {
[VALUES]: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;
} : {
/** @deprecated Use `items` instead */
values: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;

@@ -159,3 +166,3 @@ }) & (T extends {

*/
toSelect(config: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
toSelect(config: ToSelectConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
/**

@@ -177,9 +184,9 @@ * **EN:** Generate an array of objects that can be bound to those `options like` of components

*/
toSelect<FK, FV>(config: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
toSelect<FK, FV>(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>[];
/** @deprecated Use `toSelect` instead */
options(config: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
options(config: ToSelectConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
/** @deprecated Use `toSelect` instead */
options<FK, FV>(config: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
options<FK, FV>(config: ToSelectConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
/**

@@ -308,5 +315,6 @@ * **EN:** Generate an object array that can be bound to the data source of components such as

}
export type EnumInit<K extends keyof any = string, V extends EnumValue = EnumValue> = NumberEnumInit<K> | StringEnumInit<K> | StandardEnumInit<K, V> | ValueOnlyEnumInit<K, V> | LabelOnlyEnumInit<K> | CompactEnumInit<K> | AutoIncrementedEnumInit<K>;
export type EnumInit<K extends keyof any = string, V extends EnumValue = EnumValue> = NumberEnumInit<K> | StringEnumInit<K> | StringNumberEnumInit<K> | StandardEnumInit<K, V> | ValueOnlyEnumInit<K, V> | LabelOnlyEnumInit<K> | CompactEnumInit<K> | AutoIncrementedEnumInit<K>;
export type NumberEnumInit<K extends keyof any> = Record<K, number>;
export type StringEnumInit<K extends keyof any> = Record<K, string>;
export type StringNumberEnumInit<K extends keyof any> = Record<K, string | number>;
export type StandardEnumInit<K extends keyof any, V extends EnumValue> = Record<K, StandardEnumItemInit<V>>;

@@ -359,3 +367,3 @@ export type ValueOnlyEnumInit<K extends keyof any, V extends EnumValue> = Record<K, ValueOnlyEnumItemInit<V>>;

/** More options for the options method */
export type OptionsConfig = object;
export type ToSelectConfig = object;
export interface BooleanFirstOptionConfig<V> {

@@ -362,0 +370,0 @@ /**

import { EnumValuesArray } from './enum-values';
import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, IEnumValues, MenuItemOption, ObjectFirstOptionConfig, OptionsConfig, ValueTypeFromSingleInit } from './types';
import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, IEnumValues, MenuItemOption, ObjectFirstOptionConfig, ToSelectConfig, ValueTypeFromSingleInit } from './types';
/**

@@ -16,3 +16,3 @@ * **EN:** Enum collection extension base class, used to extend the Enums

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 IEnumValues<T, K, V> {
readonly values: EnumValuesArray<T, K, V>;
readonly items: EnumValuesArray<T, K, V>;
readonly keys: K[];

@@ -24,4 +24,4 @@ constructor(init?: T, options?: EnumItemOptions);

toSelect(): EnumItemOptionData<K, V>[];
toSelect(config: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
toSelect<FK = never, FV = never>(config: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
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 */

@@ -28,0 +28,0 @@ options(): EnumItemOptionData<K, V>[];

@@ -24,3 +24,4 @@ "use strict";

super();
const keys = Object.keys(init);
// exclude number keys with a "reverse mapping" value, it means those "reverse mapping" keys of number enums
const keys = Object.keys(init).filter((k) => { var _a; return !(/^-?\d+$/.test(k) && k === `${(_a = init[init[k]]) !== null && _a !== void 0 ? _a : ''}`); });
const parsed = keys.map((key) => parseEnumItem(init[key], key, { typeInit: init, keys }));

@@ -32,11 +33,14 @@ keys.forEach((key, index) => {

});
Object.freeze(keys);
// @ts-expect-error: because use KEYS to avoid naming conflicts in case of 'keys' field name is taken
this[Object.keys(init).some((k) => k === 'keys') ? index_1.KEYS : 'keys'] = keys;
// Build enum item data
const values = new enum_values_1.EnumValuesArray(init, options, ...keys.map((key, index) => {
const items = new enum_values_1.EnumValuesArray(init, options, ...keys.map((key, index) => {
const { value, label } = parsed[index];
return new enum_item_1.EnumItemClass(key, value, label, init[key], options).readonly();
}));
// @ts-expect-error: because use ITEMS to avoid naming conflicts in case of 'items' field name is taken
this[Object.keys(init).some((k) => k === 'items') ? index_1.ITEMS : 'items'] = items;
// @ts-expect-error: because use VALUES to avoid naming conflicts in case of 'values' field name is taken
this[Object.keys(init).some((k) => k === 'values') ? index_1.VALUES : 'values'] = values;
this[Object.keys(init).some((k) => k === 'values') ? index_1.VALUES : 'values'] = items;
// Override some system methods

@@ -49,3 +53,3 @@ // @ts-expect-error: because override Object.toString method for better type display

// intentionally use == to support both number and string format value
return this.values.some(
return this.items.some(
// eslint-disable-next-line eqeqeq

@@ -55,57 +59,57 @@ (i) => instance == i.value || instance === i.key);

Object.freeze(this);
Object.freeze(this.values);
Object.freeze(this.items);
Object.freeze(this.keys);
}
key(value) {
return this.values.key(value);
return this.items.key(value);
}
label(keyOrValue) {
return this.values.label(keyOrValue);
return this.items.label(keyOrValue);
}
has(keyOrValue) {
return this.values.has(keyOrValue);
return this.items.has(keyOrValue);
}
toSelect(config) {
return this.values.toSelect(config);
return this.items.toSelect(config);
}
options(config) {
return this.values.options(config);
return this.items.options(config);
}
toMenu() {
return this.values.toMenu();
return this.items.toMenu();
}
/** @deprecated use `toMenu` instead */
menus() {
return this.values.menus();
return this.items.menus();
}
toFilter() {
return this.values.toFilter();
return this.items.toFilter();
}
/** @deprecated use `toFilter` instead */
filters() {
return this.values.filters();
return this.items.filters();
}
toValueMap() {
return this.values.toValueMap();
return this.items.toValueMap();
}
/** @deprecated use `toValueMap` instead */
valuesEnum() {
return this.values.valuesEnum();
return this.items.valuesEnum();
}
raw(value) {
if (value !== undefined) {
return this.values.raw(value);
return this.items.raw(value);
}
else {
return this.values.raw();
return this.items.raw();
}
}
get valueType() {
return this.values.valueType;
return this.items.valueType;
}
get keyType() {
return this.values.keyType;
return this.items.keyType;
}
get rawType() {
return this.values.rawType;
return this.items.rawType;
}

@@ -158,45 +162,7 @@ }

else {
return inferFromNull(key, options);
}
return { value, label };
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function inferFromNull(key, options) {
const { typeInit, keys } = options;
let value;
const label = key;
// If the value is empty, first check the number incrementing enumeration, otherwise use the key as the value
const index = keys.indexOf(key);
const prev = typeInit[keys[index - 1]];
// Only pure number and empty enumeration will be incremented
if (keys.some((k) => typeInit[k] != null && typeof typeInit[k] !== 'number')) {
value = key;
label = key;
}
else if (index === 0) {
value = 0;
}
else if (typeof prev === 'number') {
value = (prev + 1);
}
else {
// only nulls
let seed = 0;
let count = 0;
// find seed
for (let i = index - 1; i >= 0; i--) {
const val = typeInit[keys[i]];
count++;
if (typeof val === 'number') {
seed = val;
break;
}
else {
// only nulls
continue;
}
}
value = (seed + count);
}
return { value, label };
}
//# sourceMappingURL=enum-collection.js.map
import type { EnumItemClass } from './enum-item';
import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, IEnumValues, MenuItemOption, ObjectFirstOptionConfig, OptionsConfig, ValueTypeFromSingleInit } from './types';
import type { BooleanFirstOptionConfig, ColumnFilterItem, EnumInit, EnumItemOptionData, EnumItemOptions, EnumKey, EnumValue, IEnumValues, MenuItemOption, ObjectFirstOptionConfig, ToSelectConfig, ValueTypeFromSingleInit } from './types';
/**

@@ -31,10 +31,10 @@ * Enum items array, mostly are simple wrappers for EnumCollectionClass

toSelect(): EnumItemOptionData<K, V>[];
toSelect(config?: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
toSelect<FK = never, FV = never>(config?: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
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>[];
/** @deprecated Use `toSelect` instead */
options(config?: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
options(config?: ToSelectConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
/** @deprecated Use `toSelect` instead */
options<FK = never, FV = never>(config?: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
options<FK = never, FV = never>(config?: ToSelectConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
toValueMap(): Record<V, {

@@ -41,0 +41,0 @@ text: string;

@@ -11,2 +11,9 @@ import type { EnumInit, EnumInitOptions, EnumItemOptions, EnumKey, EnumValue, IEnum, StandardEnumInit, ValueTypeFromSingleInit } from './types';

/**
* **EN:** Alias of `items`. If the enum contains a field with the same name as `items`, you can
* access it by this Symbol as the field name
*
* **CN:** 枚举`items`集合的别名。如果枚举中包含了`items`的同名字段,可以通过此Symbol作为字段名来访问
*/
export declare const ITEMS: unique symbol;
/**
* **EN:** Alias of `keys`. If the enum contains a field with the same name as `keys`, you can

@@ -13,0 +20,0 @@ * access it by this Symbol as the field name

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultLocalize = exports.KEYS = exports.VALUES = void 0;
exports.defaultLocalize = exports.KEYS = exports.ITEMS = exports.VALUES = void 0;
exports.Enum = Enum;

@@ -14,2 +14,9 @@ const enum_collection_1 = require("./enum-collection");

/**
* **EN:** Alias of `items`. If the enum contains a field with the same name as `items`, you can
* access it by this Symbol as the field name
*
* **CN:** 枚举`items`集合的别名。如果枚举中包含了`items`的同名字段,可以通过此Symbol作为字段名来访问
*/
exports.ITEMS = Symbol('[items]');
/**
* **EN:** Alias of `keys`. If the enum contains a field with the same name as `keys`, you can

@@ -16,0 +23,0 @@ * access it by this Symbol as the field name

import type { EnumItemClass } from './enum-item';
import type { KEYS, VALUES } from './index';
import type { ITEMS, KEYS, VALUES } from './index';
/**

@@ -57,5 +57,5 @@ * **EN:** Enum initialization options

} & (T extends {
values: unknown;
items: any;
} ? {
[VALUES]: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;
[ITEMS]: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;
} : {

@@ -73,2 +73,9 @@ /**

*/
items: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;
}) & (T extends {
values: any;
} ? {
[VALUES]: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;
} : {
/** @deprecated Use `items` instead */
values: EnumItemClass<T[K], K, V>[] & IEnumValues<T, K, V>;

@@ -159,3 +166,3 @@ }) & (T extends {

*/
toSelect(config: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
toSelect(config: ToSelectConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
/**

@@ -177,9 +184,9 @@ * **EN:** Generate an array of objects that can be bound to those `options like` of components

*/
toSelect<FK, FV>(config: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
toSelect<FK, FV>(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>[];
/** @deprecated Use `toSelect` instead */
options(config: OptionsConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
options(config: ToSelectConfig & BooleanFirstOptionConfig<V>): EnumItemOptionData<K | '', V | ''>[];
/** @deprecated Use `toSelect` instead */
options<FK, FV>(config: OptionsConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
options<FK, FV>(config: ToSelectConfig & ObjectFirstOptionConfig<FK, FV>): EnumItemOptionData<K | (FK extends never ? FV : FK), V | (FV extends never ? V : FV)>[];
/**

@@ -308,5 +315,6 @@ * **EN:** Generate an object array that can be bound to the data source of components such as

}
export type EnumInit<K extends keyof any = string, V extends EnumValue = EnumValue> = NumberEnumInit<K> | StringEnumInit<K> | StandardEnumInit<K, V> | ValueOnlyEnumInit<K, V> | LabelOnlyEnumInit<K> | CompactEnumInit<K> | AutoIncrementedEnumInit<K>;
export type EnumInit<K extends keyof any = string, V extends EnumValue = EnumValue> = NumberEnumInit<K> | StringEnumInit<K> | StringNumberEnumInit<K> | StandardEnumInit<K, V> | ValueOnlyEnumInit<K, V> | LabelOnlyEnumInit<K> | CompactEnumInit<K> | AutoIncrementedEnumInit<K>;
export type NumberEnumInit<K extends keyof any> = Record<K, number>;
export type StringEnumInit<K extends keyof any> = Record<K, string>;
export type StringNumberEnumInit<K extends keyof any> = Record<K, string | number>;
export type StandardEnumInit<K extends keyof any, V extends EnumValue> = Record<K, StandardEnumItemInit<V>>;

@@ -359,3 +367,3 @@ export type ValueOnlyEnumInit<K extends keyof any, V extends EnumValue> = Record<K, ValueOnlyEnumItemInit<V>>;

/** More options for the options method */
export type OptionsConfig = object;
export type ToSelectConfig = object;
export interface BooleanFirstOptionConfig<V> {

@@ -362,0 +370,0 @@ /**

{
"name": "enum-plus",
"version": "2.1.1",
"version": "2.2.0-beta.1",
"description": "A drop-in replacement library for enum, tiny and powerful, like native enum but much more than that",
"keywords": [
"enum",
"typescript-library"
"enumeration",
"typescript",
"localization",
"ssr",
"tool"
],

@@ -9,0 +13,0 @@ "homepage": "https://github.com/shijistar/enum-plus",

@@ -9,3 +9,3 @@ <!-- markdownlint-disable MD009 -->

[![npm version](https://img.shields.io/npm/v/enum-plus.svg)](https://www.npmjs.com/package/enum-plus)
[![npm version](https://img.shields.io/npm/v/enum-plus.svg?color=red)](https://www.npmjs.com/package/enum-plus)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/enum-plus)](https://bundlephobia.com/result?p=enum-plus)

@@ -121,4 +121,2 @@ [![npm downloads](https://img.shields.io/npm/dm/enum-plus.svg)](https://www.npmjs.com/package/enum-plus)

````js
Sometimes we need to create an enum dynamically using data returned by an api, in this case, we can use an array to initialize the enum

@@ -138,8 +136,29 @@

});
Week.values; // Output is:
Week.items; // Output is:
// [ { value: 1, label: 'Dog', key: 'dog' },
// { value: 2, label: 'Cat', key: 'cat' },
// { value: 3, label: 'Rabbit', key: 'rabbit' } ]
````
```
#### Example 6: initialized from native enum (extend native enum with additional methods)
```ts
import { Enum } from 'enum-plus';
enum init {
Sunday = 0,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
}
const Week = Enum(init);
Week.Sunday; // 0
Week.Monday; // 1
Week.Saturday; // 6
Week.label('Sunday'); // Sunday
```
## API

@@ -160,3 +179,3 @@

### values
### items

@@ -221,3 +240,3 @@ `{value, label, key, raw}[]`

`toSelect` is similar to `values`, both return an array containing all enum items. The difference is that the elements returned by `toSelect` only contain the `label` and `value` fields. At the same time, the `toSelect` method supports inserting a default element at the beginning of the array, which is generally used for the default option of components such as dropdowns, representing all, none, or unlimited, etc., of course, you can also customize this default option
`toSelect` is similar to `items`, both return an array containing all enum items. The difference is that the elements returned by `toSelect` only contain the `label` and `value` fields. At the same time, the `toSelect` method supports inserting a default element at the beginning of the array, which is generally used for the default option of components such as dropdowns, representing all, none, or unlimited, etc., of course, you can also customize this default option

@@ -390,3 +409,3 @@ ---

```js
Week.values; // Output is:
Week.items; // Output is:
// [

@@ -403,3 +422,3 @@ // { value: 0, label: 'Sunday', key: 'Sunday', raw: { value: 0, label: 'Sunday' } },

```js
Week.values[0].value; // 0
Week.items[0].value; // 0
```

@@ -413,3 +432,3 @@

Week.has(1); // true
Week.values.some(item => item.value === 1); // true
Week.items.some(item => item.value === 1); // true
1 instance of Week; // true

@@ -433,11 +452,11 @@ ```

```js
Week.values.length; // 2
Week.values.map((item) => item.value); // [0, 1], ✅ Traversable
Week.values.forEach((item) => {}); // ✅ Traversable
for (let item of Week.values) {
Week.items.length; // 2
Week.items.map((item) => item.value); // [0, 1], ✅ Traversable
Week.items.forEach((item) => {}); // ✅ Traversable
for (let item of Week.items) {
// ✅ Traversable
}
Week.values.push({ value: 2, label: 'Tuesday' }); // ❌ Not modifiable
Week.values.splice(0, 1); // ❌ Not modifiable
Week.values[0].label = 'foo'; // ❌ Not modifiable
Week.items.push({ value: 2, label: 'Tuesday' }); // ❌ Not modifiable
Week.items.splice(0, 1); // ❌ Not modifiable
Week.items[0].label = 'foo'; // ❌ Not modifiable
```

@@ -483,3 +502,3 @@

- `values` can be consumed as the data source (here uses Select as examples)
- `items` can be consumed as the data source (here uses Select as examples)

@@ -492,3 +511,3 @@ [Ant Design](https://ant.design/components/select) | [Arco Design](https://arco.design/react/en-US/components/select)

<Select options={Week.values} />;
<Select options={Week.items} />;
```

@@ -502,3 +521,3 @@

<Select>
{Week.values.map((item) => (
{Week.items.map((item) => (
<MenuItem key={item.value} value={item.value}>

@@ -516,3 +535,3 @@ {item.label}

<DropDownList data={Week.values} textField="label" dataItemKey="value" />;
<DropDownList data={Week.items} textField="label" dataItemKey="value" />;
```

@@ -524,3 +543,3 @@

<el-select>
<el-option v-for="item in Week.values" v-bind="item" />
<el-option v-for="item in Week.items" v-bind="item" />
</el-select>

@@ -532,3 +551,3 @@ ```

```tsx
<a-select :options="Week.values" />
<a-select :options="Week.items" />
```

@@ -539,3 +558,3 @@

```tsx
<v-select :items="Week.values" item-title="label" />
<v-select :items="Week.items" item-title="label" />
```

@@ -549,3 +568,3 @@

<mat-select>
<mat-option *ngFor="let item of Week.values" [value]="item.value">{{ item.label }}</mat-option>
<mat-option *ngFor="let item of Week.items" [value]="item.value">{{ item.label }}</mat-option>
</mat-select>

@@ -560,7 +579,7 @@ ```

<nz-select>
<nz-option *ngFor="let item of Week.values" [nzValue]="item.value">{{ item.label }}</nz-option>
<nz-option *ngFor="let item of Week.items" [nzValue]="item.value">{{ item.label }}</nz-option>
</nz-select>
```
- `toSelect` method is similar to `values`, but is allowed to add a default option at the top. The default option can be a boolean value or a custom object.
- `toSelect` method is similar to `items`, but is allowed to add a default option at the top. The default option can be a boolean value or a custom object.

@@ -611,3 +630,3 @@ - If set to a boolean value, the default option is `{ value: '', label: 'All' }`, the display name only supports English. If you need localization, please parse and process the built-in resource key `enum-plus.options.all` in the localization method. For more details about localization, please refer to the [Localization](#localization) section

<ProFormSelect valueEnum={Week.valuesEnum()} />;
<ProFormSelect valueEnum={Week.toValueMap()} />;
```

@@ -655,3 +674,3 @@

We know that there are methods like `label`, `key`, `toSelect` on the enum type. If they have the same name as an enum item, the enum item's value has a higher priority and will override these methods. But don't worry, you can access them under `values`. Please refer to the code example below:
We know that there are methods like `label`, `key`, `toSelect` on the enum type. If they have the same name as an enum item, the enum item's value has a higher priority and will override these methods. But don't worry, you can access them under `items`. Please refer to the code example below:

@@ -667,11 +686,11 @@ ```js

Week.label; // 4, enum item has higher priority and will override the method
// You can access these methods through values 🙂
Week.values.keys // ['foo', 'bar', 'keys', 'label']
Week.values.label(1); // 'foo'
// You can access these methods through items 🙂
Week.items.keys // ['foo', 'bar', 'keys', 'label']
Week.items.label(1); // 'foo'
```
An even more extreme case, what if `values` conflicts with the name of an enum item? Don't worry, you can still access the `values` array through an alias field. Refer to the example below:
An even more extreme case, what if `items` conflicts with the name of an enum item? Don't worry, you can still access the `items` array through an alias field. Refer to the example below:
```js
import { VALUES } from 'enum-plus';
import { ITEMS } from 'enum-plus';

@@ -681,13 +700,13 @@ const Week = Enum({

bar: { value: 2 },
values: { value: 3 }, // Naming conflict
items: { value: 3 }, // Naming conflict
} as const);
Week.values; // 3, enum item has higher priority and will override values
Week[VALUES]; // VALUES is an alias Symbol
Week.items; // 3, enum item has higher priority and will override items
Week[ITEMS]; // ITEMS is an alias Symbol
// [
// { value: 1, key: 'foo', label: 'foo' },
// { value: 2, key: 'bar', label: 'bar' },
// { value: 3, key: 'values', label: 'values' }
// { value: 3, key: 'items', label: 'items' }
// ]
// Equivalent to the original Week.values 🙂
// Equivalent to the original Week.items 🙂
```

@@ -777,9 +796,11 @@

Enum.extend({
isWeekend() {
return this.value === 0 || this.value === 6;
getLabels(this: ReturnType<typeof Enum>) {
return this.items.map((item) => item.label);
},
reversedValues(this: ReturnType<typeof Enum>) {
return this.values.reverse();
return this.items.reverse();
},
});
Week.getLabels(); // ['Sunday', 'Monday']
```

@@ -797,3 +818,3 @@

export interface EnumExtension<T, K, V> {
isWeekend: (value: number) => boolean;
getLabels: () => string[];
reversedValues: () => EnumItemClass<EnumItemInit<V>, K, V>[];

@@ -812,2 +833,2 @@ }

If you want to provide more friendly type hints in the extension methods, you may need to use these type parameters. These are all optional, if your extension method is as simple as `isWeekend`, you can completely ignore them
If you want to provide more friendly type hints in the extension methods, you may need to use these type parameters. These are all optional, if your extension method is as simple as `getLabels`, you can completely ignore them

@@ -1,2 +0,2 @@

<!-- markdownlint-disable MD009 -->
<!-- markdownlint-disable MD009 MD001 -->

@@ -9,3 +9,3 @@ # enum-plus

[![npm version](https://img.shields.io/npm/v/enum-plus.svg)](https://www.npmjs.com/package/enum-plus)
[![npm version](https://img.shields.io/npm/v/enum-plus.svg?color=red)](https://www.npmjs.com/package/enum-plus)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/enum-plus)](https://bundlephobia.com/result?p=enum-plus)

@@ -135,3 +135,3 @@ [![npm downloads](https://img.shields.io/npm/dm/enum-plus.svg)](https://www.npmjs.com/package/enum-plus)

});
Week.values; // 输出如下:
Week.items; // 输出如下:
// [ { value: 1, label: '狗', key: 'dog' },

@@ -142,2 +142,23 @@ // { value: 2, label: '猫', key: 'cat' },

#### 示例 6:支持原生枚举初始化,相当于给原生枚举添加一些扩展方法
```ts
import { Enum } from 'enum-plus';
enum init {
Sunday = 0,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
}
const Week = Enum(init);
Week.Sunday; // 0
Week.Monday; // 1
Week.Saturday; // 6
Week.label('Sunday'); // Sunday
```
## API

@@ -158,3 +179,3 @@

### values
### items

@@ -219,3 +240,3 @@ `{value, label, key, raw}[]`

`toSelect`与`values`相似,都是返回一个包含全部枚举项的数组。区别是,`toSelect`返回的元素只包含`label`和`value`两个字段,同时,`toSelect`方法支持在数组头部插入一个默认元素,一般用于下拉框等组件的默认选项,表示全部、无值或不限等,当然你也能够自定义这个默认选项
`toSelect`与`items`相似,都是返回一个包含全部枚举项的数组。区别是,`toSelect`返回的元素只包含`label`和`value`两个字段,同时,`toSelect`方法支持在数组头部插入一个默认元素,一般用于下拉框等组件的默认选项,表示全部、无值或不限等,当然你也能够自定义这个默认选项

@@ -251,3 +272,3 @@ ---

生成一个 filters 数组,可以直接传递给 [Ant Design](https://ant-design.antgroup.com/components/table-cn#table-demo-head) Table 组件的列配置,在表头中显示一个下拉筛选框,用来过滤表格数据
生成一个对象数组,可以直接传递给 [Ant Design](https://ant-design.antgroup.com/components/table-cn#table-demo-head) Table 组件的列配置,在表头中显示一个下拉筛选框,用来过滤表格数据

@@ -389,3 +410,3 @@ 数据格式为:

```js
Week.values; // 输出如下:
Week.items; // 输出如下:
// [

@@ -402,3 +423,3 @@ // { value: 0, label: '星期日', key: 'Sunday', raw: { value: 0, label: '星期日' } },

```js
Week.values[0].value; // 0
Week.items[0].value; // 0
```

@@ -412,3 +433,3 @@

Week.has(1); // true
Week.values.some(item => item.value === 1); // true
Week.items.some(item => item.value === 1); // true
1 instance of Week; // true

@@ -432,11 +453,11 @@ ```

```js
Week.values.length; // 2
Week.values.map((item) => item.value); // [0, 1],✅ 可遍历
Week.values.forEach((item) => {}); // ✅ 可遍历
for (let item of Week.values) {
Week.items.length; // 2
Week.items.map((item) => item.value); // [0, 1],✅ 可遍历
Week.items.forEach((item) => {}); // ✅ 可遍历
for (let item of Week.items) {
// ✅ 可遍历
}
Week.values.push({ value: 2, label: '星期二' }); // ❌ 不可修改
Week.values.splice(0, 1); // ❌ 不可修改
Week.values[0].label = 'foo'; // ❌ 不可修改
Week.items.push({ value: 2, label: '星期二' }); // ❌ 不可修改
Week.items.splice(0, 1); // ❌ 不可修改
Week.items[0].label = 'foo'; // ❌ 不可修改
```

@@ -482,3 +503,3 @@

- `values` 可以直接作为组件的数据源(以 Select 组件为例)
- `items` 可以直接作为组件的数据源(以 Select 组件为例)

@@ -491,3 +512,3 @@ [Ant Design](https://ant-design.antgroup.com/components/select-cn) | [Arco Design](https://arco.design/react/components/select)

<Select options={Week.values} />;
<Select options={Week.items} />;
```

@@ -501,3 +522,3 @@

<Select>
{Week.values.map((item) => (
{Week.items.map((item) => (
<MenuItem key={item.value} value={item.value}>

@@ -515,3 +536,3 @@ {item.label}

<DropDownList data={Week.values} textField="label" dataItemKey="value" />;
<DropDownList data={Week.items} textField="label" dataItemKey="value" />;
```

@@ -523,3 +544,3 @@

<el-select>
<el-option v-for="item in Week.values" v-bind="item" />
<el-option v-for="item in Week.items" v-bind="item" />
</el-select>

@@ -531,3 +552,3 @@ ```

```tsx
<a-select :options="Week.values" />
<a-select :options="Week.items" />
```

@@ -538,3 +559,3 @@

```tsx
<v-select :items="Week.values" item-title="label" />
<v-select :items="Week.items" item-title="label" />
```

@@ -548,3 +569,3 @@

<mat-select>
<mat-option *ngFor="let item of Week.values" [value]="item.value">{{ item.label }}</mat-option>
<mat-option *ngFor="let item of Week.items" [value]="item.value">{{ item.label }}</mat-option>
</mat-select>

@@ -559,7 +580,7 @@ ```

<nz-select>
<nz-option *ngFor="let item of Week.values" [nzValue]="item.value">{{ item.label }}</nz-option>
<nz-option *ngFor="let item of Week.items" [nzValue]="item.value">{{ item.label }}</nz-option>
</nz-select>
```
- `toSelect`方法与`values`类似,但允许在头部增加一个默认选项。默认选项可以是一个布尔值,也可以是一个自定义对象。
- `toSelect`方法与`items`类似,但允许在头部增加一个默认选项。默认选项可以是一个布尔值,也可以是一个自定义对象。

@@ -653,3 +674,3 @@ - 如果是布尔值,则默认选项为`{ value: '', label: 'All' }`,显示名称只支持英文。如果希望支持本地化,请在本地化方法中解析并处理`enum-plus.options.all`这个内置资源。关于本地化的更多详情,请参考[本地化](#本地化)章节

我们知道枚举类型上还存在 `label`、`key`、`toSelect` 等方法,如果与某个枚举项重名,枚举项的值优先级更高,会覆盖掉这些方法。但不用担心,你可以在 `values` 下访问到它们。请参考下面的代码示例:
我们知道枚举类型上还存在 `label`、`key`、`toSelect` 等方法,如果与某个枚举项重名,枚举项的值优先级更高,会覆盖掉这些方法。但不用担心,你可以在 `items` 下访问到它们。请参考下面的代码示例:

@@ -665,11 +686,11 @@ ```js

Week.label; // 4,枚举项优先级更高,会覆盖掉方法
// 可以通过 values 访问到这些方法 🙂
Week.values.keys // ['foo', 'bar', 'keys', 'label']
Week.values.label(1); // 'foo'
// 可以通过 items 访问到这些方法 🙂
Week.items.keys // ['foo', 'bar', 'keys', 'label']
Week.items.label(1); // 'foo'
```
更极端一些,万一`values`与枚举项命名冲突怎么办?放心,你仍然可以通过别名字段访问到`values`数组。参考下面的示例:
更极端一些,万一`items`与枚举项命名冲突怎么办?放心,你仍然可以通过别名字段访问到`items`数组。参考下面的示例:
```js
import { VALUES } from 'enum-plus';
import { ITEMS } from 'enum-plus';

@@ -679,13 +700,13 @@ const Week = Enum({

bar: { value: 2 },
values: { value: 3 }, // 命名冲突
items: { value: 3 }, // 命名冲突
} as const);
Week.values; // 3,枚举项优先级更高,会覆盖掉 values
Week[VALUES]; // VALUES 是一个别名Symbol
Week.items; // 3,枚举项优先级更高,会覆盖掉 items
Week[ITEMS]; // ITEMS 是一个别名Symbol
// [
// { value: 1, key: 'foo', label: 'foo' },
// { value: 2, key: 'bar', label: 'bar' },
// { value: 3, key: 'values', label: 'values' }
// { value: 3, key: 'items', label: 'items' }
// ]
// 等价于原来的 Week.values 🙂
// 等价于原来的 Week.items 🙂
```

@@ -775,9 +796,11 @@

Enum.extend({
isWeekend() {
return this.value === 0 || this.value === 6;
getLabels(this: ReturnType<typeof Enum>) {
return this.items.map((item) => item.label);
},
reversedValues(this: ReturnType<typeof Enum>) {
return this.values.reverse();
return this.items.reverse();
},
});
Week.getLabels(); // ['星期日', '星期一']
```

@@ -795,3 +818,3 @@

export interface EnumExtension<T, K, V> {
isWeekend: (value: number) => boolean;
getLabels: () => string[];
reversedValues: () => EnumItemClass<EnumItemInit<V>, K, V>[];

@@ -810,2 +833,2 @@ }

如果你希望在扩展方法中提供更友好的类型提示,你或许可能需要使用到这些类型参数。这些都是可选的,如果你的扩展方法像`isWeekend`这样简单,那么你完全可以忽略它们
如果你希望在扩展方法中提供更友好的类型提示,你或许可能需要使用到这些类型参数。这些都是可选的,如果你的扩展方法像`getLabels`这样简单,那么你完全可以忽略它们

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc