UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

53 lines (52 loc) 1.49 kB
/** * DevExtreme (esm/viz/components/parse_utils.js) * Version: 24.2.6 * Build date: Mon Mar 17 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { noop } from "../../core/utils/common"; import dateSerialization from "../../core/utils/date_serialization"; import { isDefined } from "../../core/utils/type"; const parsers = { string: function(val) { return isDefined(val) ? "" + val : val }, numeric: function(val) { if (!isDefined(val)) { return val } let parsedVal = Number(val); if (isNaN(parsedVal)) { parsedVal = void 0 } return parsedVal }, datetime: function(val) { if (!isDefined(val)) { return val } let parsedVal; const numVal = Number(val); if (!isNaN(numVal)) { parsedVal = new Date(numVal) } else { parsedVal = dateSerialization.deserializeDate(val) } if (isNaN(Number(parsedVal))) { parsedVal = void 0 } return parsedVal } }; export function correctValueType(type) { return "numeric" === type || "datetime" === type || "string" === type ? type : "" } export const getParser = function(valueType) { return parsers[correctValueType(valueType)] || noop };