0.8.2 • Published 3 months ago

3h-validate v0.8.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

3h-validate

A runtime validator.

Links

Examples

Type Validation

import { types } from '3h-validate';
// or: const { types } = HV;

const validator = types.number({
    integersOnly: true,
    min: 0,
    includeMin: false,
});

if (validator.test(1)) {
    console.log('1 is a valid value.');
}

validator.validate(0); // RangeError: the number is too small

Versioned Data Management

import { types, Specification } from '3h-validate';
// or: const { types, Specification } = HV;

const spec1 = new Specification({
    version: 'v1',
    validator: types.number(),
});

const spec2 = new Specification({
    version: 'v2',
    validator: types.string(),
    previousSpecification: spec1,
    updater: String,
});

const versionedData = {
    version: 'v1',
    data: 3.14,
};

console.log(spec1.test(versionedData)); // true

console.log(spec2.transform(versionedData));
// { version: 'v2', data: '3.14' }
0.8.1

3 months ago

0.8.0

3 months ago

0.7.1

3 months ago

0.8.2

3 months ago

0.7.0

5 months ago

0.6.0

2 years ago

0.3.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.5.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago