Comparing version 3.10.0 to 3.11.0
@@ -1143,2 +1143,8 @@ 'use strict'; | ||
} | ||
const checks = { | ||
missing: (keys, key) => keys.has(key), | ||
undefined: (keys, key, value) => keys.has(key) && typeof value[key] !== `undefined`, | ||
nil: (keys, key, value) => keys.has(key) && value[key] != null, | ||
falsy: (keys, key, value) => keys.has(key) && !!value[key], | ||
}; | ||
/** | ||
@@ -1148,4 +1154,6 @@ * Create a validator that checks that the tested object contains at most one | ||
*/ | ||
function hasMutuallyExclusiveKeys(exclusiveKeys) { | ||
function hasMutuallyExclusiveKeys(exclusiveKeys, options) { | ||
var _a; | ||
const exclusiveSet = new Set(exclusiveKeys); | ||
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : 'missing']; | ||
return makeValidator({ | ||
@@ -1156,3 +1164,3 @@ test: (value, state) => { | ||
for (const key of exclusiveSet) | ||
if (keys.has(key)) | ||
if (check(keys, key, value)) | ||
used.push(key); | ||
@@ -1159,0 +1167,0 @@ if (used.length > 1) |
@@ -47,2 +47,3 @@ import { AnyStrictValidator, InferType, LooseTest, StrictTest, StrictValidator } from '../types'; | ||
}>; | ||
export declare type MissingType = 'missing' | 'undefined' | 'nil' | 'falsy'; | ||
/** | ||
@@ -52,3 +53,5 @@ * Create a validator that checks that the tested object contains at most one | ||
*/ | ||
export declare function hasMutuallyExclusiveKeys(exclusiveKeys: string[]): import("../types").LooseValidator<{ | ||
export declare function hasMutuallyExclusiveKeys(exclusiveKeys: string[], options?: { | ||
missingIf: MissingType; | ||
}): import("../types").LooseValidator<{ | ||
[key: string]: unknown; | ||
@@ -55,0 +58,0 @@ }, { |
{ | ||
"name": "typanion", | ||
"version": "3.10.0", | ||
"version": "3.11.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
127630
2974