io-ts-types
Version:
A collection of codecs and combinators for use with io-ts
18 lines (17 loc) • 657 B
JavaScript
/**
* @since 0.4.6
*/
import * as t from 'io-ts';
var regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
/**
* @example
* import { UUID } from 'io-ts-types/es6/UUID'
* import { right } from 'fp-ts/es6/Either'
* import { PathReporter } from 'io-ts/es6/PathReporter'
*
* assert.deepStrictEqual(UUID.decode('00000000-0000-0000-0000-000000000000'), right('00000000-0000-0000-0000-000000000000'))
* assert.deepStrictEqual(PathReporter.report(UUID.decode('not a uuid')), ['Invalid value "not a uuid" supplied to : UUID'])
*
* @since 0.4.6
*/
export var UUID = t.brand(t.string, function (s) { return regex.test(s); }, 'UUID');