Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

args-to-arr

manferlo81238MIT1.4.9TypeScript support: included

converts arguments or any other array-like object into an array starting from specific index.

arguments, params, array, array-like, to-array, convert, rest, slice

readme

args-to-arr

CircleCI dependabot npm codecov jsDelivr dependencies dev dependencies packagephobia bundlephobia types Known Vulnerabilities license

Converts arguments or any other array-like object into an array starting from specific index.

Inspired by how Typescript handles ...rest arguments.

Install

npm i args-to-arr

CDN

jsDelivr

<script src="https://cdn.jsdelivr.net/npm/args-to-arr@latest/dist/args-to-arr.umd.js"></script>

for production

<script src="https://cdn.jsdelivr.net/npm/args-to-arr@latest/dist/args-to-arr.umd.min.js"></script>

more options...

unpkg

<script src="https://unpkg.com/args-to-arr@latest/dist/args-to-arr.umd.js"></script>

for production

<script src="https://unpkg.com/args-to-arr@latest/dist/args-to-arr.umd.min.js"></script>

more options...

Usage

Node.js

const toArray = require("args-to-arr");
const array = toArray(arrayLike, start);

Browser

After adding the script tag, toArray function will be available globally.

const array = toArray(arrayLike, start);

Reference

example

import toArray from "args-to-arr";

function anything(firstArg) {

  // convert arguments to array
  // starting from argument 1
  // it won't include firstArg
  const args = toArray(arguments, 1);

  // do something with the array

}

syntax

toArray<T>(arr: ArrayLike<T>, start: number = 0): T[];

return

type: Array

It returns a new array based on the provided parameters.

arr

type: Array | ArrayLike

Array or Array-like object to be converted to a new array.

start

type: number default: 0

Index number for array convertion to start from. If not provided or it equals null or undefined it will default to 0.

Providing a negative start index will cause the function to start iterating X items from the end of the array, see the following example.

example

const array = toArray([1, 2, 3, 4], -2);
console.log(array);
[ 3, 4 ]

If the provided negative start index exceeds the size of the array, it will fill the begining of the resulting array with empty values.

example

const array = toArray([1, 2], -4);
console.log(array);
[ <2 empty items>, 1, 2 ]

License

MIT © Manuel Fernández

changelog

args-to-arr changelog

Version History

1.4.9 (2020-06-11)

Bug Fixes

  • dependencies updated (vulnerabilities) (844c93f)

1.4.8 (2019-11-07)

1.4.7 (2019-09-14)

  • dependencies updated

1.4.6 (2019-08-29)

  • dependencies updated

1.4.5 (2019-07-07)

  • dependencies updated

1.4.4 (2019-07-01)

  • dependencies updated
  • ts-jest for typescript test
  • added husky

1.4.3 (2019-06-22)

  • dependencies updated

1.4.2 (2019-06-18)

  • fix: string support

1.4.1 (2019-06-18)

  • dependencies updated

1.4.0 (2019-06-18)

  • negative start point support
  • skip non-existent values
  • improved documentation

1.3.14 (2019-06-07)

  • dependencies updated

1.3.13 (2019-06-04)

  • improved documentation
  • test refactoring

1.3.12 (2019-06-01)

  • improved documentation

1.3.11 (2019-06-01)

  • description changed
  • dependencies updated

1.3.10 (2019-05-31)

  • fixed cdn links for latest version

1.3.9 (2019-05-30)

  • build a minified umd build
  • dependencies updated
  • improved changelog

1.3.8 (2019-05-30)

  • dependencies updated

1.3.7 (2019-05-29)

  • performance improvements

1.3.6 (2019-05-28)

  • improved changelog document

1.3.5 (2019-05-28)

  • improved documentation
  • added minified size badge

1.3.4 (2019-05-28)

  • dependencies updated
  • added install size badge
  • improved documentation

1.3.3 (2019-05-25)

  • test refactoring
  • improved documentation
  • added jsDelivr badge
  • added types badge

1.3.2 (2019-05-24)

  • dependencies updated
  • improved documentation

1.3.1 (2019-05-17)

  • dependencies updated

1.3.0 (2019-05-06)

  • browser support
  • dependencies updated
  • added badges
  • test refactoring

1.2.4 (2019-04-25)

  • dependencies updated

1.2.3 (2019-04-23)

  • improved documentation
  • switched to bundlib
  • tslint setup

1.2.2 (2019-04-23)

  • dependencies updated

1.2.1 (2019-04-23)

  • dependencies updated

1.2.0 (2019-04-22)

  • build using typescript
  • is-array-like type definitions

1.1.0 (2019-04-21)

  • using is-array-like
  • optimize output
  • test refactoring

1.0.1 (2019-04-18)

  • changelog documented

1.0.0 (2019-04-18)

  • first stable release

0.0.1 (2019-04-18)

  • preliminary release