platina-core
Version:
UI Kit of SberMarketing
28 lines (27 loc) • 855 B
JavaScript
import { round } from '../utils';
import { Types } from './types';
export function format(value, type) {
if (['', 'undefined', 'null'].includes(String(value)))
return '';
switch (type) {
case Types.List:
case Types.Object:
return JSON.stringify(value, null, 2);
case Types.Date:
return new Date(value).toLocaleString('ru', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
case Types.Number:
return round(Number(value), 100).toLocaleString('ru');
default:
return String(value);
}
}
export function escape(value) {
return value.replace(/\s/g, '\\s').replace(/\./g, '\\.');
}