@evidence-dev/component-utilities
Advanced tools
Comparing version 0.0.0-45452685 to 0.0.0-45593986
{ | ||
"name": "@evidence-dev/component-utilities", | ||
"version": "0.0.0-45452685", | ||
"version": "0.0.0-45593986", | ||
"description": "", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"ssf": "^0.11.2", | ||
"svelte": "^3.59.1" | ||
"svelte": "3.55.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "scripts": { |
@@ -7,2 +7,3 @@ import ssf from 'ssf'; | ||
import { standardizeDateString } from './dateParsing'; | ||
import { inferValueType } from './inferColumnTypes'; | ||
@@ -49,2 +50,29 @@ const AXIS_FORMATTING_CONTEXT = 'axis'; | ||
/** | ||
* Returns an Evidence format object to be used in the applyFormatting function | ||
* @param {string} formatString string containing an Excel-style format code, or a format name matching a built-in or custom format | ||
* @param {string} valueType optional - a string representing the data type within the column that will be formatted ('number', 'date', 'boolean', or 'string) | ||
* @returns a format object based on the formatString matching a built-in or custom format name, or a new custom format object containing an Excel-style format code | ||
*/ | ||
export function getFormatObjectFromString(formatString, valueType = undefined) { | ||
let potentialFormatTag = formatString; | ||
let customFormats = getCustomFormats(); | ||
let matchingFormat = [...BUILT_IN_FORMATS, ...customFormats].find( | ||
(format) => format.formatTag?.toLowerCase() === potentialFormatTag?.toLowerCase() | ||
); | ||
let newFormat = {}; | ||
if (matchingFormat) { | ||
return matchingFormat; | ||
} else { | ||
newFormat = { | ||
formatTag: 'custom', | ||
formatCode: potentialFormatTag | ||
}; | ||
if (valueType) { | ||
newFormat.valueType = valueType; | ||
} | ||
return newFormat; | ||
} | ||
} | ||
export const formatValue = (value, columnFormat = undefined, columnUnitSummary = undefined) => { | ||
@@ -140,2 +168,3 @@ try { | ||
} | ||
let result = undefined; | ||
@@ -205,1 +234,14 @@ if (columnFormat) { | ||
} | ||
/** | ||
* Formats a value to whichever format is passed in | ||
* @param {*} value the value to be formatted | ||
* @param {string} format string containing an Excel-style format code, or a format name matching a built-in or custom format | ||
* @returns a formatted value | ||
*/ | ||
export function fmt(value, format) { | ||
let formatObj = getFormatObjectFromString(format); | ||
let valueType = inferValueType(value); | ||
formatObj.valueType = valueType; | ||
return formatValue(value, formatObj); | ||
} |
@@ -17,3 +17,3 @@ // To-do, replace with import from db-commons | ||
const inferValueType = function (columnValue) { | ||
export const inferValueType = function (columnValue) { | ||
if (typeof columnValue === 'number') { | ||
@@ -20,0 +20,0 @@ return EvidenceType.NUMBER; |
176785
33
6508
+ Addedsvelte@3.55.0(transitive)
- Removedsvelte@3.59.2(transitive)
Updatedsvelte@3.55.0