Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bramus/js-range
https://github.com/bramus/js-range
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bramus/js-range
- Owner: bramus
- License: mit
- Created: 2021-12-05T21:59:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-17T23:01:17.000Z (about 3 years ago)
- Last Synced: 2024-11-04T20:05:39.013Z (about 2 months ago)
- Language: JavaScript
- Size: 73.2 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Range
Create an array containing a range of elements _(cfr. PHP's range)_
## Installation
```bash
npm i @bramus/range
```## Usage / Example
```js
import { range } from '@bramus/range';const r1 = range(0, 12);
// ~> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]const r2 = range(7, 12);
// ~> [7, 8, 9, 10, 11, 12]const r3 = range(0, 100, 10);
// ~> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
```🔗 Try it out online in the playground: [https://codepen.io/bramus/pen/dyVMPxV](https://codepen.io/bramus/pen/dyVMPxV)
## API
The exposed function has an API identical to [PHP's `range`](https://php.net/range) method:
```js
range(start, end, step = 1);
```Parameters:
- `start`: First value of the sequence.
- `end`: The sequence is ended upon reaching the `end` value.
- `step` _(default: 1)_: If a `step` value is given, it will be used as the increment between elements in the sequence. `step` should be given as a positive number. If not specified, step will default to `1`.## Limitations
Unlike PHP's `range`, this function is limited to numbers only. In case you do want to get letters, combine `range()` with `Array.map()`.
## License
`@bramus/range` is released under the MIT public license. See the enclosed `LICENSE` for details.