@toolz/allow
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "@toolz/allow", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Provides validation of data types", | ||
@@ -58,5 +58,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@toolz/is-a-regular-object": "^1.0.1", | ||
"@toolz/local-storage": "^1.0.2" | ||
"@toolz/is-a-regular-object": "^1.0.1" | ||
} | ||
} |
import { isARegularObject } from '@toolz/is-a-regular-object'; | ||
import { local } from '@toolz/local-storage'; | ||
const localStorageIsSupported = () => { | ||
try { | ||
const testKey = '__some_random_key_you_are_not_going_to_use__'; | ||
localStorage.setItem(testKey, testKey); | ||
localStorage.removeItem(testKey); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
const Allow = () => { | ||
let allowNull = local.getItem('allow.allowNull', false); | ||
let allowNull; | ||
let currentFailureBehavior; | ||
const failureBehavior = { | ||
@@ -11,3 +22,10 @@ IGNORE: 'ignore', | ||
}; | ||
let currentFailureBehavior = local.getItem('allow.failureBehavior', failureBehavior.THROW); | ||
if (localStorageIsSupported()) { | ||
const savedAllowNull = localStorage.getItem('allow.allowNull'); | ||
allowNull = savedAllowNull === 'true'; | ||
currentFailureBehavior = localStorage.getItem('allow.failureBehavior') || failureBehavior.THROW; | ||
} else { | ||
allowNull = false; | ||
currentFailureBehavior = failureBehavior.THROW; | ||
} | ||
let onFailure = () => { | ||
@@ -212,3 +230,5 @@ // | ||
aBoolean(newAllowNull); | ||
allowNull = local.setItem('allow.allowNull', newAllowNull); | ||
if (localStorageIsSupported()) | ||
localStorage.setItem('allow.allowNull', newAllowNull.toString()); | ||
allowNull = newAllowNull; | ||
}; | ||
@@ -218,3 +238,5 @@ | ||
oneOf(behavior, failureBehavior); | ||
currentFailureBehavior = local.setItem('allow.failureBehavior', behavior); | ||
if (localStorageIsSupported()) | ||
localStorage.setItem('allow.failureBehavior', behavior); | ||
currentFailureBehavior = behavior; | ||
}; | ||
@@ -221,0 +243,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
84107
1
1161
- Removed@toolz/local-storage@^1.0.2
- Removed@toolz/allow@1.1.5(transitive)
- Removed@toolz/local-storage@1.0.5(transitive)
- Removed@toolz/local-storage-is-available@1.0.0(transitive)
- Removed@toolz/session-storage-is-available@1.0.0(transitive)