UNPKG

ts-data-forge

Version:

[![npm version](https://img.shields.io/npm/v/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![npm downloads](https://img.shields.io/npm/dm/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![License](https://img.shields.

105 lines (102 loc) 3.04 kB
import '../../number/branded-types/finite-number.mjs'; import '../../number/branded-types/int.mjs'; import '../../number/branded-types/int16.mjs'; import '../../number/branded-types/int32.mjs'; import '../../number/branded-types/non-negative-finite-number.mjs'; import '../../number/branded-types/non-negative-int16.mjs'; import '../../number/branded-types/non-negative-int32.mjs'; import '../../number/branded-types/non-zero-finite-number.mjs'; import '../../number/branded-types/non-zero-int.mjs'; import '../../number/branded-types/non-zero-int16.mjs'; import '../../number/branded-types/non-zero-int32.mjs'; import '../../number/branded-types/non-zero-safe-int.mjs'; import '../../number/branded-types/non-zero-uint16.mjs'; import '../../number/branded-types/non-zero-uint32.mjs'; import '../../number/branded-types/positive-finite-number.mjs'; import '../../number/branded-types/positive-int.mjs'; import '../../number/branded-types/positive-int16.mjs'; import '../../number/branded-types/positive-int32.mjs'; import '../../number/branded-types/positive-safe-int.mjs'; import '../../number/branded-types/positive-uint16.mjs'; import '../../number/branded-types/positive-uint32.mjs'; import '../../number/branded-types/safe-int.mjs'; import '../../number/branded-types/safe-uint.mjs'; import '../../number/branded-types/uint.mjs'; import '../../number/branded-types/uint16.mjs'; import { asUint32 } from '../../number/branded-types/uint32.mjs'; import '../../number/enum/int8.mjs'; import '../../number/enum/uint8.mjs'; import '../../number/num.mjs'; import '../../number/refined-number-utils.mjs'; /** * Returns an iterator of `[index, value]` pairs for an array. * * @example * * ```ts * const tags = ['alpha', 'beta', 'gamma'] as const; * * const entryList = Array.from( * Arr.entries(tags), * ([index, tag]) => [Number(index), tag] as const, * ); * * assert.deepStrictEqual( * entryList, * Array.from([ * [0, 'alpha'], * [1, 'beta'], * [2, 'gamma'], * ]), * ); * ``` */ const entries = function* (array) { for (const [index, value] of array.entries()) { yield [asUint32(index), value]; } }; /** * Returns an iterator of values for an array. * * @example * * ```ts * const players = ['Ada', 'Grace', 'Alan']; * * const valueList = Array.from(Arr.values(players)); * * assert.deepStrictEqual(valueList, players); * ``` */ const values = function* (array) { for (const value of array.values()) { yield value; } }; /** * Returns an iterator of indices for an array. * * @example * * ```ts * const items = ['zero', 'one', 'two'] as const; * * const indexList = Array.from(Arr.indices(items)); * * assert.deepStrictEqual(indexList, [0, 1, 2]); * ``` */ const indices = function* (array) { for (const key of array.keys()) { yield asUint32(key); } }; /** * Alias for `indices`. * * @see {@link indices} */ const keys = indices; export { entries, indices, keys, values }; //# sourceMappingURL=array-utils-iterators.mjs.map