@toolz/allow
Advanced tools
Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "@toolz/allow", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Provides validation of data types", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import { isARegularObject } from '@toolz/is-a-regular-object'; | ||
export const failureBehavior = { | ||
IGNORE: 'ignore', | ||
THROW: 'throw', | ||
WARN: 'warn', | ||
}; | ||
const Allow = () => { | ||
let allowNull = false; | ||
let failureBehavior = 'throw'; | ||
const failureBehaviorOptions = { | ||
ignore: 'ignore', | ||
throw: 'throw', | ||
warn: 'warn', | ||
}; | ||
let currentFailureBehavior = failureBehavior.THROW; | ||
let onFailure = () => { | ||
@@ -167,5 +168,5 @@ // | ||
onFailure(value, message); | ||
if (failureBehavior === 'ignore') | ||
if (currentFailureBehavior === 'ignore') | ||
return allow; | ||
if (failureBehavior === 'warn') { | ||
if (currentFailureBehavior === 'warn') { | ||
console.warn(value); | ||
@@ -181,3 +182,3 @@ console.warn(`[${value.toString()}] ${message}`); | ||
const getFailureBehavior = () => failureBehavior; | ||
const getFailureBehavior = () => currentFailureBehavior; | ||
@@ -216,4 +217,4 @@ const getOnFailure = () => onFailure; | ||
const setFailureBehavior = behavior => { | ||
oneOf(behavior, failureBehaviorOptions); | ||
failureBehavior = behavior; | ||
oneOf(behavior, failureBehavior); | ||
currentFailureBehavior = behavior; | ||
}; | ||
@@ -245,3 +246,2 @@ | ||
fail, | ||
failureBehaviorOptions, | ||
getAllowNull, | ||
@@ -248,0 +248,0 @@ getFailureBehavior, |
82938
1138