枚举数组的完整字面量类型,必须由 as const
断言。
例如:typeof [\{ label: 'A', value: 1 \}] as const
创建EnumArray实例
构造函数会初始化内部的Map结构以提供高性能查找, 并根据配置检查重复的value和label。
符合EnumArrayObj接口的元组,建议使用 as const 断言
Optional
options: EnumCreationOptions创建时的配置项
Readonly
[unscopables]Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optional
[iterator]?: booleanOptional
Readonly
[unscopables]?: booleanIs an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optional
at?: booleanOptional
concat?: booleanOptional
copyWithin?: booleanOptional
entries?: booleanOptional
every?: booleanOptional
fill?: booleanOptional
filter?: booleanOptional
find?: booleanOptional
findIndex?: booleanOptional
findLast?: booleanOptional
findLastIndex?: booleanOptional
flat?: booleanOptional
flatMap?: booleanOptional
forEach?: booleanOptional
includes?: booleanOptional
indexOf?: booleanOptional
join?: booleanOptional
keys?: booleanOptional
lastIndexOf?: booleanOptional
length?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
Optional
map?: booleanOptional
pop?: booleanOptional
push?: booleanOptional
reduce?: booleanOptional
reduceRight?: booleanOptional
reverse?: booleanOptional
shift?: booleanOptional
slice?: booleanOptional
some?: booleanOptional
sort?: booleanOptional
splice?: booleanOptional
toLocaleString?: booleanOptional
toReversed?: booleanOptional
toSorted?: booleanOptional
toSpliced?: booleanOptional
toString?: booleanOptional
unshift?: booleanOptional
values?: booleanOptional
with?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
Static
Readonly
[species]Iterator
Returns the item located at the specified index.
The zero-based index of the desired code unit. A negative index will count back from the last item.
Combines two or more arrays. This method returns a new array without modifying any existing arrays.
Additional arrays and/or items to add to the end of the array.
Combines two or more arrays. This method returns a new array without modifying any existing arrays.
Additional arrays and/or items to add to the end of the array.
Returns an iterable of key, value pairs for every entry in the array
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the value of the first element in the array where predicate is true, and undefined otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Optional
thisArg: anyReturns the index of the first element in the array where predicate is true, and -1 otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns the value of the last element in the array where predicate is true, and undefined otherwise.
findLast calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLast immediately returns that element value. Otherwise, findLast returns undefined.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Optional
thisArg: anyReturns the index of the last element in the array where predicate is true, and -1 otherwise.
findLastIndex calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1.
A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array.
Optional
thisArg: ThisAn object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value.
Performs the specified action for each element in an array.
A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Determines whether an array includes a certain element, returning true or false as appropriate.
The element to search for.
Optional
fromIndex: numberThe position in this array at which to begin searching for searchElement.
Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
The value to locate in the array.
Optional
fromIndex: numberThe array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
判断给定的label是否在指定的label集合中
该方法的核心优势是:在输入label参数时,会获得所有枚举内合法label的自动补全提示, 同时它也接受任意普通字符串作为输入,实现了类型安全和开发便利性的完美平衡。
要检查的标签,输入时会获得自动补全
包含所有期望的合法标签的数组
判断给定的外部值是否属于指定的label集合
该方法特别适用于处理来自API等外部源的数据,支持null和undefined的安全检查
要检查的值,可以是来自API等外部源的数据
允许的标签数组
Adds all the elements of an array into a string, separated by the specified separator string.
Optional
separator: stringA string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.
Returns an iterable of keys in the array
Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
The value to locate in the array.
Optional
fromIndex: numberThe array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array.
Calls a defined callback function on each element of an array, and returns an array that contains the results.
A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
私有方法:获取重复检查配置
根据传入的配置项决定是否需要执行重复检查。
Optional
options: EnumCreationOptions枚举创建配置项
是否应该执行重复检查
Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array.
Optional
start: numberThe beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0.
Optional
end: numberThe end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array.
Determines whether the specified callback function returns true for any element of an array.
A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.
Optional
options: NumberFormatOptions & DateTimeFormatOptionsReturns a copy of an array with its elements reversed.
Returns a copy of an array with its elements sorted.
Optional
compareFn: (a: BaseEnumObj, b: BaseEnumObj) => numberFunction used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order.
[11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22]
Copies an array and removes elements and, if necessary, inserts new elements in their place. Returns the copied array.
The zero-based location in the array from which to start removing elements.
The number of elements to remove.
Elements to insert into the copied array in place of the deleted elements.
The copied array.
Copies an array and removes elements while returning the remaining elements.
The zero-based location in the array from which to start removing elements.
Optional
deleteCount: numberThe number of elements to remove.
A copy of the original array with the remaining elements.
Returns a string representation of an array.
Returns an iterable of values in the array
Copies an array, then overwrites the value at the provided index with the given value. If the index is negative, then it replaces from the end of the array.
The index of the value to overwrite. If the index is negative, then it replaces from the end of the array.
The value to write into the copied array.
The copied array with the updated value.
Static
fromStatic
fromCreates an array from an async iterator or iterable object.
Static
isStatic
of
枚举数组类,继承了Array,提供高性能的枚举操作方法
该类通过内部维护的Map结构实现O(1)时间复杂度的查找操作, 同时保持了Array的所有原生方法和特性。
Example