Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint updates #6

Merged
merged 12 commits into from
Aug 30, 2024
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git/
node_modules/
coverage/
test/
35 changes: 35 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parserOptions": {
"ecmaVersion": 2018
},
"env": {
"node": true,
"es6": true
},
"extends": ["prettier"],
"rules": {
"no-eval": 2,
"no-console": 2,
"strict": [2, "global"],
"guard-for-in": 2,
"wrap-iife": 2,
"new-cap": 0,
"no-caller": 2,
"curly": 2,
"no-bitwise": 2,
"no-empty": 2,
"no-use-before-define": 2,
"no-new": 2,
"max-depth": [2, 4],
"no-undef": 2,
"max-params": [1, 4],
"max-statements": [1, 40],
"complexity": [2, 25],
"quotes": [2, "single"],
"no-mixed-requires": 0,
"consistent-return": 0,
"no-underscore-dangle": 0,
"camelcase": 0,
"semi": 2
}
}
35 changes: 35 additions & 0 deletions .github/workflows/node-package-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
push:
branches:
- main
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://artifactory.brandwatch.com/artifactory/api/npm/npm/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
5 changes: 5 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
recursive: true,
reporter: "spec",
exit: true,
};
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.github
.mocharc.js
test
43 changes: 0 additions & 43 deletions Gruntfile.coffee

This file was deleted.

21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
node-xlsx-stream
================
# node-xlsx-stream

Creates SpreadsheetML (.xlsx) files in sequence with streaming interface.

* Installation
- Installation

npm install xlsx-stream

* Features
- Features

Multiple sheets, String, Number, Date, Duration, Cell Formats

* Usage
- Usage

# coffee-script
xlsx = require "xlsx-stream"
fs = require "fs"

x = xlsx()
x.pipe fs.createWriteStream("./out.xlsx")

x.write ["foo", "bar", "buz"]
x.write [1,2,3]
x.write ["Date", new Date]
Expand All @@ -30,10 +29,10 @@ Creates SpreadsheetML (.xlsx) files in sequence with streaming interface.

x.end()

* Multiple sheets support
- Multiple sheets support

# coffee-script

x = xlsx()
x.pipe fs.createWriteStream("./out.xlsx")

Expand All @@ -47,6 +46,6 @@ Creates SpreadsheetML (.xlsx) files in sequence with streaming interface.

x.finalize()

* Help Wanted
- Help Wanted

Comments
12 changes: 0 additions & 12 deletions a.js

This file was deleted.

118 changes: 69 additions & 49 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var archiver, duplex, sheetStream, templates, through, utils, xlsxStream, _;

through = require('through');
Expand All @@ -10,109 +12,127 @@ duplex = require('duplexer');

templates = require('./templates');

utils = require("./utils");
utils = require('./utils');

sheetStream = require("./sheet");
sheetStream = require('./sheet');

module.exports = xlsxStream = function(opts) {
var defaultRepeater, defaultSheet, index, item, proxy, sheets, styles, zip, _i, _len, _ref;
module.exports = xlsxStream = function (opts) {
var defaultRepeater,
defaultSheet,
index,
item,
proxy,
sheets,
styles,
zip,
_i,
_len,
_ref;
if (opts == null) {
opts = {};
}
zip = archiver.create('zip', opts);
defaultRepeater = through();
proxy = duplex(defaultRepeater, zip);
zip.pause();
process.nextTick(function() {
process.nextTick(function () {
return zip.resume();
});
defaultSheet = null;
sheets = [];
styles = {
numFmts: [
{
numFmtId: "0",
formatCode: ""
}
numFmtId: '0',
formatCode: '',
},
],
cellStyleXfs: [
{
numFmtId: "0",
formatCode: ""
}, {
numFmtId: "1",
formatCode: "0"
}, {
numFmtId: "14",
formatCode: "m/d/yy"
}
numFmtId: '0',
formatCode: '',
},
{
numFmtId: '1',
formatCode: '0',
},
{
numFmtId: '14',
formatCode: 'm/d/yy',
},
],
customFormatsCount: 0,
formatCodesToStyleIndex: {}
formatCodesToStyleIndex: {},
};
index = 0;
_ref = styles.cellStyleXfs;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
item = _ref[_i];
styles.formatCodesToStyleIndex[item.formatCode || ""] = index;
styles.formatCodesToStyleIndex[item.formatCode || ''] = index;
index++;
}
defaultRepeater.once('data', function(data) {
defaultRepeater.once('data', function (data) {
defaultSheet = proxy.sheet('Sheet1');
defaultSheet.write(data);
defaultRepeater.pipe(defaultSheet);
return defaultRepeater.on('end', proxy.finalize);
});
proxy.sheet = function(name) {
proxy.sheet = function (name) {
var sheet;
index = sheets.length + 1;
sheet = {
index: index,
name: name || ("Sheet" + index),
rel: "worksheets/sheet" + index + ".xml",
path: "xl/worksheets/sheet" + index + ".xml",
styles: styles
name: name || 'Sheet' + index,
rel: 'worksheets/sheet' + index + '.xml',
path: 'xl/worksheets/sheet' + index + '.xml',
styles: styles,
};
sheets.push(sheet);
return sheetStream(zip, sheet, opts);
};
proxy.finalize = function() {
proxy.finalize = function () {
var buffer, func, name, obj, sheet, _j, _len1, _ref1, _ref2, _ref3;
zip.append(templates.styles(styles), {
name: "xl/styles.xml",
store: opts.store
name: 'xl/styles.xml',
store: opts.store,
});
_ref1 = templates.statics;
for (name in _ref1) {
buffer = _ref1[name];
zip.append(buffer, {
name: name,
store: opts.store
});
if (_ref1.hasOwnProperty(name)) {
buffer = _ref1[name];
zip.append(buffer, {
name: name,
store: opts.store,
});
}
}
_ref2 = templates.semiStatics;
for (name in _ref2) {
func = _ref2[name];
zip.append(func(opts), {
name: name,
store: opts.store
});
if (_ref2.hasOwnProperty(name)) {
func = _ref2[name];
zip.append(func(opts), {
name: name,
store: opts.store,
});
}
}
_ref3 = templates.sheet_related;
for (name in _ref3) {
obj = _ref3[name];
buffer = obj.header;
for (_j = 0, _len1 = sheets.length; _j < _len1; _j++) {
sheet = sheets[_j];
buffer += obj.sheet(sheet);
if (_ref3.hasOwnProperty(name)) {
obj = _ref3[name];
buffer = obj.header;
for (_j = 0, _len1 = sheets.length; _j < _len1; _j++) {
sheet = sheets[_j];
buffer += obj.sheet(sheet);
}
buffer += obj.footer;
zip.append(buffer, {
name: name,
store: opts.store,
});
}
buffer += obj.footer;
zip.append(buffer, {
name: name,
store: opts.store
});
}
return zip.finalize(function(e, bytes) {
return zip.finalize(function (e, bytes) {
if (e != null) {
return proxy.emit('error', e);
}
Expand Down
Loading