Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
sync: refactor internal variables
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jul 23, 2018
1 parent c0c6105 commit fdc88ce
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@

## Trunk

* sync: refactor internal variables
* index: use destructuring assignment for deps

## Version 2.5.0
Expand Down
5 changes: 3 additions & 2 deletions lib/es5/index.js
Expand Up @@ -20,8 +20,6 @@ stream = require('stream');

util = require('util');

StringDecoder = require('string_decoder').StringDecoder;

// ## Usage

// Callback approach, for ease of use:
Expand All @@ -31,6 +29,9 @@ StringDecoder = require('string_decoder').StringDecoder;
// [Node.js Stream API][stream], for maximum of power:

// `parse([options], [callback])`
var _require = require('string_decoder');

StringDecoder = _require.StringDecoder;
module.exports = function () {
var callback, called, chunks, data, err, options, parser;
if (arguments.length === 3) {
Expand Down
14 changes: 7 additions & 7 deletions lib/es5/sync.js
Expand Up @@ -5,7 +5,7 @@

// Provides a synchronous alternative to the CSV parser.

// Usage: `records = parse(data, [options]`
// Usage: `const records = parse(data, [options]`
var StringDecoder, parse;

var _require = require('string_decoder');
Expand All @@ -18,18 +18,18 @@ parse = require('./index');
module.exports = function (data) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var decoder, err, parser, records;
records = options.objname ? {} : [];
var chunks, decoder, err, parser;
chunks = options.objname ? {} : [];
if (data instanceof Buffer) {
decoder = new StringDecoder();
data = decoder.write(data);
}
parser = new parse.Parser(options);
parser.push = function (record) {
parser.push = function (chunk) {
if (options.objname) {
return records[record[0]] = record[1];
return chunks[chunk[0]] = chunk[1];
} else {
return records.push(record);
return chunks.push(chunk);
}
};
err = parser.__write(data, false);
Expand All @@ -46,5 +46,5 @@ module.exports = function (data) {
if (err) {
throw err;
}
return records;
return chunks;
};
2 changes: 1 addition & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions lib/sync.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/sync.coffee.md
Expand Up @@ -3,27 +3,27 @@

Provides a synchronous alternative to the CSV parser.

Usage: `records = parse(data, [options]`
Usage: `const records = parse(data, [options]`

{StringDecoder} = require 'string_decoder'
parse = require './index'
module.exports = (data, options={})->
records = if options.objname then {} else []
chunks = if options.objname then {} else []
if data instanceof Buffer
decoder = new StringDecoder()
data = decoder.write data
parser = new parse.Parser options
parser.push = (record) ->
parser.push = (chunk) ->
if options.objname
records[record[0]] = record[1]
chunks[chunk[0]] = chunk[1]
else
records.push record
chunks.push chunk
err = parser.__write data, false
throw err if err
if data instanceof Buffer
err = parser.__write data.end(), true
throw err if err
err = parser.__flush()
throw err if err
records
chunks

0 comments on commit fdc88ce

Please sign in to comment.