markdown-up 2.4.1 → 3.0.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/dataTable.js CHANGED
@@ -3,12 +3,12 @@
3
3
 
4
4
  /** @module lib/dataTable */
5
5
 
6
- import {compareValues} from 'bare-script/lib/data.js';
7
6
  import {formatValue} from './dataUtil.js';
8
7
  import {markdownElements} from 'markdown-model/lib/elements.js';
9
8
  import {parseMarkdown} from 'markdown-model/lib/parser.js';
10
9
  import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
11
10
  import {validateType} from 'schema-markdown/lib/schema.js';
11
+ import {valueCompare} from 'bare-script/lib/value.js';
12
12
 
13
13
 
14
14
  // The data table model's Schema Markdown
@@ -164,7 +164,7 @@ export function dataTableElements(data, dataTable = null, options = null) {
164
164
 
165
165
  // Skip this value?
166
166
  if (skip) {
167
- skip = (compareValues(value, rowPrev[field] ?? null) === 0);
167
+ skip = (valueCompare(value, rowPrev[field] ?? null) === 0);
168
168
  }
169
169
 
170
170
  const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
package/lib/dataUtil.js CHANGED
@@ -1,36 +1,39 @@
1
1
  // Licensed under the MIT License
2
2
  // https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
3
3
 
4
+ import {valueString, valueType} from 'bare-script/lib/value.js';
5
+
4
6
 
5
7
  // Helper function to format labels
6
8
  export function formatValue(value, precision = null, datetime = null, trim = null) {
7
- if (value instanceof Date) {
9
+ const type = valueType(value);
10
+ if (type === 'datetime') {
8
11
  if (datetime === 'year') {
9
12
  // Round to nearest year
10
13
  let valueRounded = value;
11
- if (value.getUTCMonth() > 5) {
14
+ if (value.getMonth() > 5) {
12
15
  valueRounded = new Date(value);
13
- valueRounded.setUTCFullYear(value.getUTCFullYear() + 1);
16
+ valueRounded.setFullYear(value.getFullYear() + 1);
14
17
  }
15
18
 
16
- const isoFormat = valueRounded.toISOString();
19
+ const isoFormat = valueString(valueRounded);
17
20
  return isoFormat.slice(0, isoFormat.indexOf('T') - 6);
18
21
  } else if (datetime === 'month') {
19
22
  // Round to the nearest month
20
23
  let valueRounded = value;
21
- if (value.getUTCDate() > 15) {
24
+ if (value.getDate() > 15) {
22
25
  valueRounded = new Date(value);
23
- valueRounded.setMonth(value.getUTCMonth() + 1);
26
+ valueRounded.setMonth(value.getMonth() + 1);
24
27
  }
25
28
 
26
- const isoFormat = valueRounded.toISOString();
29
+ const isoFormat = valueString(valueRounded);
27
30
  return isoFormat.slice(0, isoFormat.indexOf('T') - 3);
28
31
  } else if (datetime === 'day') {
29
- const isoFormat = value.toISOString();
32
+ const isoFormat = valueString(value);
30
33
  return isoFormat.slice(0, isoFormat.indexOf('T'));
31
34
  }
32
- return value.toISOString().replace(rDateCleanup, '');
33
- } else if (typeof value === 'number') {
35
+ return valueString(value).replace(rDateCleanup, '');
36
+ } else if (type === 'number') {
34
37
  const numberFormat = value.toFixed(precision ?? defaultPrecision);
35
38
  return (trim ?? defaultTrim) ? numberFormat.replace(rNumberCleanup, '') : numberFormat;
36
39
  }
@@ -40,7 +43,7 @@ export function formatValue(value, precision = null, datetime = null, trim = nul
40
43
  const defaultPrecision = 2;
41
44
  const defaultTrim = true;
42
45
  const rNumberCleanup = /\.0*$/;
43
- const rDateCleanup = /(?:(?:(?:-01)?T00:00)?:00)?\.\d\d\dZ$/;
46
+ const rDateCleanup = /(?:(?:(?:-01)?T00:00)?:00)?(?:\.\d{1,6})?(?:Z|[+-]\d\d:\d\d)$/;
44
47
 
45
48
 
46
49
  // Helper function to compute a value's parameter
@@ -49,7 +52,7 @@ export function valueParameter(value, minValue, maxValue) {
49
52
  return 0;
50
53
  }
51
54
 
52
- if (minValue instanceof Date) {
55
+ if (valueType(minValue) === 'datetime') {
53
56
  const minDateValue = minValue.valueOf();
54
57
  return (value.valueOf() - minDateValue) / (maxValue.valueOf() - minDateValue);
55
58
  }
@@ -60,7 +63,7 @@ export function valueParameter(value, minValue, maxValue) {
60
63
 
61
64
  // Helper function to compute a value from a parameter
62
65
  export function parameterValue(param, minValue, maxValue) {
63
- if (minValue instanceof Date) {
66
+ if (valueType(minValue) === 'datetime') {
64
67
  const minDateValue = minValue.valueOf();
65
68
  return new Date(minDateValue + param * (maxValue.valueOf() - minDateValue));
66
69
  }
package/lib/lineChart.js CHANGED
@@ -4,9 +4,9 @@
4
4
  /** @module lib/lineChart */
5
5
 
6
6
  import {formatValue, parameterValue, valueParameter} from './dataUtil.js';
7
- import {compareValues} from 'bare-script/lib/data.js';
8
7
  import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
9
8
  import {validateType} from 'schema-markdown/lib/schema.js';
9
+ import {valueCompare} from 'bare-script/lib/value.js';
10
10
 
11
11
 
12
12
  // The line chart model's Schema Markdown
@@ -185,7 +185,7 @@ export function lineChartElements(data, lineChart, options = null) {
185
185
  data.sort((row1, row2) => {
186
186
  const x1 = row1[xField] ?? null;
187
187
  const x2 = row2[xField] ?? null;
188
- return compareValues(x1, x2);
188
+ return valueCompare(x1, x2);
189
189
  });
190
190
 
191
191
  // Generate the line points - [(label, color, points), ...]