asArray
Ensure that the information you are working with is always an Array.
Optionally, you may pass a callback that will transform a single value,
or map key value pairs from an object
Install
npm install @jfrazx/asarray
or
yarn add @jfrazx/asarray
Usage
asArray<T, TResult>(data: T | T[], callback?: (value: T) => TResult): Array<T | TResult>
import { asArray } from '@jfrazx/asarray';
const person: Person = { name: 'Bart Simpson', age: 10 };
asArray('this string will be in an array');
asArray([8, 6, 7, 5, 3, 0, 9]);
asArray(person);
asArray(person, (object: T) => object.name);
asArray(person, true);
asArray(person, true, (key: K, object: T, index: number, array: K[]) => [k, o[k]]);
function things() {
asArray(arguments);
}
things('koalas', 'marsupial');