Add .tupleLike() (#189)

Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
This commit is contained in:
Tal Michel 2023-07-23 15:35:23 +03:00 committed by GitHub
parent 94dc715577
commit 3868f47783
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 119 additions and 1 deletions

View file

@ -410,6 +410,26 @@ function foo() {
foo();
```
##### .tupleLike(value, guards)
A `value` is tuple-like if it matches the provided `guards` array both in `.length` and in types.
```js
is.tupleLike([1], [is.number]);
//=> true
```
```js
function foo() {
const tuple = [1, '2', true];
if (is.tupleLike(tuple, [is.number, is.string, is.boolean])) {
tuple // [number, string, boolean]
}
}
foo();
```
#### .positiveNumber(value)
Check if `value` is a number and is more than 0.