@sindresorhus/is
Advanced tools
Comparing version 5.5.2 to 5.6.0
@@ -75,2 +75,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
var arrayLike: <T = unknown>(value: unknown) => value is ArrayLike<T>; | ||
var tupleLike: <T extends TypeGuard<unknown>[]>(value: unknown, guards: [...T]) => value is ResolveTypesOfTypeGuardsTuple<T, []>; | ||
var inRange: (value: number, range: number | number[]) => value is number; | ||
@@ -105,2 +106,4 @@ var domElement: (value: unknown) => value is HTMLElement; | ||
}; | ||
type TypeGuard<T> = (value: unknown) => value is T; | ||
type ResolveTypesOfTypeGuardsTuple<TypeGuardsOfT, ResultOfT extends unknown[] = []> = TypeGuardsOfT extends [TypeGuard<infer U>, ...infer TOthers] ? ResolveTypesOfTypeGuardsTuple<TOthers, [...ResultOfT, U]> : TypeGuardsOfT extends undefined[] ? ResultOfT : never; | ||
export type NodeStream = { | ||
@@ -128,2 +131,3 @@ pipe<T extends NodeJS.WritableStream>(destination: T, options?: { | ||
arrayLike = "array-like", | ||
tupleLike = "tuple-like", | ||
typedArray = "TypedArray", | ||
@@ -216,2 +220,3 @@ domElement = "HTMLElement", | ||
arrayLike: <T = unknown>(value: unknown) => asserts value is ArrayLike<T>; | ||
tupleLike: <T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T]) => asserts value is ResolveTypesOfTypeGuardsTuple<T>; | ||
domElement: (value: unknown) => asserts value is HTMLElement; | ||
@@ -218,0 +223,0 @@ observable: (value: unknown) => asserts value is ObservableLike; |
@@ -226,2 +226,8 @@ const typedArrayTypeNames = [ | ||
is.arrayLike = (value) => !is.nullOrUndefined(value) && !is.function_(value) && isValidLength(value.length); | ||
is.tupleLike = (value, guards) => { | ||
if (is.array(guards) && is.array(value) && guards.length === value.length) { | ||
return guards.every((guard, index) => guard(value[index])); | ||
} | ||
return false; | ||
}; | ||
is.inRange = (value, range) => { | ||
@@ -394,2 +400,3 @@ if (is.number(range)) { | ||
arrayLike: (value) => assertType(is.arrayLike(value), "array-like" /* AssertionTypeDescription.arrayLike */, value), | ||
tupleLike: (value, guards) => assertType(is.tupleLike(value, guards), "tuple-like" /* AssertionTypeDescription.tupleLike */, value), | ||
domElement: (value) => assertType(is.domElement(value), "HTMLElement" /* AssertionTypeDescription.domElement */, value), | ||
@@ -396,0 +403,0 @@ observable: (value) => assertType(is.observable(value), 'Observable', value), |
{ | ||
"name": "@sindresorhus/is", | ||
"version": "5.5.2", | ||
"version": "5.6.0", | ||
"description": "Type check values", | ||
@@ -64,3 +64,4 @@ "license": "MIT", | ||
"xo": "^0.54.2", | ||
"zen-observable": "^0.10.0" | ||
"zen-observable": "^0.10.0", | ||
"expect-type": "^0.16.0" | ||
}, | ||
@@ -67,0 +68,0 @@ "sideEffects": false, |
@@ -413,2 +413,22 @@ # is | ||
##### .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) | ||
@@ -415,0 +435,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61258
736
699
14