markdown-up 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/data.js CHANGED
@@ -517,7 +517,7 @@ export function topData(data, count, categoryFields = null) {
517
517
 
518
518
 
519
519
  // Helper function to format labels
520
- export function formatValue(value, precision = null, datetime = null, trim = true) {
520
+ export function formatValue(value, precision = null, datetime = null, trim = null) {
521
521
  if (value instanceof Date) {
522
522
  if (datetime === 'year') {
523
523
  // Round to nearest year
@@ -546,12 +546,13 @@ export function formatValue(value, precision = null, datetime = null, trim = tru
546
546
  return value.toISOString().replace(rDateCleanup, '');
547
547
  } else if (typeof value === 'number') {
548
548
  const numberFormat = value.toFixed(precision ?? defaultPrecision);
549
- return trim ? numberFormat.replace(rNumberCleanup, '') : numberFormat;
549
+ return (trim ?? defaultTrim) ? numberFormat.replace(rNumberCleanup, '') : numberFormat;
550
550
  }
551
551
  return `${value}`;
552
552
  }
553
553
 
554
554
  const defaultPrecision = 2;
555
+ const defaultTrim = true;
555
556
  const rNumberCleanup = /\.0*$/;
556
557
  const rDateCleanup = /(?:(?:(?:-01)?T00:00)?:00)?\.\d\d\dZ$/;
557
558
 
package/lib/dataTable.js CHANGED
@@ -33,6 +33,9 @@ struct DataTable
33
33
  # The datetime format
34
34
  optional DataTableDatetimeFormat datetime
35
35
 
36
+ # If true, trim formatted values (default is true)
37
+ optional bool trim
38
+
36
39
 
37
40
  # A data table field formatting model
38
41
  struct DataTableFieldFormat
@@ -118,6 +121,7 @@ export function dataTableElements(data, dataTable = null, options = null) {
118
121
  const markdownOptions = (options !== null && 'urlFn' in options ? {'urlFn': options.urlFn} : null);
119
122
  const formatPrecision = (dataTable !== null ? (dataTable.precision ?? null) : null);
120
123
  const formatDatetime = (dataTable !== null ? (dataTable.datetime ?? null) : null);
124
+ const formatTrim = (dataTable !== null ? (dataTable.trim ?? null) : null);
121
125
  return {
122
126
  'html': 'table',
123
127
  'elem': [
@@ -162,7 +166,7 @@ export function dataTableElements(data, dataTable = null, options = null) {
162
166
  const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
163
167
  const fieldElements = fieldFormat !== null && fieldFormat.markdown
164
168
  ? markdownElements(parseMarkdown(`${value}`), markdownOptions)
165
- : {'text': formatValue(value, formatPrecision, formatDatetime, false)};
169
+ : {'text': formatValue(value, formatPrecision, formatDatetime, formatTrim)};
166
170
  return {
167
171
  'html': 'td',
168
172
  'attr': fieldFormat !== null && 'align' in fieldFormat
@@ -175,7 +179,7 @@ export function dataTableElements(data, dataTable = null, options = null) {
175
179
  const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
176
180
  const fieldElements = fieldFormat !== null && fieldFormat.markdown
177
181
  ? markdownElements(parseMarkdown(`${value}`), markdownOptions)
178
- : {'text': formatValue(value, formatPrecision, formatDatetime, false)};
182
+ : {'text': formatValue(value, formatPrecision, formatDatetime, formatTrim)};
179
183
  return {
180
184
  'html': 'td',
181
185
  'attr': fieldFormat !== null && 'align' in fieldFormat
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "2.2.0",
4
+ "version": "2.2.1",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",