// @flow import { validatorError } from '../error.js' import { isBoolean, isNumber, isString } from '../is.js' import { EMPTY_VALUE } from '../const.js' import type { LiteralValue, TypeValidator } from '..' export const literalOf = (primitive: T): TypeValidator => { function literal (value: mixed, _scope: string = ''): T { if (value === EMPTY_VALUE || (value === primitive)) return primitive throw validatorError(literal, value, _scope) } literal.type = () => { if (isBoolean(primitive)) return `${primitive ? 'true': 'false'}` else return `"${primitive}"` } return literal }