@sindresorhus/is
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -203,3 +203,3 @@ "use strict"; | ||
is.plainObject = (value) => { | ||
// From: https://github.com/sindresorhus/is-plain-obj/blob/master/index.js | ||
// From: https://github.com/sindresorhus/is-plain-obj/blob/main/index.js | ||
if (toString.call(value) !== '[object Object]') { | ||
@@ -286,5 +286,11 @@ return false; | ||
is.all = (predicate, ...values) => predicateOnArray(Array.prototype.every, predicate, values); | ||
const assertType = (condition, description, value) => { | ||
const assertType = (condition, description, value, options = {}) => { | ||
if (!condition) { | ||
throw new TypeError(`Expected value which is \`${description}\`, received value of type \`${is(value)}\`.`); | ||
const { multipleValues } = options; | ||
const valuesMessage = multipleValues ? | ||
`received values of types ${[ | ||
...new Set(value.map(singleValue => `\`${is(singleValue)}\``)) | ||
].join(', ')}` : | ||
`received value of type \`${is(value)}\``; | ||
throw new TypeError(`Expected value which is \`${description}\`, ${valuesMessage}.`); | ||
} | ||
@@ -381,4 +387,6 @@ }; | ||
// Variadic functions. | ||
any: (predicate, ...values) => assertType(is.any(predicate, ...values), "predicate returns truthy for any value" /* any */, values), | ||
all: (predicate, ...values) => assertType(is.all(predicate, ...values), "predicate returns truthy for all values" /* all */, values) | ||
any: (predicate, ...values) => { | ||
return assertType(is.any(predicate, ...values), "predicate returns truthy for any value" /* any */, values, { multipleValues: true }); | ||
}, | ||
all: (predicate, ...values) => assertType(is.all(predicate, ...values), "predicate returns truthy for all values" /* all */, values, { multipleValues: true }) | ||
}; | ||
@@ -385,0 +393,0 @@ // Some few keywords are reserved, but we'll populate them for Node.js users |
{ | ||
"name": "@sindresorhus/is", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Type check values", | ||
@@ -20,3 +20,3 @@ "license": "MIT", | ||
"test": "xo && ava", | ||
"prepublishOnly": "npm run build" | ||
"prepare": "npm run build" | ||
}, | ||
@@ -23,0 +23,0 @@ "files": [ |
@@ -1,2 +0,2 @@ | ||
# is [![Build Status](https://travis-ci.org/sindresorhus/is.svg?branch=master)](https://travis-ci.org/sindresorhus/is) | ||
# is | ||
@@ -3,0 +3,0 @@ > Type check values |
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
53326
666