UNPKG

bguard

Version:

**bguard** is a powerful, flexible, and type-safe validation library for TypeScript. It allows developers to define validation schemas for their data structures and ensures that data conforms to the expected types and constraints.

55 lines (47 loc) 1.96 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _chunkFIDPCCCWjs = require('./chunk-FIDPCCCW.js'); // src/translationMap.ts var defaultErrorMap = { //@@start "c:optional": "The required value is missing", "c:nullable": "Value should not be null", "c:array": "Expected an array but received a different type", "c:objectType": "Expected an object but received a different type", "c:objectTypeAsArray": "Expected an object but received an array. Invalid type of data", "c:unrecognizedProperty": "This property is not allowed in the object", "c:requiredProperty": "Missing required property in the object", "c:invalidType": "Invalid type of data", "c:isBoolean": "The received value is not {{e}}", "c:date": "The received value is not a valid instance of Date" //@@end }; var data = { default: { ...defaultErrorMap } }; function setToDefaultLocale({ key, message }) { const defaultLocale = data.default; if (defaultLocale[key]) throw new (0, _chunkFIDPCCCWjs.BuildSchemaError)("Duplicate default message key"); defaultLocale[key] = message; } function setLocale(lng, custom) { if (lng === "default") throw new (0, _chunkFIDPCCCWjs.BuildSchemaError)("Invalid language"); data[lng] ??= { ...defaultErrorMap }; const locale = data[lng]; Object.entries(custom).forEach(([messageKey, messageValue]) => { locale[messageKey] = messageValue; }); } function clearLocales() { data = { default: { ...defaultErrorMap } }; } function getTranslationByLocale(lng) { if (!lng) return data["default"]; return _nullishCoalesce(data[lng], () => ( data["default"])); } exports.setToDefaultLocale = setToDefaultLocale; exports.setLocale = setLocale; exports.clearLocales = clearLocales; exports.getTranslationByLocale = getTranslationByLocale; //# sourceMappingURL=chunk-TJQ5NVL4.js.map