@toolz/allow
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "@toolz/allow", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Provides validation of data types", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# allow | ||
`allow` | ||
is a library that checks data types and _allows_ the script to continue if they pass the check. If the check fails, the script can throw an `Error`or just a warning. The package was written to ensure that only the "right" kind of data is allowed into the body of a function / method / component / etc. The intention is to provide effective _runtime_ validation of data before it reaches application logic. | ||
is a library that checks data types and _allows_ the script to continue if they pass the check. If the check fails, the script can throw an `Error`, or emit a warning, or invoke a custom callback. The package was written to ensure that only the "right" kind of data is allowed into the body of a function / method / component / etc. The intention is to provide effective _runtime_ validation of data before it reaches application logic. | ||
@@ -17,3 +17,3 @@ ## Usage | ||
```javascript | ||
const addSalesTax = (originalPrice) => { | ||
const addSalesTax = originalPrice => { | ||
allow.aNumber(originalPrice, 0); | ||
@@ -33,7 +33,9 @@ /* | ||
```javascript | ||
// example: | ||
const doSomething = (reallyDoIt) => { | ||
const doSomething = reallyDoIt => { | ||
allow.aBoolean(reallyDoIt); | ||
/* | ||
This is NOT "truthy". It fails if anything other than a true Boolean is provided. This means that it fails on 'TRUE'/'FALSE' (because they're strings), on 1/0 (because they're numbers), or any other value that is not a pure TRUE/FALSE | ||
This is NOT "truthy". It fails if anything other than a true Boolean is | ||
provided. This means that it fails on 'TRUE'/'FALSE' (because they're | ||
strings), on 1/0 (because they're numbers), or any other value that is not | ||
a pure TRUE/FALSE | ||
...proceed with the rest of the function | ||
@@ -43,1 +45,49 @@ */ | ||
``` | ||
### aFunction | ||
```javascript | ||
const doSomething = callback => { | ||
allow.aFunction(callback); | ||
/* | ||
This will fail unless a function is provided as the value for callback | ||
...proceed with the rest of the function | ||
*/ | ||
} | ||
``` | ||
### anArray | ||
```javascript | ||
const doSomething = theValues => { | ||
allow.anArray(theValues); | ||
/* | ||
This will fail unless an array is provided as the value for theValues. | ||
In this example, theValues can be an empty array - but it must still be | ||
an array. | ||
...proceed with the rest of the function | ||
*/ | ||
} | ||
``` | ||
```javascript | ||
const doSomething = theValues => { | ||
allow.anArray(theValues, 0); | ||
/* | ||
The second argument of anArray() is the minimum length of the array. So, | ||
by setting this value to 0, it ensures that theValues is a non-empty array. | ||
...proceed with the rest of the function | ||
*/ | ||
} | ||
``` | ||
```javascript | ||
const doSomething = theValues => { | ||
allow.anArray(theValues, 2, 50); | ||
/* | ||
This ensures that theValues is an array, that is has no fewer than 2 | ||
elements, and no more than 50 elements. | ||
...proceed with the rest of the function | ||
*/ | ||
} | ||
``` |
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
12952
91