Comparing version 3.9.0 to 3.10.0
@@ -1109,2 +1109,18 @@ 'use strict'; | ||
/** | ||
* Create a validator that checks that the tested object contains at least one | ||
* of the specified keys. | ||
*/ | ||
function hasAtLeastOneKey(requiredKeys) { | ||
const requiredSet = new Set(requiredKeys); | ||
return makeValidator({ | ||
test: (value, state) => { | ||
const keys = Object.keys(value); | ||
const valid = keys.some(key => requiredSet.has(key)); | ||
if (!valid) | ||
return pushError(state, `Missing at least one property from ${getPrintableArray(Array.from(requiredSet), `or`)}`); | ||
return true; | ||
}, | ||
}); | ||
} | ||
/** | ||
* Create a validator that checks that the tested object contains none of the | ||
@@ -1195,2 +1211,3 @@ * specified keys. | ||
exports.fn = fn; | ||
exports.hasAtLeastOneKey = hasAtLeastOneKey; | ||
exports.hasExactLength = hasExactLength; | ||
@@ -1197,0 +1214,0 @@ exports.hasForbiddenKeys = hasForbiddenKeys; |
@@ -34,2 +34,7 @@ import { AnyStrictValidator, InferType, LooseTest, StrictTest, StrictValidator } from '../types'; | ||
/** | ||
* Create a validator that checks that the tested object contains at least one | ||
* of the specified keys. | ||
*/ | ||
export declare function hasAtLeastOneKey(requiredKeys: string[]): import("../types").LooseValidator<Record<string, unknown>, Record<string, unknown>>; | ||
/** | ||
* Create a validator that checks that the tested object contains none of the | ||
@@ -36,0 +41,0 @@ * specified keys. |
{ | ||
"name": "typanion", | ||
"version": "3.9.0", | ||
"version": "3.10.0", | ||
"main": "lib/index", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
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
126590
2955