UNPKG

@respeecher/respeecher-js

Version:

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Frespeecher%2Frespeecher-js) [![npm shield](

26 lines (25 loc) 896 B
import { SchemaType } from "../../Schema.mjs"; import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator.mjs"; import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.mjs"; export function stringLiteral(literal) { const schemaCreator = createIdentitySchemaCreator(SchemaType.STRING_LITERAL, (value, { breadcrumbsPrefix = [] } = {}) => { if (value === literal) { return { ok: true, value: literal, }; } else { return { ok: false, errors: [ { path: breadcrumbsPrefix, message: getErrorMessageForIncorrectType(value, `"${literal}"`), }, ], }; } }); return schemaCreator(); }