From 766fc4f4d20c292e59705358a7c4d42ab7388429 Mon Sep 17 00:00:00 2001 From: julitork Date: Tue, 29 Aug 2023 16:04:32 +0300 Subject: [PATCH] allow rawNumber override raw option --- bits/90_utils.js | 2 +- test.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bits/90_utils.js b/bits/90_utils.js index 2a290d8..7891f58 100644 --- a/bits/90_utils.js +++ b/bits/90_utils.js @@ -39,7 +39,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar else if(raw && v === null) row[hdr[C]] = null; else continue; } else { - row[hdr[C]] = raw && (val.t !== "n" || (val.t === "n" && o.rawNumbers !== false)) ? v : format_cell(val,v,o); + row[hdr[C]] = (val.t === 'n' && typeof o.rawNumbers === 'boolean' ? o.rawNumbers : raw) ? v : format_cell(val, v, o); } if(v != null) isempty = false; } diff --git a/test.js b/test.js index 0ae6cec..39c4eb6 100644 --- a/test.js +++ b/test.js @@ -1402,13 +1402,16 @@ describe('parse features', function() { ].forEach(function(m) { it(m[0], function() { var wb = X.read(fs.readFileSync(m[1]), {type: TYPE, cellDates: true}); var ws = wb.Sheets[wb.SheetNames[0]]; - var data = X.utils.sheet_to_json(ws, { header: 1, raw: true, rawNumbers: false }); - assert.ok(data[0][1] instanceof Date); - assert.ok(data[1][1] instanceof Date); - assert.equal(data[2][1], '$123.00'); - assert.equal(data[3][1], '98.76%'); - assert.equal(data[4][1], '456.00'); - assert.equal(data[5][1], '7,890'); + var data1 = X.utils.sheet_to_json(ws, { header: 1, raw: true, rawNumbers: false }); + var data2 = X.utils.sheet_to_json(ws, { header: 1, raw: false, rawNumbers: true }); + assert.ok(data1[0][1] instanceof Date); + assert.ok(data1[1][1] instanceof Date); + assert.equal(data1[2][1], '$123.00'); + assert.equal(data1[3][1], '98.76%'); + assert.equal(data1[4][1], '456.00'); + assert.equal(data1[5][1], '7,890'); + assert.equal(data2[0][1], '7/23/2020'); + assert.equal(data2[5][1], 7890); }); }); }); it('date system', function() {[