Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jfrazx/asarray

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jfrazx/asarray

Ensures returned value is always an Array

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
increased by1050%
Maintainers
1
Weekly downloads
 
Created
Source

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


devDependencies Status Master Build Status codecov License

Install

npm install @jfrazx/asarray

or

yarn add @jfrazx/asarray

Usage

asArray<T, TResult>(data: T | T[], callback?: (value: T) => TResult): Array<T | TResult>
asArray<T extends Object, K extends keyof T>(data: T, extractObjectValues?: boolean, callback?: (key: K) => T[K]): Array<T | T[K]>
import { asArray } from '@jfrazx/asarray';

const person: Person = { name: 'Bart Simpson', age: 10 };

asArray('this string will be in an array');
// => ['this string will be in an array']

asArray([8, 6, 7, 5, 3, 0, 9]);
// => [8, 6, 7, 5, 3, 0, 9]

asArray(person);
// => [{ name: 'Bart Simpson', age: 10 }];

asArray(person, (object: T) => object.name);
// => ['Bart Simpson'];

asArray(person, true);
// => ['Bart Simpson', 10];

asArray(person, true, (key: K, object: T, index: number, array: K[]) => [k, o[k]]);
// => [['name', 'Bart Simpson'], ['age', 10]];

function things() {
  asArray(arguments);
  // => ['koalas', 'marsupial']
}

things('koalas', 'marsupial');

Keywords

FAQs

Package last updated on 02 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc