pull in and reflect changes from upstream/master
This commit is contained in:
parent
23caa33a5a
commit
00cfddcd32
2 changed files with 65 additions and 8 deletions
32
readme.md
32
readme.md
|
|
@ -78,12 +78,6 @@ Keep in mind that [functions are objects too](https://developer.mozilla.org/en-U
|
|||
|
||||
Returns `true` for any object with a `.then()` and `.catch()` method. Prefer this one over `.nativePromise()` as you usually want to allow userland promise implementations too.
|
||||
|
||||
##### .generator(value)
|
||||
|
||||
Returns `true` for any object that implements its own `.next()` and `.throw()` methods and has a function definition for `Symbol.iterator`.
|
||||
|
||||
##### .generatorFunction(value)
|
||||
|
||||
##### .map(value)
|
||||
##### .set(value)
|
||||
##### .weakMap(value)
|
||||
|
|
@ -127,6 +121,24 @@ Returns `true` for instances created by a ES2015 class.
|
|||
|
||||
##### .typedArray(value)
|
||||
|
||||
##### .inRange(value, range)
|
||||
|
||||
Check if `value` (number) is in the given `range`. The range is an array of two values, lower bound and upper bound, in no specific order.
|
||||
|
||||
```js
|
||||
is.inRange(3, [0, 5]);
|
||||
is.inRange(3, [5, 0]);
|
||||
is.inRange(0, [-2, 2]);
|
||||
```
|
||||
|
||||
##### .inRange(value, upperBound)
|
||||
|
||||
Check if `value` (number) is in the range of `0` to `upperBound`.
|
||||
|
||||
```js
|
||||
is.inRange(3, 10);
|
||||
```
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
|
|
@ -157,6 +169,12 @@ The most common mistakes I noticed in these modules was using `instanceof` for t
|
|||
- [is-empty-iterable](https://github.com/sindresorhus/is-empty-iterable) - Check if an Iterable is empty
|
||||
|
||||
|
||||
## Created by
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Giora Guttsait](https://github.com/gioragutt)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
MIT
|
||||
|
|
|
|||
41
test.js
41
test.js
|
|
@ -10,7 +10,11 @@ const ErrorSubclassFixture = class extends Error {};
|
|||
const types = new Map([
|
||||
['undefined', undefined],
|
||||
['null', null],
|
||||
['string', '🦄'],
|
||||
['string', [
|
||||
'🦄',
|
||||
'hello world',
|
||||
''
|
||||
]],
|
||||
['number', [
|
||||
6,
|
||||
1.4,
|
||||
|
|
@ -319,3 +323,38 @@ test('is.typedArray', t => {
|
|||
t.false(m.typedArray([]));
|
||||
t.false(m.typedArray({}));
|
||||
});
|
||||
|
||||
test('is.inRange', t => {
|
||||
const x = 3;
|
||||
|
||||
t.true(m.inRange(x, [0, 5]));
|
||||
t.true(m.inRange(x, [5, 0]));
|
||||
t.true(m.inRange(x, [-5, 5]));
|
||||
t.true(m.inRange(x, [5, -5]));
|
||||
t.false(m.inRange(x, [4, 8]));
|
||||
t.true(m.inRange(-7, [-5, -10]));
|
||||
t.true(m.inRange(-5, [-5, -10]));
|
||||
t.true(m.inRange(-10, [-5, -10]));
|
||||
|
||||
t.true(m.inRange(x, 10));
|
||||
t.true(m.inRange(0, 0));
|
||||
t.true(m.inRange(-2, -3));
|
||||
t.false(m.inRange(x, 2));
|
||||
t.false(m.inRange(-3, -2));
|
||||
|
||||
t.throws(() => {
|
||||
m.inRange(0);
|
||||
});
|
||||
|
||||
t.throws(() => {
|
||||
m.inRange(0, []);
|
||||
});
|
||||
|
||||
t.throws(() => {
|
||||
m.inRange(0, [5]);
|
||||
});
|
||||
|
||||
t.throws(() => {
|
||||
m.inRange(0, [1, 2, 3]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue