UNPKG

@discoveryjs/discovery

Version:

Frontend framework for rapid data (JSON) analysis, shareable serverless reports and dashboards

24 lines (23 loc) 751 B
const delimRegExp = /\.\d+(?:eE[-+]?\d+)?|\B(?=(?:\d{3})+(?:\D|$))/g; export function escapeHtml(str) { return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); } export function numDelimOffsets(value) { const strValue = String(value); const offsets = []; let match = null; while ((match = delimRegExp.exec(strValue)) !== null) { offsets.push(match.index); } return offsets; } export function numDelim(value, escape = true) { const strValue = escape && typeof value !== "number" ? escapeHtml(String(value)) : String(value); if (strValue.length > 3) { return strValue.replace( delimRegExp, (m) => m || '<span class="num-delim"></span>' ); } return strValue; }