UNPKG

@authduo/authduo

Version:

Free User-sovereign Authentication for the World

20 lines 645 B
export class EnsureError extends Error { constructor(message) { super(`failed validation: ${message}`); } } function fn(kind, validate) { return (name, x) => { if (!validate(x)) throw new EnsureError(`${name} should be ${kind}`); return x; }; } export const ensure = { string: fn("string", x => typeof x === "string"), number: fn("number", x => typeof x === "number"), boolean: fn("boolean", x => typeof x === "boolean"), array: fn("array", x => Array.isArray(x)), object: fn("object", x => typeof x === "object" && !Array.isArray(x)), }; //# sourceMappingURL=ensure.js.map