UNPKG

read-excel-file

Version:

Read `.xlsx` files in a web browser or in Node.js

41 lines (39 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = readSheet; var _parseXml = _interopRequireDefault(require("../xml/parseXml.js")); var _unpackXlsxFileUniversal = _interopRequireDefault(require("./unpackXlsxFileUniversal.js")); var _parseSheet = _interopRequireDefault(require("./parseSheet.js")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } // There seems to be no way to access Node.js `Worker` // other than explicitly `import`ing it from the "worker_threads" module. // It's in contrast to web browsers where the `Worker` class is accessible through a global variable. // // The requirement for an explicit `import` of a "native" module in Node.js // means that it's not really possible to write a "universal" worker implementation // because what works in Node.js won't work in a web browser due to the absence of the "native" module. // // So there seems to be no way to use `Worker` in a "universal" export. // var createWorkerFunction = undefined; /** * Reads a single sheet from an `.xlsx` file. * @param {(Blob|ArrayBuffer)} input * @param {(number|string)} [sheet] — Sheet number or sheet name * @param {object} [options] * @return {Promise<SheetData>} */ function readSheet(input, sheet, options) { // `sheet` argument is optional. // It could be omitted while `options` argument is passed. if (!options && sheet && typeof sheet !== 'number' && typeof sheet !== 'string') { options = sheet; sheet = undefined; } return (0, _unpackXlsxFileUniversal["default"])(input).then(function (contents) { return (0, _parseSheet["default"])(createWorkerFunction, _parseXml["default"], contents, sheet, options); }); } //# sourceMappingURL=readSheetUniversal.js.map