@ariesclark/array
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published
@ariesclark/array logo

Fast, efficient, and easy-to-use array extensions for TypeScript.

Packages

Installation

npm install @ariesclark/extensions
# Or directly, if you only need the array extension.
npm install @ariesclark/array

Documentation

group (function)

Groups the items in the array by the given function.

group([1, 2, 3, 4, 5], item => (item % 2 === 0 ? 'even' : 'odd'));
// {
//   odd: [1, 3, 5],
//   even: [2, 4]
// }

randomIndex (function)

Get a random index from an array.

Parameters:

  • array ({ length: 0; })
  • random (RandomFunction)

returns: null

const value = ['lorem', 'ipsum', 'dolor', 'sit', 'amet'];

randomIndex(value); // 3, eventually.
randomIndex(value); // 0, eventually.
randomIndex(value); // 2, eventually.

randomIndex (function)

Parameters:

  • array ({ length: number; })
  • random (RandomFunction)

returns: null

randomIndex (function)

Parameters:

  • array ({ length: number; })
  • random (RandomFunction)

returns: null

randomItem (function)

Get a random item from an array, with an optional random number generator.

Parameters:

  • array ({ length: 0; })
  • random (RandomFunction)

returns: null

const value = ['lorem', 'ipsum', 'dolor', 'sit', 'amet'];

randomItem(value); // "amet", eventually.
randomItem(value); // "dolor", eventually.
randomItem(value); // "lorem", eventually.

randomItem (function)

Parameters:

  • array ({ [index: number]: T; length: number; })
  • random (RandomFunction)

returns: null

randomItem (function)

Parameters:

  • array ({ [index: number]: T; length: number; })
  • random (RandomFunction)

returns: null

unique (function)

Returns a new array with unique values based on the by function.

Parameters:

  • array (T[])
  • by ((value: T) => unknown)

returns: T[]

{ from, fromAsync, isArray, of } (variable)

Package Sidebar

Install

npm i @ariesclark/array

Weekly Downloads

3

Version

0.3.1

License

MIT

Unpacked Size

9.81 kB

Total Files

14

Last publish

Collaborators

  • ariesclark