@sdeverywhere/compile 0.7.23 → 0.7.24
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/package.json +1 -1
- package/src/_shared/helpers.js +13 -2
package/package.json
CHANGED
package/src/_shared/helpers.js
CHANGED
|
@@ -24,6 +24,8 @@ let nextLevelVarSeq = 1
|
|
|
24
24
|
let nextAuxVarSeq = 1
|
|
25
25
|
// parsed csv data cache
|
|
26
26
|
let csvData = new Map()
|
|
27
|
+
// parsed xlsx data cache
|
|
28
|
+
let xlsxData = new Map()
|
|
27
29
|
|
|
28
30
|
// Newer versions of the xlsx package require manually setting the `fs` instance
|
|
29
31
|
// before using the `XLSX.readFile` function
|
|
@@ -38,6 +40,7 @@ export function resetHelperState() {
|
|
|
38
40
|
nextLevelVarSeq = 1
|
|
39
41
|
nextAuxVarSeq = 1
|
|
40
42
|
csvData.clear()
|
|
43
|
+
xlsxData.clear()
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
export let canonicalName = name => {
|
|
@@ -200,7 +203,15 @@ export let isIterable = obj => {
|
|
|
200
203
|
}
|
|
201
204
|
// Command helpers
|
|
202
205
|
export let readXlsx = pathname => {
|
|
203
|
-
|
|
206
|
+
// Read the XLSX file at the pathname and parse it.
|
|
207
|
+
// Return a `XLSX.WorkBook` object that can be used to access the data.
|
|
208
|
+
// Cache parsed files to support multiple reads from different equations.
|
|
209
|
+
let xlsx = xlsxData.get(pathname)
|
|
210
|
+
if (!xlsx) {
|
|
211
|
+
xlsx = XLSX.readFile(pathname, { cellDates: true })
|
|
212
|
+
xlsxData.set(pathname, xlsx)
|
|
213
|
+
}
|
|
214
|
+
return xlsx
|
|
204
215
|
}
|
|
205
216
|
export let readCsv = (pathname, delimiter = ',') => {
|
|
206
217
|
// Read the CSV file at the pathname and parse it with the given delimiter.
|
|
@@ -208,7 +219,7 @@ export let readCsv = (pathname, delimiter = ',') => {
|
|
|
208
219
|
// If there is a header row, it is returned as the first row.
|
|
209
220
|
// Cache parsed files to support multiple reads from different equations.
|
|
210
221
|
let csv = csvData.get(pathname)
|
|
211
|
-
if (csv
|
|
222
|
+
if (!csv) {
|
|
212
223
|
const CSV_PARSE_OPTS = {
|
|
213
224
|
delimiter,
|
|
214
225
|
columns: false,
|