@sindresorhus/is
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -124,3 +124,3 @@ /// <reference types="node" /> | ||
var nonEmptyMap: <Key = unknown, Value = unknown>(value: unknown) => value is Map<Key, Value>; | ||
var any: (predicate: Predicate, ...values: unknown[]) => boolean; | ||
var any: (predicate: Predicate | Predicate[], ...values: unknown[]) => boolean; | ||
var all: (predicate: Predicate, ...values: unknown[]) => boolean; | ||
@@ -258,3 +258,3 @@ } | ||
inRange: (value: number, range: number | number[]) => asserts value is number; | ||
any: (predicate: Predicate, ...values: unknown[]) => void | never; | ||
any: (predicate: Predicate | Predicate[], ...values: unknown[]) => void | never; | ||
all: (predicate: Predicate, ...values: unknown[]) => void | never; | ||
@@ -261,0 +261,0 @@ } |
@@ -232,3 +232,6 @@ "use strict"; | ||
}; | ||
is.any = (predicate, ...values) => predicateOnArray(Array.prototype.some, predicate, values); | ||
is.any = (predicate, ...values) => { | ||
const predicates = is.array(predicate) ? predicate : [predicate]; | ||
return predicates.some(singlePredicate => predicateOnArray(Array.prototype.some, singlePredicate, values)); | ||
}; | ||
is.all = (predicate, ...values) => predicateOnArray(Array.prototype.every, predicate, values); | ||
@@ -235,0 +238,0 @@ const assertType = (condition, description, value) => { |
{ | ||
"name": "@sindresorhus/is", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Type check values", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -423,5 +423,5 @@ # is [![Build Status](https://travis-ci.org/sindresorhus/is.svg?branch=master)](https://travis-ci.org/sindresorhus/is) | ||
##### .any(predicate, ...values) | ||
##### .any(predicate | predicate[], ...values) | ||
Returns `true` if **any** of the input `values` returns true in the `predicate`: | ||
Using a single `predicate` argument, returns `true` if **any** of the input `values` returns true in the `predicate`: | ||
@@ -436,2 +436,12 @@ ```js | ||
Using an array of `predicate[]`, returns `true` if **any** of the input `values` returns true for **any** of the `predicates` provided in an array: | ||
```js | ||
is.any([is.string, is.number], {}, true, '🦄'); | ||
//=> true | ||
is.any([is.boolean, is.number], 'unicorns', [], new Map()); | ||
//=> false | ||
``` | ||
##### .all(predicate, ...values) | ||
@@ -514,25 +524,25 @@ | ||
async function badNumberAssumption(input: unknown) { | ||
// Bad assumption about the generic type parameter fools the compile-time type system. | ||
assert.promise<number>(input); | ||
// `input` is a `Promise` but only assumed to be `Promise<number>`. | ||
// Bad assumption about the generic type parameter fools the compile-time type system. | ||
assert.promise<number>(input); | ||
// `input` is a `Promise` but only assumed to be `Promise<number>`. | ||
const resolved = await input; | ||
// `resolved` is typed as `number` but was not actually checked at runtime. | ||
const resolved = await input; | ||
// `resolved` is typed as `number` but was not actually checked at runtime. | ||
// Multiplication will return NaN if the input promise did not actually contain a number. | ||
return 2 * resolved; | ||
// Multiplication will return NaN if the input promise did not actually contain a number. | ||
return 2 * resolved; | ||
} | ||
async function goodNumberAssertion(input: unknown) { | ||
assert.promise(input); | ||
// `input` is typed as `Promise<unknown>` | ||
assert.promise(input); | ||
// `input` is typed as `Promise<unknown>` | ||
const resolved = await input; | ||
// `resolved` is typed as `unknown` | ||
const resolved = await input; | ||
// `resolved` is typed as `unknown` | ||
assert.number(resolved); | ||
// `resolved` is typed as `number` | ||
assert.number(resolved); | ||
// `resolved` is typed as `number` | ||
// Uses runtime checks so only numbers will reach the multiplication. | ||
return 2 * resolved; | ||
// Uses runtime checks so only numbers will reach the multiplication. | ||
return 2 * resolved; | ||
} | ||
@@ -539,0 +549,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
52063
617
595