1.0.6 • Published 4 years ago

provoke-array v1.0.6

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

provoke-array generates an array for you

Installation

npm install provoke-array

or

yarn add provoke-array

provokeArray((length: Number), (customReturn: Function));

Examples

Basic

By default it returns an array with 3 positions containing empty objects (this is helpful in tests to use mocked data).

import provokeArray from "provoke-array";

provokeArray();

// Result:
// [{}, {}, {}]

Custom return

You can customize what it returns by passing a function as 2nd argument.

import provokeArray from "provoke-array";

provokeArray(2, (i) => ({
  id: i,
  name: `Name: ${i}`
}));

// Result:
// [
//     {
//         id: 0,
//         name: 'Name: 0'
//     },
//     {
//         id: 1,
//         name: 'Name: 1'
//     }
// ]

Use with faker

You can use it with faker to generate more custom data.

import provokeArray from "provoke-array";
import faker from "faker";

provokeArray(2, i => ({
  id: i,
  name: faker.name.firstName()
}));

// Result:
// [
//     {
//         id: 0,
//         name: 'John'
//     },
//     {
//         id: 1,
//         name: 'Alice'
//     }
// ]
1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago