@mudssky/jsutils
    Preparing search index...

    Class EnumArray<T>

    枚举数组类,继承了Array,提供高性能的枚举操作方法

    该类通过内部维护的Map结构实现O(1)时间复杂度的查找操作, 同时保持了Array的所有原生方法和特性。

    const statusList = [
    { label: '待处理', value: 1, color: 'orange' },
    { label: '已完成', value: 2, color: 'green' }
    ] as const

    const statusEnum = createEnum(statusList)
    const label = statusEnum.getLabelByValue(1) // '待处理'
    const item = statusEnum.getItemByValue(1) // 完整对象

    Type Parameters

    • T extends readonly EnumArrayObj[]

      枚举数组的完整字面量类型,必须由 as const 断言。 例如:typeof [\{ label: 'A', value: 1 \}] as const

    Hierarchy

    Indexable

    • [n: number]: BaseEnumObj
    Index

    Constructors

    • 创建EnumArray实例

      构造函数会初始化内部的Map结构以提供高性能查找, 并根据配置检查重复的value和label。

      Type Parameters

      • T extends readonly BaseEnumObj[]

      Parameters

      • list: T

        符合EnumArrayObj接口的元组,建议使用 as const 断言

      • Optionaloptions: EnumCreationOptions

        创建时的配置项

      Returns EnumArray<T>

      const list = [
      { label: '启用', value: 1 },
      { label: '禁用', value: 0 }
      ] as const
      const enumArray = new EnumArray(list)

      // 配置检查级别
      const enumArray2 = new EnumArray(list, { checkDuplicates: 'always' })

    Properties

    "[unscopables]": {
        "[iterator]"?: boolean;
        "[unscopables]"?: boolean;
        at?: boolean;
        concat?: boolean;
        copyWithin?: boolean;
        entries?: boolean;
        every?: boolean;
        fill?: boolean;
        filter?: boolean;
        find?: boolean;
        findIndex?: boolean;
        findLast?: boolean;
        findLastIndex?: boolean;
        flat?: boolean;
        flatMap?: boolean;
        forEach?: boolean;
        includes?: boolean;
        indexOf?: boolean;
        join?: boolean;
        keys?: boolean;
        lastIndexOf?: boolean;
        length?: boolean;
        map?: boolean;
        pop?: boolean;
        push?: boolean;
        reduce?: boolean;
        reduceRight?: boolean;
        reverse?: boolean;
        shift?: boolean;
        slice?: boolean;
        some?: boolean;
        sort?: boolean;
        splice?: boolean;
        toLocaleString?: boolean;
        toReversed?: boolean;
        toSorted?: boolean;
        toSpliced?: boolean;
        toString?: boolean;
        unshift?: boolean;
        values?: boolean;
        with?: boolean;
        [key: number]: undefined | boolean;
    }

    Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.

    Type declaration

    • [key: number]: undefined | boolean
    • Optional[iterator]?: boolean
    • Optional Readonly[unscopables]?: boolean

      Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.

    • Optionalat?: boolean
    • Optionalconcat?: boolean
    • OptionalcopyWithin?: boolean
    • Optionalentries?: boolean
    • Optionalevery?: boolean
    • Optionalfill?: boolean
    • Optionalfilter?: boolean
    • Optionalfind?: boolean
    • OptionalfindIndex?: boolean
    • OptionalfindLast?: boolean
    • OptionalfindLastIndex?: boolean
    • Optionalflat?: boolean
    • OptionalflatMap?: boolean
    • OptionalforEach?: boolean
    • Optionalincludes?: boolean
    • OptionalindexOf?: boolean
    • Optionaljoin?: boolean
    • Optionalkeys?: boolean
    • OptionallastIndexOf?: boolean
    • Optionallength?: boolean

      Gets or sets the length of the array. This is a number one higher than the highest index in the array.

    • Optionalmap?: boolean
    • Optionalpop?: boolean
    • Optionalpush?: boolean
    • Optionalreduce?: boolean
    • OptionalreduceRight?: boolean
    • Optionalreverse?: boolean
    • Optionalshift?: boolean
    • Optionalslice?: boolean
    • Optionalsome?: boolean
    • Optionalsort?: boolean
    • Optionalsplice?: boolean
    • OptionaltoLocaleString?: boolean
    • OptionaltoReversed?: boolean
    • OptionaltoSorted?: boolean
    • OptionaltoSpliced?: boolean
    • OptionaltoString?: boolean
    • Optionalunshift?: boolean
    • Optionalvalues?: boolean
    • Optionalwith?: boolean
    length: number

    Gets or sets the length of the array. This is a number one higher than the highest index in the array.

    "[species]": ArrayConstructor

    Methods

    • Iterator

      Returns ArrayIterator<BaseEnumObj>

    • Returns the item located at the specified index.

      Parameters

      • index: number

        The zero-based index of the desired code unit. A negative index will count back from the last item.

      Returns undefined | BaseEnumObj

    • Combines two or more arrays. This method returns a new array without modifying any existing arrays.

      Parameters

      • ...items: ConcatArray<BaseEnumObj>[]

        Additional arrays and/or items to add to the end of the array.

      Returns BaseEnumObj[]

    • Combines two or more arrays. This method returns a new array without modifying any existing arrays.

      Parameters

      • ...items: (BaseEnumObj | ConcatArray<BaseEnumObj>)[]

        Additional arrays and/or items to add to the end of the array.

      Returns BaseEnumObj[]

    • Parameters

      • target: number
      • start: number
      • Optionalend: number

      Returns this

      EnumArray is immutable. This method will throw an error.

    • Returns an iterable of key, value pairs for every entry in the array

      Returns ArrayIterator<[number, BaseEnumObj]>

    • Determines whether all the members of an array satisfy the specified test.

      Type Parameters

      • S extends BaseEnumObj

      Parameters

      • predicate: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => value is S

        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.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns this is S[]

    • Determines whether all the members of an array satisfy the specified test.

      Parameters

      • predicate: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => unknown

        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.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns boolean

    • Parameters

      • value: any
      • Optionalstart: number
      • Optionalend: number

      Returns this

      EnumArray is immutable. This method will throw an error.

    • Returns the elements of an array that meet the condition specified in a callback function.

      Type Parameters

      • S extends BaseEnumObj

      Parameters

      • predicate: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => value is S

        A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns S[]

    • Returns the elements of an array that meet the condition specified in a callback function.

      Parameters

      • predicate: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => unknown

        A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns BaseEnumObj[]

    • Returns the value of the first element in the array where predicate is true, and undefined otherwise.

      Type Parameters

      • S extends BaseEnumObj

      Parameters

      • predicate: (value: BaseEnumObj, index: number, obj: BaseEnumObj[]) => value is S

        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.

      • OptionalthisArg: any

        If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

      Returns undefined | S

    • Parameters

      • predicate: (value: BaseEnumObj, index: number, obj: BaseEnumObj[]) => unknown
      • OptionalthisArg: any

      Returns undefined | BaseEnumObj

    • Returns the index of the first element in the array where predicate is true, and -1 otherwise.

      Parameters

      • predicate: (value: BaseEnumObj, index: number, obj: BaseEnumObj[]) => unknown

        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.

      • OptionalthisArg: any

        If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

      Returns number

    • Returns the value of the last element in the array where predicate is true, and undefined otherwise.

      Type Parameters

      • S extends BaseEnumObj

      Parameters

      • predicate: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => value is S

        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.

      • OptionalthisArg: any

        If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

      Returns undefined | S

    • Parameters

      • predicate: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => unknown
      • OptionalthisArg: any

      Returns undefined | BaseEnumObj

    • Returns the index of the last element in the array where predicate is true, and -1 otherwise.

      Parameters

      • predicate: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => unknown

        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.

      • OptionalthisArg: any

        If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

      Returns number

    • Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.

      Type Parameters

      • A
      • D extends number = 1

      Parameters

      • this: A
      • Optionaldepth: D

        The maximum recursion depth

      Returns FlatArray<A, D>[]

    • 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.

      Type Parameters

      • U
      • This = undefined

      Parameters

      • callback: (
            this: This,
            value: BaseEnumObj,
            index: number,
            array: BaseEnumObj[],
        ) => U | readonly U[]

        A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array.

      • OptionalthisArg: This

        An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value.

      Returns U[]

    • Performs the specified action for each element in an array.

      Parameters

      • callbackfn: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => void

        A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

      Returns void

    • 使value和label用相同的值

      Returns (T[number] & { value: string })[]

      所有项的label作为value的新数组

      该方法功能特殊,建议在外部通过 map 方法实现: myEnum.map(item => ({ ...item, value: item.label }))

    • 根据label获取指定属性的值

      该方法提供类型安全的属性访问,支持获取枚举对象的任意属性

      Type Parameters

      • K extends string | number | symbol

        属性键名类型

      Parameters

      • label: LabelOf<T>

        枚举标签

      • key: K

        属性键名

      Returns undefined | T[number][K]

      属性值,如果未找到则返回undefined

      const color = enumArray.getAttrByLabel('启用', 'color') // 类型安全的属性访问
      
    • 根据value获取指定属性的值

      该方法提供类型安全的属性访问,支持获取枚举对象的任意属性

      Type Parameters

      • K extends string | number | symbol

        属性键名类型

      Parameters

      • value: ValueOf<T>

        枚举值

      • key: K

        属性键名

      Returns undefined | T[number][K]

      • 属性值,如果未找到则返回undefined
      const color = enumArray.getAttrByValue(1, 'color') // 类型安全的属性访问
      
    • 根据label获取显示文本

      如果枚举对象有displayText属性则返回displayText,否则返回label本身

      Parameters

      Returns string

      显示文本

      const displayText = enumArray.getDisplayTextByLabel('启用') // '状态启用' 或 '启用'
      
    • 根据value获取显示文本

      如果枚举对象有displayText属性则返回displayText,否则返回label

      Parameters

      Returns undefined | string

      显示文本

      const displayText = enumArray.getDisplayTextByValue(1) // '状态启用' 或 '启用'
      
    • 根据label获取完整的枚举对象

      时间复杂度:O(1)

      Parameters

      Returns undefined | T[number]

      返回匹配的完整对象,如果未找到则返回undefined

      const item = enumArray.getItemByLabel('启用')
      // { label: '启用', value: 1, ...其他属性 }
    • 根据label获取完整的枚举对象 (兼容性方法)

      Parameters

      Returns undefined | T[number]

      匹配的完整对象或undefined

      请使用 getItemByLabel,该方法性能更好 (O(1) vs O(n))

    • 根据value获取完整的枚举对象

      时间复杂度:O(1)

      Parameters

      Returns undefined | T[number]

      返回匹配的完整对象,如果未找到则返回undefined

      const item = enumArray.getItemByValue(1)
      // { label: '启用', value: 1, ...其他属性 }
    • 根据value获取完整的枚举对象 (兼容性方法)

      Parameters

      Returns undefined | T[number]

      匹配的完整对象或undefined

      请使用 getItemByValue,该方法性能更好 (O(1) vs O(n))

    • 使用映射字典改变枚举类的键

      Parameters

      • mapDictionary: Record<string, string>

        键映射字典

      Returns ArrayIterator<Record<string, any>>

      映射后对象的迭代器

      建议直接使用 getKeyMappedList,迭代器模式在此场景下意义不大

    • 使用映射字典改变枚举类的键,返回新对象组成的数组

      Parameters

      • mapDictionary: Record<string, string>

        键映射字典,例如 { value: 'id', label: 'name' }

      Returns Record<string, any>[]

      • 映射后的对象数组
      const mapped = enumArray.getKeyMappedList(\{ value: 'id', label: 'name' \})
      // [\{ id: 1, name: '启用' \}, \{ id: 0, name: '禁用' \}]
    • 根据value获取对应的label

      时间复杂度:O(1)

      Parameters

      • value: ValueOf<T>

        枚举值,必须是创建枚举时定义的value之一

      Returns undefined | LabelOf<T>

      返回value匹配的label,如果未找到则返回undefined

      const label = enumArray.getLabelByValue(1) // '启用'
      
    • 获取所有label的列表

      Returns readonly LabelOf<T>[]

      • 包含所有枚举标签的数组
      const labels = enumArray.getLabelList() // ['启用', '禁用']
      
    • 获取所有label的列表 (别名方法)

      Returns readonly LabelOf<T>[]

      包含所有枚举标签的数组

      const labels = enumArray.getLabels() // ['启用', '禁用']
      
    • 根据value列表获取label列表

      Parameters

      Returns (undefined | LabelOf<T>)[]

      • label列表

      建议在外部通过 values.map(v => myEnum.getLabelByValue(v)) 实现,以保持API简洁

    • 根据label获取对应的value

      时间复杂度:O(1)

      Parameters

      • label: LabelOf<T>

        枚举标签,必须是创建枚举时定义的label之一

      Returns undefined | ValueOf<T>

      返回label匹配的value,如果未找到则返回undefined

      const value = enumArray.getValueByLabel('启用') // 1
      
    • 获取所有value的列表

      Returns ValueOf<T>[]

      • 包含所有枚举值的数组
      const values = enumArray.getValues() // [1, 0]
      
    • 根据label列表获取value列表

      Parameters

      Returns (undefined | ValueOf<T>)[]

      • value列表

      建议在外部通过 labels.map(l => myEnum.getValueByLabel(l)) 实现,以保持API简洁

    • 检查给定的值或标签是否存在于枚举中

      Parameters

      • valueOrLabel: unknown

        要检查的值或标签

      Returns boolean

      • 如果存在则返回true
      const exists = enumArray.has(1) // true
      const exists2 = enumArray.has('启用') // true
    • Determines whether an array includes a certain element, returning true or false as appropriate.

      Parameters

      • searchElement: BaseEnumObj

        The element to search for.

      • OptionalfromIndex: number

        The position in this array at which to begin searching for searchElement.

      Returns boolean

    • Returns the index of the first occurrence of a value in an array, or -1 if it is not present.

      Parameters

      • searchElement: BaseEnumObj

        The value to locate in the array.

      • OptionalfromIndex: number

        The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

      Returns number

    • 类型守卫:检查给定标签是否为有效的枚举标签

      该方法不仅检查标签的存在性,还提供TypeScript类型缩窄功能, 在类型守卫通过后,TypeScript会将参数类型缩窄为具体的枚举标签类型。

      Parameters

      • label: unknown

        要检查的标签,可以是任意类型

      Returns label is LabelOf<T>

      如果是有效的枚举标签则返回true,同时提供类型缩窄

      const unknownLabel: unknown = '启用'
      if (enumArray.isEnumLabel(unknownLabel)) {
      // 此时 unknownLabel 的类型被缩窄为 LabelOf<T>
      const value = enumArray.getValueByLabel(unknownLabel) // 类型安全
      }
    • 类型守卫:检查给定值是否为有效的枚举值

      该方法不仅检查值的存在性,还提供TypeScript类型缩窄功能, 在类型守卫通过后,TypeScript会将参数类型缩窄为具体的枚举值类型。

      Parameters

      • value: unknown

        要检查的值,可以是任意类型

      Returns value is ValueOf<T>

      • 如果是有效的枚举值则返回true,同时提供类型缩窄
      const unknownValue: unknown = 1
      if (enumArray.isEnumValue(unknownValue)) {
      // 此时 unknownValue 的类型被缩窄为 ValueOf<T>
      const label = enumArray.getLabelByValue(unknownValue) // 类型安全
      }
    • 判断给定的label是否在指定的label集合中

      该方法的核心优势是:在输入label参数时,会获得所有枚举内合法label的自动补全提示, 同时它也接受任意普通字符串作为输入,实现了类型安全和开发便利性的完美平衡。

      Parameters

      • label: EnhancedLabel<LabelOf<T>>

        要检查的标签,输入时会获得自动补全

      • allowedLabels: readonly LabelOf<T>[]

        包含所有期望的合法标签的数组

      Returns boolean

      • 如果label不为null/undefined且存在于allowedLabels中,则返回true
      const isAllowed = enumArray.isLabelIn(userInput, ['启用', '禁用'])
      
    • 判断label是否匹配列表,可以节省引入Type的时间

      Parameters

      • labels: LabelOf<T>[]

        标签列表

      • Optionallabel: any

        要检查的标签

      Returns boolean

      • 是否匹配
    • 判断枚举值匹配label列表中的某个label

      Parameters

      • labels: LabelOf<T>[]

        标签列表

      • Optionalvalue: any

        要检查的值

      Returns boolean

      • 是否匹配

      请使用 isValueInLabels(value, labels),参数顺序更符合直觉且类型更安全

    • 判断给定的外部值是否属于指定的label集合

      该方法特别适用于处理来自API等外部源的数据,支持null和undefined的安全检查

      Parameters

      • value: ExternalValue

        要检查的值,可以是来自API等外部源的数据

      • labels: readonly LabelOf<T>[]

        允许的标签数组

      Returns boolean

      • 如果value对应的label在labels中则返回true
      const isValid = enumArray.isValueInLabels(apiData.status, ['启用', '禁用'])
      
    • Adds all the elements of an array into a string, separated by the specified separator string.

      Parameters

      • Optionalseparator: string

        A 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 string

    • Returns an iterable of keys in the array

      Returns ArrayIterator<number>

    • Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.

      Parameters

      • searchElement: BaseEnumObj

        The value to locate in the array.

      • OptionalfromIndex: number

        The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array.

      Returns number

    • Calls a defined callback function on each element of an array, and returns an array that contains the results.

      Type Parameters

      • U

      Parameters

      • callbackfn: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => U

        A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

      Returns U[]

    • Returns undefined | BaseEnumObj

      EnumArray is immutable. This method will throw an error.

    • Parameters

      • ...items: any[]

      Returns number

      EnumArray is immutable. This method will throw an error.

    • 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.

      Parameters

      • callbackfn: (
            previousValue: BaseEnumObj,
            currentValue: BaseEnumObj,
            currentIndex: number,
            array: BaseEnumObj[],
        ) => BaseEnumObj

        A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

      Returns BaseEnumObj

    • Parameters

      • callbackfn: (
            previousValue: BaseEnumObj,
            currentValue: BaseEnumObj,
            currentIndex: number,
            array: BaseEnumObj[],
        ) => BaseEnumObj
      • initialValue: BaseEnumObj

      Returns BaseEnumObj

    • 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.

      Type Parameters

      • U

      Parameters

      • callbackfn: (
            previousValue: U,
            currentValue: BaseEnumObj,
            currentIndex: number,
            array: BaseEnumObj[],
        ) => U

        A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

      • initialValue: U

        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.

      Returns U

    • 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.

      Parameters

      • callbackfn: (
            previousValue: BaseEnumObj,
            currentValue: BaseEnumObj,
            currentIndex: number,
            array: BaseEnumObj[],
        ) => BaseEnumObj

        A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

      Returns BaseEnumObj

    • Parameters

      • callbackfn: (
            previousValue: BaseEnumObj,
            currentValue: BaseEnumObj,
            currentIndex: number,
            array: BaseEnumObj[],
        ) => BaseEnumObj
      • initialValue: BaseEnumObj

      Returns BaseEnumObj

    • 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.

      Type Parameters

      • U

      Parameters

      • callbackfn: (
            previousValue: U,
            currentValue: BaseEnumObj,
            currentIndex: number,
            array: BaseEnumObj[],
        ) => U

        A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

      • initialValue: U

        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.

      Returns U

    • Returns this

      EnumArray is immutable. This method will throw an error.

    • Returns undefined | BaseEnumObj

      EnumArray is immutable. This method will throw an error.

    • 私有方法:获取重复检查配置

      根据传入的配置项决定是否需要执行重复检查。

      Parameters

      Returns boolean

      是否应该执行重复检查

    • 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.

      Parameters

      • Optionalstart: number

        The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0.

      • Optionalend: number

        The 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.

      Returns BaseEnumObj[]

    • Determines whether the specified callback function returns true for any element of an array.

      Parameters

      • predicate: (value: BaseEnumObj, index: number, array: BaseEnumObj[]) => unknown

        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.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns boolean

    • Parameters

      • OptionalcompareFn: (a: any, b: any) => number

      Returns this

      EnumArray is immutable. This method will throw an error.

    • Parameters

      • start: number
      • OptionaldeleteCount: number
      • ...items: any[]

      Returns BaseEnumObj[]

      EnumArray is immutable. This method will throw an error.

    • 转换为普通数组

      Returns T[number][]

      普通数组

      EnumArray本身继承自Array,可以直接使用或用展开语法 [...myEnum]

    • Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.

      Returns string

    • Parameters

      • locales: string | string[]
      • Optionaloptions: NumberFormatOptions & DateTimeFormatOptions

      Returns string

    • Returns a copy of an array with its elements reversed.

      Returns BaseEnumObj[]

    • Returns a copy of an array with its elements sorted.

      Parameters

      • OptionalcompareFn: (a: BaseEnumObj, b: BaseEnumObj) => number

        Function 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]
        

      Returns BaseEnumObj[]

    • Copies an array and removes elements and, if necessary, inserts new elements in their place. Returns the copied array.

      Parameters

      • start: number

        The zero-based location in the array from which to start removing elements.

      • deleteCount: number

        The number of elements to remove.

      • ...items: BaseEnumObj[]

        Elements to insert into the copied array in place of the deleted elements.

      Returns BaseEnumObj[]

      The copied array.

    • Copies an array and removes elements while returning the remaining elements.

      Parameters

      • start: number

        The zero-based location in the array from which to start removing elements.

      • OptionaldeleteCount: number

        The number of elements to remove.

      Returns BaseEnumObj[]

      A copy of the original array with the remaining elements.

    • Returns a string representation of an array.

      Returns string

    • Parameters

      • ...items: any[]

      Returns number

      EnumArray is immutable. This method will throw an error.

    • Returns an iterable of values in the array

      Returns ArrayIterator<BaseEnumObj>

    • 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.

      Parameters

      • index: number

        The index of the value to overwrite. If the index is negative, then it replaces from the end of the array.

      • value: BaseEnumObj

        The value to write into the copied array.

      Returns BaseEnumObj[]

      The copied array with the updated value.

    • Creates an array from an array-like object.

      Type Parameters

      • T

      Parameters

      • arrayLike: ArrayLike<T>

        An array-like object to convert to an array.

      Returns T[]

    • Creates an array from an iterable object.

      Type Parameters

      • T
      • U

      Parameters

      • arrayLike: ArrayLike<T>

        An array-like object to convert to an array.

      • mapfn: (v: T, k: number) => U

        A mapping function to call on every element of the array.

      • OptionalthisArg: any

        Value of 'this' used to invoke the mapfn.

      Returns U[]

    • Creates an array from an iterable object.

      Type Parameters

      • T

      Parameters

      • iterable: Iterable<T, any, any> | ArrayLike<T>

        An iterable object to convert to an array.

      Returns T[]

    • Creates an array from an iterable object.

      Type Parameters

      • T
      • U

      Parameters

      • iterable: Iterable<T, any, any> | ArrayLike<T>

        An iterable object to convert to an array.

      • mapfn: (v: T, k: number) => U

        A mapping function to call on every element of the array.

      • OptionalthisArg: any

        Value of 'this' used to invoke the mapfn.

      Returns U[]

    • Creates an array from an async iterator or iterable object.

      Type Parameters

      • T

      Parameters

      • iterableOrArrayLike:
            | AsyncIterable<T, any, any>
            | Iterable<T | PromiseLike<T>, any, any>
            | ArrayLike<T | PromiseLike<T>>

        An async iterator or array-like object to convert to an array.

      Returns Promise<T[]>

    • Creates an array from an async iterator or iterable object.

      Type Parameters

      • T
      • U

      Parameters

      • iterableOrArrayLike: AsyncIterable<T, any, any> | Iterable<T, any, any> | ArrayLike<T>

        An async iterator or array-like object to convert to an array.

      • mapFn: (value: Awaited<T>, index: number) => U
      • OptionalthisArg: any

        Value of 'this' used when executing mapfn.

      Returns Promise<Awaited<U>[]>

    • Parameters

      • arg: any

      Returns arg is any[]

    • Returns a new array from a set of elements.

      Type Parameters

      • T

      Parameters

      • ...items: T[]

        A set of elements to include in the new array object.

      Returns T[]