Comparing version 0.24.1 to 0.25.0
@@ -8,3 +8,3 @@ import { Predicate } from './predicates/predicate'; | ||
*/ | ||
export declare type Main = <T>(value: T, label: string | Function, predicate: BasePredicate<T>) => void; | ||
export declare type Main = <T>(value: T, label: string | Function, predicate: BasePredicate<T>, idLabel?: boolean) => void; | ||
export interface Ow extends Modifiers, Predicates { | ||
@@ -11,0 +11,0 @@ /** |
@@ -11,3 +11,3 @@ import { BasePredicate, testSymbol } from './base-predicate'; | ||
constructor(predicates: BasePredicate[], options?: PredicateOptions); | ||
[testSymbol](value: T, main: Main, label: string | Function): asserts value; | ||
[testSymbol](value: T, main: Main, label: string | Function, idLabel: boolean): asserts value; | ||
} |
@@ -25,7 +25,7 @@ "use strict"; | ||
} | ||
[base_predicate_1.testSymbol](value, main, label) { | ||
[base_predicate_1.testSymbol](value, main, label, idLabel) { | ||
const errors = new Map(); | ||
for (const predicate of this.predicates) { | ||
try { | ||
main(value, label, predicate); | ||
main(value, label, predicate, idLabel); | ||
return; | ||
@@ -32,0 +32,0 @@ } |
@@ -14,3 +14,3 @@ import { Main } from '..'; | ||
export interface BasePredicate<T = unknown> { | ||
[testSymbol](value: T, main: Main, label: string | Function): void; | ||
[testSymbol](value: T, main: Main, label: string | Function, idLabel?: boolean): void; | ||
} |
@@ -54,3 +54,3 @@ "use strict"; | ||
message: (_, label, error) => `(${label}) ${error}`, | ||
validator: object => of_type_1.default(Object.values(object), predicate) | ||
validator: object => of_type_1.default(Object.values(object), predicate, 'values') | ||
}); | ||
@@ -57,0 +57,0 @@ } |
@@ -62,3 +62,3 @@ import { BasePredicate, testSymbol } from './base-predicate'; | ||
*/ | ||
[testSymbol](value: T, main: Main, label: string | Function): asserts value is T; | ||
[testSymbol](value: T, main: Main, label: string | Function, idLabel: boolean): asserts value is T; | ||
/** | ||
@@ -65,0 +65,0 @@ @hidden |
@@ -56,3 +56,3 @@ "use strict"; | ||
*/ | ||
[base_predicate_1.testSymbol](value, main, label) { | ||
[base_predicate_1.testSymbol](value, main, label, idLabel) { | ||
// Create a map of labels -> received errors. | ||
@@ -76,4 +76,5 @@ const errors = new Map(); | ||
const label2 = is_1.default.function_(label) ? label() : label; | ||
const label_ = label2 ? | ||
`${this.type} \`${label2}\`` : | ||
const labelWithTick = (label2 && idLabel) ? `\`${label2}\`` : label2; | ||
const label_ = labelWithTick ? | ||
`${this.type} ${labelWithTick}` : | ||
this.type; | ||
@@ -80,0 +81,0 @@ const mapKey = label2 || this.type; |
@@ -10,3 +10,4 @@ import { BasePredicate } from './predicates/base-predicate'; | ||
@param predicate - Predicate to test to value against. | ||
@param idLabel - If true, the label is a variable or type. Default: true. | ||
*/ | ||
export default function test<T>(value: T, label: string | Function, predicate: BasePredicate<T>): void; | ||
export default function test<T>(value: T, label: string | Function, predicate: BasePredicate<T>, idLabel?: boolean): void; |
@@ -12,6 +12,7 @@ "use strict"; | ||
@param predicate - Predicate to test to value against. | ||
@param idLabel - If true, the label is a variable or type. Default: true. | ||
*/ | ||
function test(value, label, predicate) { | ||
predicate[base_predicate_1.testSymbol](value, test, label); | ||
function test(value, label, predicate, idLabel = true) { | ||
predicate[base_predicate_1.testSymbol](value, test, label, idLabel); | ||
} | ||
exports.default = test; |
import { BasePredicate } from '../predicates/base-predicate'; | ||
declare const _default: <T>(source: IterableIterator<T> | Set<T> | T[], predicate: BasePredicate<T>) => boolean | string; | ||
declare const _default: <T>(source: IterableIterator<T> | Set<T> | T[], predicate: BasePredicate<T>, name?: string | undefined) => boolean | string; | ||
/** | ||
@@ -9,3 +9,4 @@ Test all the values in the collection against a provided predicate. | ||
@param predicate Predicate to test every item in the source collection against. | ||
@param name The name to call the collection of values, such as `values` or `keys`. If it is `undefined`, it uses the call stack to infer the label. | ||
*/ | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
const test_1 = require("../test"); | ||
// TODO: After we migrate all usages of this function to specify the optional 'name' parameter, we can change the parameter to be required. | ||
/** | ||
@@ -10,7 +12,13 @@ Test all the values in the collection against a provided predicate. | ||
@param predicate Predicate to test every item in the source collection against. | ||
@param name The name to call the collection of values, such as `values` or `keys`. If it is `undefined`, it uses the call stack to infer the label. | ||
*/ | ||
exports.default = (source, predicate) => { | ||
exports.default = (source, predicate, name) => { | ||
try { | ||
for (const item of source) { | ||
__1.default(item, predicate); | ||
if (name) { | ||
test_1.default(item, name, predicate, false); | ||
} | ||
else { | ||
__1.default(item, predicate); | ||
} | ||
} | ||
@@ -17,0 +25,0 @@ return true; |
{ | ||
"name": "ow", | ||
"version": "0.24.1", | ||
"version": "0.25.0", | ||
"description": "Function argument validation for humans", | ||
@@ -22,3 +22,3 @@ "license": "MIT", | ||
"prepare": "npm run build", | ||
"// postpublish": "npm run docs && gh-pages --dist docs --no-history --message \"Deploy documentation\"", | ||
"postpublish": "npm run docs && gh-pages --dist docs --no-history --message \"Deploy documentation\"", | ||
"example": "npm run build && node example.js" | ||
@@ -51,7 +51,7 @@ }, | ||
"dependencies": { | ||
"@sindresorhus/is": "^4.0.0", | ||
"@sindresorhus/is": "^4.0.1", | ||
"callsites": "^3.1.0", | ||
"dot-prop": "^6.0.1", | ||
"lodash.isequal": "^4.5.0", | ||
"type-fest": "^1.2.0", | ||
"type-fest": "^1.2.1", | ||
"vali-date": "^1.0.0" | ||
@@ -62,11 +62,11 @@ }, | ||
"@types/lodash.isequal": "^4.5.5", | ||
"@types/node": "^15.6.2", | ||
"@types/node": "^15.12.4", | ||
"@types/vali-date": "^1.0.0", | ||
"ava": "^2.4.0", | ||
"del-cli": "^3.0.1", | ||
"del-cli": "^4.0.0", | ||
"expect-type": "^0.11.0", | ||
"gh-pages": "^3.2.0", | ||
"gh-pages": "^3.2.3", | ||
"nyc": "^15.1.0", | ||
"ts-node": "^10.0.0", | ||
"typescript": "^4.3.2", | ||
"typescript": "^4.3.4", | ||
"xo": "^0.38.2" | ||
@@ -73,0 +73,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
135253
3310
Updated@sindresorhus/is@^4.0.1
Updatedtype-fest@^1.2.1