@etsoo/toolpad
Version:
Dashboard framework extention based on Toolpad Core
61 lines (60 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CODEC_STRING = exports.CODEC_JSON_STRICT = exports.CODEC_JSON = exports.CODE_BOOLEAN = exports.CODEC_NUMBER = exports.CODEC_DATE_ONLY = exports.CODEC_DATE = void 0;
/**
* A codec that can encode and decode Date objects to and from strings.
*/
exports.CODEC_DATE = {
parse: (value) => new Date(value),
stringify: (value) => value.toISOString()
};
/**
* A codec that can encode and decode Date objects to and from strings, but only the date part.
*/
exports.CODEC_DATE_ONLY = {
parse: (value) => new Date(value),
stringify: (value) => value.toISOString().split("T")[0]
};
/**
* A codec that can encode and decode numbers to and from strings.
*/
exports.CODEC_NUMBER = {
parse: (value) => Number(value),
stringify: (value) => String(value)
};
/**
* A codec that can encode and decode boolean values to and from strings.
*/
exports.CODE_BOOLEAN = {
parse: (value) => value === "true",
stringify: (value) => String(value)
};
/**
* A codec that can encode and decode JSON values to and from strings.
*/
exports.CODEC_JSON = {
parse: (value) => {
try {
return JSON.parse(value);
}
catch {
return null;
}
},
stringify: (value) => JSON.stringify(value)
};
/**
* A codec that can encode and decode JSON values to and from strings.
* If the JSON value is invalid, parsing will fail.
*/
exports.CODEC_JSON_STRICT = {
parse: (value) => JSON.parse(value),
stringify: (value) => JSON.stringify(value)
};
/**
* A codec that can encode and decode strings to and from strings.
*/
exports.CODEC_STRING = {
parse: (value) => value,
stringify: (value) => value
};