Skip to content

Commit

Permalink
Forgot to update the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 16, 2019
1 parent d5eb538 commit 51eb372
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function * ({start = 0, end, step = 1}) {
}

validate('start', start);
validate('stop', end);
validate('end', end);
validate('step', step);

for (let i = start; i < end; i += step) {
Expand Down
25 changes: 14 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ $ npm install get-range
```js
const getRange = require('get-range');

for (const index of getRange(4)) {
for (const index of getRange({end: 4})) {
console.log(index);
}
//=> 0
//=> 1
//=> 2
//=> 3

const range = getRange(0, 4, 2);
const range = getRange({start: 0, end: 4, step: 2});
range.next().value;
//=> 0
range.next().value;
//=> 2

console.log(...getRange(0, -5, -1));
console.log(...getRange({start: 0, end: -5, step: -1}));
//=> [0, -1, -2, -3, -4]
```

Expand All @@ -44,31 +44,34 @@ Can replace for-loops in many cases:
for (let i = 0; i < 5; i++) {}

// After
for (const i of getRange(5)) {}
for (const i of getRange({end: 5})) {}
```


## API

### getRange(stop)
### getRange(start, stop, [step])
### getRange(range)

Returns a [`Generator` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) *(which is both an `Iterable` and `Iterator`)*.

#### start
#### range

Type: `Object`

##### start

Type: `integer`<br>
Default: `0`

Start from this number.
Start of the range.

#### stop
##### end

Type: `integer`

Stop after this many numbers.
End of the range.

#### step
##### step

Type: `integer`<br>
Default: `1`<br>
Expand Down

0 comments on commit 51eb372

Please sign in to comment.