Skip to content

Commit

Permalink
Merge 42e81b2 into f636dd1
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed May 21, 2022
2 parents f636dd1 + 42e81b2 commit ac13bc4
Show file tree
Hide file tree
Showing 24 changed files with 15,828 additions and 7,175 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
@@ -1,3 +1,5 @@
* text=auto
test/fixtures/csv/backslashBeforeNewLine.csv text eol=lf
test/fixtures/csv/eol.csv text eol=crlf
test/fixtures/csv/escapeEOL.csv text eol=crlf
test/fixtures/csv/quoteOnlyIfNecessary.csv text eol=lf
56 changes: 56 additions & 0 deletions .github/workflows/on-push.yaml
@@ -0,0 +1,56 @@
name: Node.js CI

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest] # macos-latest is too slow
node-version: [16.x, 14.x, 12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Cache Node.js modules on Linux
uses: actions/cache@v2
if: ${{ runner.OS != 'Windows' }}
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Cache Node.js modules on Windows
uses: actions/cache@v2
if: ${{ runner.OS == 'Windows' }}
with:
path: ~\AppData\Roaming\npm-cache
key: ${{ runner.os }}-node-${{ hashFiles('**\package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci
- run: npm run lint
- name: Unit tests
run: npm run test-with-coverage
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.node-version }}
parallel: true
finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
19 changes: 19 additions & 0 deletions .github/workflows/on-release.yaml
@@ -0,0 +1,19 @@
name: Node.js Publish
on:
release:
types: [published]
jobs:
build:
runs-on: Ubuntu-20.04
steps:
- uses: actions/checkout@v2
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v1
with:
node-version: '16.x'
# Needs to be explicitly specified for auth to work
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions bin/json2csv.js
Expand Up @@ -76,9 +76,9 @@ function getOutputStream(outputPath, config) {
return process.stdout;
}

async function getInput(inputPath, ndjson) {
async function getInput(inputPath, ndjson, eol) {
if (!inputPath) return getInputFromStdin();
if (ndjson) return parseNdJson(await readFile(inputPath, 'utf8'));
if (ndjson) return parseNdJson(await readFile(inputPath, 'utf8'), eol);
return require(inputPath);
}

Expand All @@ -104,15 +104,15 @@ async function getInputFromStdin() {
async function processOutput(outputPath, csv, config) {
if (!outputPath) {
// eslint-disable-next-line no-console
config.pretty ? (new TablePrinter(config)).printCSV(csv) : console.log(csv);
config.pretty ? (new TablePrinter(config)).printCSV(csv) : process.stdout.write(csv);
return;
}

await writeFile(outputPath, csv);
}

async function processInMemory(config, opts) {
const input = await getInput(program.input, config.ndjson);
const input = await getInput(program.input, config.ndjson, config.eol);
const output = new JSON2CSVParser(opts).parse(input);
await processOutput(program.output, output, config);
}
Expand Down
13 changes: 7 additions & 6 deletions bin/utils/TablePrinter.js
@@ -1,5 +1,6 @@
'use strict';

const os = require('os');
const { Writable } = require('stream');

const MIN_CELL_WIDTH = 15;
Expand Down Expand Up @@ -44,14 +45,14 @@ class TablePrinter {
}

print(top, lines, bottom) {
const table = `${top}\n`
const table = `${top}${os.EOL}`
+ lines
.map(row => this.formatRow(row))
.join(`\n${this.middleLine}\n`)
+ (bottom ? `\n${bottom}` : '');
.join(`${os.EOL}${this.middleLine}${os.EOL}`)
+ os.EOL
+ (bottom ? bottom : '');

// eslint-disable-next-line no-console
console.log(table);
process.stdout.write(table);
}

formatRow(row) {
Expand All @@ -66,7 +67,7 @@ class TablePrinter {

return Array(height).fill('')
.map((_, i) => `│${processedCells.map(cell => cell[i]).join('│')}│`)
.join('\n');
.join(os.EOL);
}

formatCell(content, heigth, width) {
Expand Down
4 changes: 2 additions & 2 deletions bin/utils/parseNdjson.js
@@ -1,8 +1,8 @@
'use strict';

function parseNdJson(input) {
function parseNdJson(input, eol) {
return input
.split('\n')
.split(eol)
.map(line => line.trim())
.filter(line => line !== '')
.map(line=> JSON.parse(line));
Expand Down
4 changes: 2 additions & 2 deletions lib/JSON2CSVStreamParser.js
Expand Up @@ -50,8 +50,8 @@ class JSON2CSVStreamParser extends JSON2CSVBase {
}

getNdJsonTokenizer(asyncOpts) {
const tokenizer = new Tokenizer({ ...asyncOpts, separator: '\n' });
this.tokenParser = new TokenParser({ paths: ['$'], keepStack: false, separator: '\n' });
const tokenizer = new Tokenizer({ ...asyncOpts, separator: this.opts.eol });
this.tokenParser = new TokenParser({ paths: ['$'], keepStack: false, separator: this.opts.eol });
this.configureCallbacks(tokenizer, this.tokenParser);
return tokenizer;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/formatters/stringQuoteOnlyIfNecessary.js
Expand Up @@ -5,7 +5,7 @@ function stringQuoteOnlyIfNecessaryFormatter(opts = {}) {
const quote = typeof opts.quote === 'string' ? opts.quote : '"';
const escapedQuote = typeof opts.escapedQuote === 'string' ? opts.escapedQuote : `${quote}${quote}`;
const separator = typeof opts.separator === 'string' ? opts.separator : ',';
const eol = typeof opts.eol === 'string' ? opts.escapedQeoluote : os.EOL;
const eol = typeof opts.eol === 'string' ? opts.eol : os.EOL;

const stringFormatter = defaulStringFormatter({ quote, escapedQuote });

Expand Down

0 comments on commit ac13bc4

Please sign in to comment.