@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
54 lines (53 loc) • 1.66 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import { objectObjectHandler, parseJson, watchValidator } from "../utils";
import { isObject, isString } from "../validators";
export const validateMsg = (component, value) => {
objectObjectHandler(value, () => {
try {
value = parseJson(value);
}
catch (_a) {
}
watchValidator(component, `_msg`, (value) => {
if (value === undefined) {
return true;
}
if (typeof value === 'string' && value.length > 0) {
return true;
}
if (isObject(value) && value !== null) {
const desc = value._description;
return isString(desc, 1);
}
return false;
}, new Set(['MsgPropType', 'string']), value);
});
};
export function isMsgDefinedAndInputTouched(msg, touched) {
return Boolean(msg) && touched === true;
}
export const checkHasMsg = isMsgDefinedAndInputTouched;
export function normalizeMsg(msg) {
if (typeof msg === 'string') {
try {
return parseJson(msg);
}
catch (_a) {
return { _description: msg, _type: 'error' };
}
}
if (msg && typeof msg === 'object' && !('_type' in msg)) {
return Object.assign(Object.assign({}, msg), { _type: 'error' });
}
return msg;
}
export function getMsgType(msg) {
var _a;
if (typeof msg === 'string') {
return 'error';
}
return (_a = msg === null || msg === void 0 ? void 0 : msg._type) !== null && _a !== void 0 ? _a : 'error';
}
//# sourceMappingURL=msg.js.map