Comparing version 0.15.0 to 0.16.0
@@ -1,28 +0,36 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.isCellDescriptor = exports.isObject = exports.isString = exports.isNumber = exports.isBoolean = exports.buildSheetFromMatrix = undefined; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.__esModule = true; | ||
exports.buildSheetFromMatrix = exports.buildExcelDate = exports.isCellDescriptor = exports.isObject = exports.isString = exports.isNumber = exports.isBoolean = void 0; | ||
var _xlsx = require('xlsx'); | ||
var _xlsx = _interopRequireDefault(require("xlsx")); | ||
var _xlsx2 = _interopRequireDefault(_xlsx); | ||
var ORIGIN_DATE = new Date(Date.UTC(1899, 11, 30)); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var isBoolean = function isBoolean(maybeBoolean) { | ||
return typeof maybeBoolean === 'boolean'; | ||
}; | ||
exports.isBoolean = isBoolean; | ||
var isNumber = function isNumber(maybeNumber) { | ||
return typeof maybeNumber === 'number'; | ||
}; | ||
exports.isNumber = isNumber; | ||
var isString = function isString(maybeString) { | ||
return typeof maybeString === 'string'; | ||
}; | ||
exports.isString = isString; | ||
var isObject = function isObject(maybeObject) { | ||
return maybeObject !== null && (typeof maybeObject === 'undefined' ? 'undefined' : _typeof(maybeObject)) === 'object'; | ||
return maybeObject !== null && typeof maybeObject === 'object'; | ||
}; | ||
exports.isObject = isObject; | ||
var isCellDescriptor = function isCellDescriptor(maybeCell) { | ||
@@ -32,15 +40,27 @@ return isObject(maybeCell) && 'v' in maybeCell; | ||
var originDate = new Date(Date.UTC(1899, 11, 30)); | ||
exports.isCellDescriptor = isCellDescriptor; | ||
var buildExcelDate = function buildExcelDate(value, is1904) { | ||
var epoch = Date.parse(value + (is1904 ? 1462 : 0)); | ||
return (epoch - originDate) / 864e5; | ||
return (epoch - ORIGIN_DATE) / 864e5; | ||
}; | ||
var buildSheetFromMatrix = function buildSheetFromMatrix(data) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
exports.buildExcelDate = buildExcelDate; | ||
var buildSheetFromMatrix = function buildSheetFromMatrix(data, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var workSheet = {}; | ||
var range = { s: { c: 1e7, r: 1e7 }, e: { c: 0, r: 0 } }; | ||
var range = { | ||
s: { | ||
c: 1e7, | ||
r: 1e7 | ||
}, | ||
e: { | ||
c: 0, | ||
r: 0 | ||
} | ||
}; | ||
if (!Array.isArray(data)) throw new Error('sheet data is not array'); | ||
@@ -50,4 +70,3 @@ | ||
for (var C = 0; C !== data[R].length; C += 1) { | ||
if (!Array.isArray(data[R])) throw new Error(R + 'th row data is not array'); | ||
if (!Array.isArray(data[R])) throw new Error(`${R}th row data is not array`); | ||
if (range.s.r > R) range.s.r = R; | ||
@@ -57,7 +76,16 @@ if (range.s.c > C) range.s.c = C; | ||
if (range.e.c < C) range.e.c = C; | ||
if (data[R][C] === null) { | ||
continue; // eslint-disable-line | ||
} | ||
var cell = isCellDescriptor(data[R][C]) ? data[R][C] : { v: data[R][C] }; | ||
var cellRef = _xlsx2.default.utils.encode_cell({ c: C, r: R }); | ||
var cell = isCellDescriptor(data[R][C]) ? data[R][C] : { | ||
v: data[R][C] | ||
}; | ||
var cellRef = _xlsx.default.utils.encode_cell({ | ||
c: C, | ||
r: R | ||
}); | ||
if (isNumber(cell.v)) { | ||
@@ -70,10 +98,11 @@ cell.t = 'n'; | ||
cell.v = buildExcelDate(cell.v); | ||
cell.z = cell.z || _xlsx2.default.SSF._table[14]; // eslint-disable-line no-underscore-dangle | ||
cell.z = cell.z || _xlsx.default.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: | ||
@@ -84,2 +113,3 @@ * - Cell Object: https://sheetjs.gitbooks.io/docs/#cell-object | ||
**/ | ||
/* eslint-disable spaced-comment, no-trailing-spaces */ | ||
@@ -93,15 +123,21 @@ } else if (isObject(cell.v)) { | ||
} | ||
if (isNumber(cell.z)) cell.z = _xlsx2.default.SSF._table[cell.z]; // eslint-disable-line no-underscore-dangle | ||
if (isNumber(cell.z)) cell.z = _xlsx.default.SSF._table[cell.z]; // eslint-disable-line no-underscore-dangle | ||
workSheet[cellRef] = cell; | ||
} | ||
} | ||
if (range.s.c < 1e7) { | ||
workSheet['!ref'] = _xlsx2.default.utils.encode_range(range); | ||
workSheet['!ref'] = _xlsx.default.utils.encode_range(range); | ||
} | ||
if (options['!cols']) { | ||
workSheet['!cols'] = options['!cols']; | ||
} | ||
if (options['!merges']) { | ||
workSheet['!merges'] = options['!merges']; | ||
} | ||
return workSheet; | ||
@@ -111,7 +147,2 @@ }; | ||
exports.buildSheetFromMatrix = buildSheetFromMatrix; | ||
exports.isBoolean = isBoolean; | ||
exports.isNumber = isNumber; | ||
exports.isString = isString; | ||
exports.isObject = isObject; | ||
exports.isCellDescriptor = isCellDescriptor; | ||
//# sourceMappingURL=helpers.js.map |
@@ -1,41 +0,63 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
exports.__esModule = true; | ||
exports.default = exports.build = exports.parseMetadata = exports.parse = void 0; | ||
exports.parse = parse; | ||
exports.build = build; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _xlsx = require('xlsx'); | ||
var _xlsx = _interopRequireDefault(require("xlsx")); | ||
var _xlsx2 = _interopRequireDefault(_xlsx); | ||
var _bufferFrom = _interopRequireDefault(require("buffer-from")); | ||
var _bufferFrom = require('buffer-from'); | ||
var _helpers = require("./helpers"); | ||
var _bufferFrom2 = _interopRequireDefault(_bufferFrom); | ||
var _workbook = _interopRequireDefault(require("./workbook")); | ||
var _helpers = require('./helpers'); | ||
var parse = function parse(mixed, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var _workbook = require('./workbook'); | ||
var workSheet = _xlsx.default[(0, _helpers.isString)(mixed) ? 'readFile' : 'read'](mixed, options); | ||
var _workbook2 = _interopRequireDefault(_workbook); | ||
return Object.keys(workSheet.Sheets).map(function (name) { | ||
var sheet = workSheet.Sheets[name]; | ||
return { | ||
name, | ||
data: _xlsx.default.utils.sheet_to_json(sheet, { | ||
header: 1, | ||
raw: options.raw !== false, | ||
range: options.range ? options.range[name] : null | ||
}) | ||
}; | ||
}); | ||
}; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.parse = parse; | ||
function parse(mixed) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var parseMetadata = function parseMetadata(mixed, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var workSheet = _xlsx2.default[(0, _helpers.isString)(mixed) ? 'readFile' : 'read'](mixed, options); | ||
var workSheet = _xlsx.default[(0, _helpers.isString)(mixed) ? 'readFile' : 'read'](mixed, options); | ||
return Object.keys(workSheet.Sheets).map(function (name) { | ||
var sheet = workSheet.Sheets[name]; | ||
return { name: name, data: _xlsx2.default.utils.sheet_to_json(sheet, { header: 1, raw: options.raw !== false }) }; | ||
return { | ||
name, | ||
data: sheet["!ref"] ? _xlsx.default.utils.decode_range(sheet["!ref"]) : null | ||
}; | ||
}); | ||
} | ||
}; | ||
function build(worksheets) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
exports.parseMetadata = parseMetadata; | ||
var build = function build(worksheets, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var defaults = { | ||
@@ -46,15 +68,23 @@ bookType: 'xlsx', | ||
}; | ||
var workBook = new _workbook2.default(); | ||
var workBook = new _workbook.default(); | ||
worksheets.forEach(function (worksheet) { | ||
var sheetName = worksheet.name || 'Sheet'; | ||
var sheetOptions = worksheet.options || {}; | ||
var sheetData = (0, _helpers.buildSheetFromMatrix)(worksheet.data || [], _extends({}, options, sheetOptions)); | ||
var sheetData = (0, _helpers.buildSheetFromMatrix)(worksheet.data || [], (0, _extends2.default)({}, options, sheetOptions)); | ||
workBook.SheetNames.push(sheetName); | ||
workBook.Sheets[sheetName] = sheetData; | ||
}); | ||
var excelData = _xlsx2.default.write(workBook, Object.assign({}, defaults, options)); | ||
return excelData instanceof Buffer ? excelData : (0, _bufferFrom2.default)(excelData, 'binary'); | ||
} | ||
exports.default = { parse: parse, build: build }; | ||
var excelData = _xlsx.default.write(workBook, (0, _extends2.default)({}, defaults, options)); | ||
return excelData instanceof Buffer ? excelData : (0, _bufferFrom.default)(excelData, 'binary'); | ||
}; | ||
exports.build = build; | ||
var _default = { | ||
parse, | ||
parseMetadata, | ||
build | ||
}; | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var Workbook = function Workbook() { | ||
_classCallCheck(this, Workbook); | ||
this.SheetNames = []; | ||
this.Sheets = {}; | ||
(0, _defineProperty2.default)(this, "SheetNames", []); | ||
(0, _defineProperty2.default)(this, "Sheets", {}); | ||
}; | ||
@@ -15,0 +14,0 @@ |
{ | ||
"name": "node-xlsx", | ||
"author": "Olivier Louvignes <olivier@mg-crea.com>", | ||
"version": "0.15.0", | ||
"version": "0.16.0", | ||
"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" | ||
}, | ||
@@ -20,21 +20,22 @@ "repository": "github:mgcrea/node-xlsx", | ||
"dependencies": { | ||
"buffer-from": "^1.1.0", | ||
"xlsx": "^0.14.1" | ||
"buffer-from": "^1.1.1", | ||
"xlsx": "^0.16.8" | ||
}, | ||
"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.12.1", | ||
"@babel/core": "^7.12.3", | ||
"@babel/plugin-proposal-class-properties": "^7.12.1", | ||
"@babel/plugin-transform-runtime": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"@babel/runtime": "^7.12.5", | ||
"babel-eslint": "^10.1.0", | ||
"codacy-coverage": "^3.4.0", | ||
"debug-utils": "^0.5.3", | ||
"eslint": "^7.13.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"expect": "^26.6.2", | ||
"jest": "^24.8.0", | ||
"rimraf": "^3.0.2" | ||
}, | ||
@@ -52,4 +53,7 @@ "engines": { | ||
"jest": { | ||
"testEnvironment": "node" | ||
"testEnvironment": "node", | ||
"setupFiles": [ | ||
"<rootDir>/test/setup.js" | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26772
185
16
1
+ Addedfflate@0.3.11(transitive)
+ Addedssf@0.11.2(transitive)
+ Addedwmf@1.0.2(transitive)
+ Addedword@0.3.0(transitive)
+ Addedxlsx@0.16.9(transitive)
- Removedssf@0.10.3(transitive)
- Removedxlsx@0.14.5(transitive)
Updatedbuffer-from@^1.1.1
Updatedxlsx@^0.16.8