Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

excel2json

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

excel2json - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

5

lib/excel/cell.js

@@ -51,2 +51,7 @@ /**

if (value === '') {
// empty cell
return;
}
result.push({

@@ -53,0 +58,0 @@ cell: coord.cell,

96

lib/index.js

@@ -60,2 +60,6 @@ /**

number: function(d) {
if (d.length >= 18) {
// IEEE754
return Number(Number(d).toFixed(8))
}
return Number(d);

@@ -83,2 +87,3 @@ },

opts = {},
beforeRow,
idx = {},

@@ -94,9 +99,12 @@ list = [];

_.each(cells, function(cell) {
if (beforeRow !== cell.row) {
_.each(idx, function(i) {
if (i.type !== 'format') {
i.value += 1;
}
});
beforeRow = cell.row;
}
if (cell.cell === _this.opts.option_cell) {
var _opts;
try {
_opts = JSON.parse(cell.value) || {};
} catch (e) {
_opts = {};
}
var _opts = JSON.parse(cell.value);
_.extend(opts, _opts);

@@ -107,7 +115,10 @@ return;

if (cell.row === opts.attr_line) {
var type = cell.value.match(/:(\w+)$/);
var keys = cell.value.replace(/:\w+$/, '').split('.');
var type = cell.value.match(/:(\w+)$/),
key = cell.value.replace(/:\w+$/, ''),
keys = key.split('.');
opts.format = opts.format || {};
opts.format[cell.column] = {
type: type && type[1],
key: key,
keys: keys

@@ -118,3 +129,6 @@ };

var format = opts.format && opts.format[cell.column];
var format = opts.format && opts.format[cell.column],
data,
_idx;
if (cell.row < opts.data_line || !format) {

@@ -124,14 +138,26 @@ return;

if (format.type && format.type.toLowerCase() === 'index') {
idx[format.keys.join('.')] = parseInt(cell.value, 10);
_idx = parseInt(cell.value, 10);
if (!idx[format.key] || idx[format.key].value !== _idx) {
idx[format.key] = {
type: 'format',
value: _idx
};
_.each(idx, function(i, key) {
if (new RegExp('^' + format.key + '.+$').test(key)) {
idx[key].value = 0;
}
});
}
return;
}
if (cell.column === 'A') {
if (format.key === opts.ref_key || format.key === '__ref') {
idx = {};
list.push({});
}
var data = _.last(list);
data = _.last(list);
_.each(format.keys, function(_key, i) {
var isArray = /^#/.test(_key),
isSplitArray = /^\$/.test(_key);
isSplitArray = /^\$/.test(_key),
__key;
if (isArray) {

@@ -147,5 +173,11 @@ _key = _key.replace(/^#/, '');

if (isArray) {
var _idx = idx[format.keys.slice(0, i + 1).join('.')];
_idx = typeof _idx === 'number' ? _idx : data[_key].length;
data = data[_key][_idx] = data[_key][_idx] || {};
__key = format.keys.slice(0, i + 1).join('.');
_idx = idx[__key];
if (!_idx) {
_idx = idx[__key] = {
type: 'normal',
value: data[_key].length ? data[_key].length - 1 : 0
};
}
data = data[_key][_idx.value] = data[_key][_idx.value] || {};
return;

@@ -158,7 +190,18 @@ }

if (isArray) {
var __key = data[_key].length;
__key = format.keys.slice(0, i + 1).join('.');
_idx = idx[__key];
if (!_idx) {
_idx = idx[__key] = {
type: 'normal',
value: data[_key].length ? data[_key].length - 1 : 0
};
}
data = data[_key];
_key = __key;
_key = _idx.value;
}
if (data[_key]) {
return;
}
var type = format.type && format.type.toLowerCase();

@@ -252,2 +295,3 @@ if (type === 'number' || type === 'num') {

list,
errList,
excelData;

@@ -272,4 +316,10 @@

} catch (e) {
_this.logger.error(e.stack);
return _next(e);
_this.logger.error('invalid sheet format.', sheetData.num, sheetData.name);
errList = errList || [];
errList.push({
num: sheetData.num,
name: sheetData.name,
error: e
});
return _next();
}

@@ -290,3 +340,3 @@

list = result;
list = _.compact(result);
next();

@@ -300,3 +350,3 @@ });

callback(null, list);
callback(null, list, errList);
});

@@ -303,0 +353,0 @@ };

{
"name": "excel2json",
"version": "0.2.0",
"version": "0.2.1",
"description": "excel2json",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -70,5 +70,5 @@ Excel2Json

// format: {
// A: { type: null, keys: [ '_id' ] },
// B: { type: null, keys: [ 'obj', 'code' ] },
// C: { type: 'number', keys: [ 'obj', 'value' ] }
// A: { type: null, key: '_id', keys: [ '_id' ] },
// B: { type: null, key: 'obj.code', keys: [ 'obj', 'code' ] },
// C: { type: 'number', key: 'obj.value', keys: [ 'obj', 'value' ] }
// }

@@ -75,0 +75,0 @@ // },

@@ -8,5 +8,6 @@ var should = require('should');

it(filepath, function(done) {
excel2json.parse(filepath, [], function(err, result) {
excel2json.parse(filepath, [], function(err, result, errList) {
should.not.exist(err);
should.exist(result);
should.not.exist(errList);
result.should.have.length(2);

@@ -20,8 +21,8 @@ result[0].should.property('num', 1);

format: {
A: { type: null, keys: [ '_id' ] },
B: { type: 'index', keys: [ '#array' ] },
C: { type: null, keys: [ '#array', 'key' ] },
D: { type: 'number', keys: [ '#array', 'num' ] },
E: { type: 'number', keys: [ '#array', '#list' ] },
F: { type: null, keys: [ 'key' ] }
A: { type: null, key: '_id', keys: [ '_id' ] },
B: { type: 'index', key: '#array', keys: [ '#array' ] },
C: { type: null, key: '#array.key', keys: [ '#array', 'key' ] },
D: { type: 'number', key: '#array.num', keys: [ '#array', 'num' ] },
E: { type: 'number', key: '#array.#list', keys: [ '#array', '#list' ] },
F: { type: null, key: 'key', keys: [ 'key' ] }
}

@@ -74,5 +75,6 @@ });

it(filepath, function(done) {
excel2json.parse(filepath, [], function(err, result) {
excel2json.parse(filepath, [], function(err, result, errList) {
should.not.exist(err);
should.exist(result);
should.not.exist(errList);

@@ -79,0 +81,0 @@ excel2json.toJson(result, function(_err, _result) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc