Skip to content

Commit

Permalink
chore(project): upgrade stack
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcrea committed Jul 25, 2019
1 parent 8815e5f commit 97144a9
Show file tree
Hide file tree
Showing 17 changed files with 5,403 additions and 97 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

16 changes: 0 additions & 16 deletions .eslintrc

This file was deleted.

5 changes: 5 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,5 @@
module.exports = {
extends: ['airbnb-base', 'prettier'],
parser: 'babel-eslint',
rules: {}
};
7 changes: 7 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,7 @@
module.exports = {
printWidth: 120,
semi: true,
singleQuote: true,
bracketSpacing: false,
arrowParens: 'always'
};
8 changes: 5 additions & 3 deletions .travis.yml
@@ -1,9 +1,11 @@
language: node_js
sudo: false
node_js:
- "6"
- "8"
- "stable"
- '4'
- '6'
- '8'
- 'lts/*'
- 'stable'

env:
global:
Expand Down
14 changes: 14 additions & 0 deletions babel.config.js
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: '4'
},
loose: true
}
]
],
plugins: ['@babel/plugin-proposal-class-properties', '@babel/plugin-transform-runtime']
};
54 changes: 29 additions & 25 deletions package.json
Expand Up @@ -5,37 +5,38 @@
"description": "NodeJS Excel files parser & builder",
"main": "lib/index.js",
"scripts": {
"start": "npm run test:watch",
"start": "yarn test:watch",
"test": "NODE_ENV=test jest --runInBand",
"test:watch": "npm run test -- --watch",
"test:coverage": "npm run test -- --coverage",
"lint": "NODE_ENV=test eslint src/",
"compile": "rimraf lib/*; NODE_ENV=production babel src/ -d lib/ -s",
"compile:watch": "npm run compile -- -w",
"prepublish": "npm run compile"
"test:watch": "yarn test -- --watch",
"test:coverage": "yarn test -- --coverage",
"lint": "NODE_ENV=test eslint src/ test/",
"build": "rimraf lib/*; NODE_ENV=production babel src/ -d lib/ -s",
"build:watch": "yarn build -- -w",
"prepublish": "yarn build"
},
"repository": "github:mgcrea/node-xlsx",
"license": "Apache-2.0",
"dependencies": {
"buffer-from": "^1.1.0",
"xlsx": "^0.14.1"
"buffer-from": "^1.1.1",
"xlsx": "^0.14.4"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^8.2.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-function-bind": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"codacy-coverage": "^3.0.0",
"debug-utils": "^0.3.2",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.12.0",
"expect": "^23.1.0",
"jest": "^23.1.0",
"rimraf": "^2.6.2"
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/runtime": "^7.5.5",
"babel-eslint": "^10.0.2",
"codacy-coverage": "^3.4.0",
"debug-utils": "^0.5.3",
"eslint": "^6.1.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.2",
"expect": "^24.8.0",
"jest": "^24.8.0",
"rimraf": "^2.6.3"
},
"engines": {
"node": ">=4.0.0"
Expand All @@ -48,6 +49,9 @@
"xls"
],
"jest": {
"testEnvironment": "node"
"testEnvironment": "node",
"setupFiles": [
"<rootDir>/test/setup.js"
]
}
}
44 changes: 21 additions & 23 deletions src/helpers.js
@@ -1,19 +1,19 @@
import XLSX from 'xlsx';

const isBoolean = maybeBoolean => typeof maybeBoolean === 'boolean';
const isNumber = maybeNumber => typeof maybeNumber === 'number';
const isString = maybeString => typeof maybeString === 'string';
const isObject = maybeObject => maybeObject !== null && typeof maybeObject === 'object';
const isCellDescriptor = maybeCell => isObject(maybeCell) && 'v' in maybeCell;
const ORIGIN_DATE = new Date(Date.UTC(1899, 11, 30));

const originDate = new Date(Date.UTC(1899, 11, 30));
export const isBoolean = (maybeBoolean) => typeof maybeBoolean === 'boolean';
export const isNumber = (maybeNumber) => typeof maybeNumber === 'number';
export const isString = (maybeString) => typeof maybeString === 'string';
export const isObject = (maybeObject) => maybeObject !== null && typeof maybeObject === 'object';
export const isCellDescriptor = (maybeCell) => isObject(maybeCell) && 'v' in maybeCell;

const buildExcelDate = (value, is1904) => {
export const buildExcelDate = (value, is1904) => {
const epoch = Date.parse(value + (is1904 ? 1462 : 0));
return (epoch - originDate) / (864e5);
return (epoch - ORIGIN_DATE) / 864e5;
};

const buildSheetFromMatrix = (data, options = {}) => {
export const buildSheetFromMatrix = (data, options = {}) => {
const workSheet = {};
const range = {s: {c: 1e7, r: 1e7}, e: {c: 0, r: 0}};

Expand Down Expand Up @@ -41,18 +41,18 @@ const buildSheetFromMatrix = (data, options = {}) => {
cell.v = buildExcelDate(cell.v);
cell.z = cell.z || XLSX.SSF._table[14]; // eslint-disable-line no-underscore-dangle

/* eslint-disable spaced-comment, no-trailing-spaces */
/***
* Allows for an non-abstracted representation of the data
*
* example: {t:'n', z:10, f:'=AVERAGE(A:A)'}
*
* Documentation:
* - Cell Object: https://sheetjs.gitbooks.io/docs/#cell-object
* - Data Types: https://sheetjs.gitbooks.io/docs/#data-types
* - Format: https://sheetjs.gitbooks.io/docs/#number-formats
**/
/* eslint-disable spaced-comment, no-trailing-spaces */
/* eslint-disable spaced-comment, no-trailing-spaces */
/***
* Allows for an non-abstracted representation of the data
*
* example: {t:'n', z:10, f:'=AVERAGE(A:A)'}
*
* Documentation:
* - Cell Object: https://sheetjs.gitbooks.io/docs/#cell-object
* - Data Types: https://sheetjs.gitbooks.io/docs/#data-types
* - Format: https://sheetjs.gitbooks.io/docs/#number-formats
**/
/* eslint-disable spaced-comment, no-trailing-spaces */
} else if (isObject(cell.v)) {
cell.t = cell.v.t;
cell.f = cell.v.f;
Expand All @@ -75,5 +75,3 @@ const buildSheetFromMatrix = (data, options = {}) => {
}
return workSheet;
};

export {buildSheetFromMatrix, isBoolean, isNumber, isString, isObject, isCellDescriptor};
11 changes: 4 additions & 7 deletions src/index.js
@@ -1,18 +1,17 @@

import XLSX from 'xlsx';
import bufferFrom from 'buffer-from';
import {buildSheetFromMatrix, isString} from './helpers';
import Workbook from './workbook';

export function parse(mixed, options = {}) {
export const parse = (mixed, options = {}) => {
const workSheet = XLSX[isString(mixed) ? 'readFile' : 'read'](mixed, options);
return Object.keys(workSheet.Sheets).map((name) => {
const sheet = workSheet.Sheets[name];
return {name, data: XLSX.utils.sheet_to_json(sheet, {header: 1, raw: options.raw !== false})};
});
}
};

export function build(worksheets, options = {}) {
export const build = (worksheets, options = {}) => {
const defaults = {
bookType: 'xlsx',
bookSST: false,
Expand All @@ -28,6 +27,4 @@ export function build(worksheets, options = {}) {
});
const excelData = XLSX.write(workBook, Object.assign({}, defaults, options));
return excelData instanceof Buffer ? excelData : bufferFrom(excelData, 'binary');
}

export default {parse, build};
};
2 changes: 1 addition & 1 deletion src/workbook.js
@@ -1,5 +1,5 @@

export default class Workbook {
SheetNames = [];

Sheets = {};
}
1 change: 0 additions & 1 deletion test/.eslintrc
@@ -1,6 +1,5 @@
{
"extends": "./../.eslintrc",
"parser": "babel-eslint",
"env": {
"jest": true,
"jasmine": true
Expand Down
3 changes: 3 additions & 0 deletions test/setup.js
@@ -0,0 +1,3 @@
import registerDebugUtils from 'debug-utils';

registerDebugUtils();

0 comments on commit 97144a9

Please sign in to comment.