Skip to content

Commit

Permalink
Convert to pure JS and exceljs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiridudekusy committed Apr 26, 2020
1 parent 440aaaa commit adc1f24
Show file tree
Hide file tree
Showing 26 changed files with 1,388 additions and 1,082 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ node_modules
build
lib
test
coverage
coverage
/.nyc_output/
*.tgz
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=http://registry.npmjs.com
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "excel-as-json",
"version": "2.0.2",
"name": "excel-as-json2",
"version": "0.1.0-dev.0",
"description": "Convert Excel data to JSON",
"author": "Steve Tarver <steve.tarver@gmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -28,15 +28,11 @@
},
"homepage": "https://github.com/stevetarver/excel-as-json",
"dependencies": {
"excel": "0.1.7"
"exceljs": "^3.9.0"
},
"devDependencies": {
"chai": "4.1.2",
"codecov.io": "0.1.6",
"coffee-coverage": "3.0.0",
"coffeescript": "2.2.4",
"coveralls": "3.0.0",
"istanbul": "0.4.5",
"mocha": "5.1.0"
"mocha": "5.1.0",
"nyc": "^15.0.1"
}
}
8 changes: 0 additions & 8 deletions spec/all-specs.coffee

This file was deleted.

8 changes: 8 additions & 0 deletions spec/all-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require('./assignSpec');
require('./convertSpec');
require('./convertValueSpec');
require('./parseKeyNameSpec');
require('./transposeSpec');
require('./validateOptionsSpec');
require('./processFileSpec');
require('./regressionSpec');
154 changes: 0 additions & 154 deletions spec/assignSpec.coffee

This file was deleted.

185 changes: 185 additions & 0 deletions spec/assignSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const {
assign
} = require('../src/excel-as-json');

// TODO: How to get chai defined in a more global way
const chai = require('chai');
chai.should();
const {
expect
} = chai;

// NOTE: the excel package uses '' for all empty cells
const EMPTY_CELL = '';
const DEFAULT_OPTIONS = {
omitEmptyFields: false,
convertTextToNumber: true
};


describe('assign', function() {

it('should assign first level properties', function() {
const subject = {};
assign(subject, 'foo', 'clyde', DEFAULT_OPTIONS);
return subject.foo.should.equal('clyde');
});


it('should assign second level properties', function() {
const subject = {};
assign(subject, 'foo.bar', 'wombat', DEFAULT_OPTIONS);
return subject.foo.bar.should.equal('wombat');
});


it('should assign third level properties', function() {
const subject = {};
assign(subject, 'foo.bar.bazz', 'honey badger', DEFAULT_OPTIONS);
return subject.foo.bar.bazz.should.equal('honey badger');
});


it('should convert text to numbers', function() {
const subject = {};
assign(subject, 'foo.bar.bazz', '42', DEFAULT_OPTIONS);
return subject.foo.bar.bazz.should.equal(42);
});


it('should convert text to booleans', function() {
const subject = {};
assign(subject, 'foo.bar.bazz', 'true', DEFAULT_OPTIONS);
subject.foo.bar.bazz.should.equal(true);
assign(subject, 'foo.bar.bazz', 'false', DEFAULT_OPTIONS);
return subject.foo.bar.bazz.should.equal(false);
});


it('should overwrite existing values', function() {
const subject = {};
assign(subject, 'foo.bar.bazz', 'honey badger', DEFAULT_OPTIONS);
subject.foo.bar.bazz.should.equal('honey badger');
assign(subject, 'foo.bar.bazz', "don't care", DEFAULT_OPTIONS);
return subject.foo.bar.bazz.should.equal("don't care");
});


it('should assign properties to objects in a list', function() {
const subject = {};
assign(subject, 'foo.bar[0].what', 'that', DEFAULT_OPTIONS);
return subject.foo.bar[0].what.should.equal('that');
});


it('should assign properties to objects in a list with first entry out of order', function() {
const subject = {};
assign(subject, 'foo.bar[1].what', 'that', DEFAULT_OPTIONS);
assign(subject, 'foo.bar[0].what', 'this', DEFAULT_OPTIONS);
subject.foo.bar[0].what.should.equal('this');
return subject.foo.bar[1].what.should.equal('that');
});


it('should assign properties to objects in a list with second entry out of order', function() {
const subject = {};
assign(subject, 'foo.bar[0].what', 'this', DEFAULT_OPTIONS);
assign(subject, 'foo.bar[2].what', 'that', DEFAULT_OPTIONS);
assign(subject, 'foo.bar[1].what', 'other', DEFAULT_OPTIONS);
subject.foo.bar[0].what.should.equal('this');
subject.foo.bar[2].what.should.equal('that');
return subject.foo.bar[1].what.should.equal('other');
});


it('should split a semicolon delimited list for flat arrays', function() {
const subject = {};
assign(subject, 'foo.bar[]', 'peter;paul;mary', DEFAULT_OPTIONS);
return subject.foo.bar.toString().should.equal(['peter','paul','mary'].toString());
});


it('should convert text in a semicolon delimited list to numbers', function() {
const subject = {};
assign(subject, 'foo.bar[]', 'peter;-43;mary', DEFAULT_OPTIONS);
return subject.foo.bar.toString().should.equal(['peter',-43,'mary'].toString());
});


it('should convert text in a semicolon delimited list to booleans', function() {
const subject = {};
assign(subject, 'foo.bar[]', 'peter;false;true', DEFAULT_OPTIONS);
return subject.foo.bar.toString().should.equal(['peter',false,true].toString());
});


it('should not split a semicolon list with a terminal indexed array', function() {
const subject = {};
console.log('Note: warnings on this test expected');
assign(subject, 'foo.bar[0]', 'peter;paul;mary', DEFAULT_OPTIONS);
return subject.foo.bar.should.equal('peter;paul;mary');
});


it('should omit empty scalar fields when directed', function() {
const o = {
omitEmptyFields: true,
convertTextToNumber: true
};
const subject = {};
assign(subject, 'foo', EMPTY_CELL, o);
return subject.should.not.have.property('foo');
});


it('should omit empty nested scalar fields when directed', function() {
const o = {
omitEmptyFields: true,
convertTextToNumber: true
};
const subject = {};
assign(subject, 'foo.bar', EMPTY_CELL, o);
subject.should.have.property('foo');
return subject.foo.should.not.have.property('bar');
});


it('should omit nested array fields when directed', function() {
const o = {
omitEmptyFields: true,
convertTextToNumber: true
};

// specified as an entire list
let subject = {};
console.log('Note: warnings on this test expected');
assign(subject, 'foo[]', EMPTY_CELL, o);
subject.should.not.have.property('foo');

// specified as a list
subject = {};
assign(subject, 'foo[0]', EMPTY_CELL, o);
subject.should.not.have.property('foo');

// specified as a list of objects
subject = {};
assign(subject, 'foo[0].bar', 'bazz', o);
assign(subject, 'foo[1].bar', EMPTY_CELL, o);
return subject.foo[1].should.not.have.property('bar');
});


return it('should treat text that looks like numbers as text when directed', function() {
const o =
{convertTextToNumber: false};

const subject = {};
assign(subject, 'part', '00938', o);
return subject.part.should.be.a('string').and.equal('00938');
});
});
Loading

0 comments on commit adc1f24

Please sign in to comment.