@respeecher/respeecher-js
Version:
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Frespeecher%2Frespeecher-js) [ • 896 B
JavaScript
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();
}