0.0.20 • Published 2 years ago
@0bdx/ainta v0.0.20
@0bdx/ainta
Utilities for validating values in apps, libraries and websites.
∅ Version: 0.0.20
∅ NPM: https://www.npmjs.com/package/@0bdx/ainta
∅ Repo: https://github.com/0bdx/ainta
∅ Homepage: https://0bdx.com/ainta
@TODO add an overview
Examples
Basic usage:
import { aintaBoolean } from '@0bdx/ainta';
aintaBoolean(true);
// false
aintaBoolean(1234);
// "A value is type 'number' not 'boolean'"
aintaBoolean(null, 'isDone', { begin:'doThings()' });
// "doThings(): `isDone` is null not type 'boolean'"Using the narrowAintas() helper:
In the example below, narrowAintas() is used to narrow aintaNumber()
into aintaNatural(), and then capture its validation results:
begin:'bothNatural()'sets a prefix, added to all explanationsgte:0checks that the value is not negativemod:1checks that the value is an integerlte:1000andlte:50specify different maximum values for each argumentif (results.length)checks whether there were any problems
import narrowAintas, { aintaNumber } from '@0bdx/ainta';
function bothNatural(a, b) {
const [ results, aintaNatural ] = narrowAintas(
{ begin:'bothNatural()', gte:0, mod:1 },
aintaNumber
);
aintaNatural(a, 'a', { lte:1000 });
aintaNatural(b, 'b', { lte:50 });
if (results.length) return results;
return "a and b are both natural numbers, in range!";
}
bothNatural(-5, 12.34);
// [ "bothNatural(): `a` -5 is not gte 0",
// "bothNatural(): `b` 23.45 is not divisible by 1" ]
bothNatural(99, 200);
// [ "bothNatural(): `b` 200 is not lte 50" ]
bothNatural(12, 3);
// "a and b are both natural numbers, in range!"0.0.20
2 years ago
0.0.16
3 years ago
0.0.17
3 years ago
0.0.18
3 years ago
0.0.19
3 years ago
0.0.10
3 years ago
0.0.11
3 years ago
0.0.12
3 years ago
0.0.13
3 years ago
0.0.14
3 years ago
0.0.15
3 years ago
0.0.9
3 years ago
0.0.8
3 years ago
0.0.7
3 years ago
0.0.6
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.1
3 years ago