parserblade
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "parserblade", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "The easiest parser for JSON, XML, CSV and YAML. Use it as simple as JSON.stringify() or JSON.parse(). All in one place.", | ||
@@ -18,8 +18,16 @@ "homepage": "https://onhernandes.github.io/parserblade", | ||
"data-parser", | ||
"stream", | ||
"stream-parser", | ||
"streaming-parser", | ||
"csv-parser", | ||
"csv-parser-stream", | ||
"csv-stringify", | ||
"csv-stringify-stream", | ||
"transform-csv", | ||
"csv-streaming", | ||
"csv", | ||
"yaml-parser", | ||
"yaml-stringify", | ||
"yaml-stringify-stream", | ||
"yaml-parser-stream", | ||
"transform-yaml", | ||
@@ -29,6 +37,11 @@ "yaml", | ||
"xml-stringify", | ||
"xml-parser-stream", | ||
"xml-stringify-stream", | ||
"transform-xml", | ||
"xml", | ||
"json", | ||
"json-parser" | ||
"json-parser", | ||
"json-stringify", | ||
"json-stringify-stream", | ||
"json-parser-stream" | ||
], | ||
@@ -78,7 +91,9 @@ "devDependencies": { | ||
"dependencies": { | ||
"JSONStream": "^1.3.5", | ||
"csv-parse": "^4.11.1", | ||
"csv-stringify": "^5.5.0", | ||
"js-yaml": "^3.14.0", | ||
"node-xml-stream": "^1.0.2", | ||
"xml-js": "^1.6.11" | ||
} | ||
} |
@@ -41,2 +41,16 @@ /** | ||
/** | ||
* Parser.prototype.pipeStringify - Exposes the pipeStringify() method from strategy. Streams data through stringify | ||
*/ | ||
Parser.prototype.pipeStringify = function pipeStringify () { | ||
return this.strategy.pipeStringify() | ||
} | ||
/** | ||
* Parser.prototype.pipeParse - Exposes the pipeParse() method from strategy. Streams data through parse | ||
*/ | ||
Parser.prototype.pipeParse = function pipeParse () { | ||
return this.strategy.pipeParse() | ||
} | ||
Parser.prototype.get = function get (data, path) {} | ||
@@ -43,0 +57,0 @@ |
@@ -63,2 +63,20 @@ const NotImplemented = require('../errors/NotImplemented') | ||
/** | ||
* Base.prototype.pipeParse - prototype for streams | ||
* | ||
* @throws {NotImplemented} This method must be implemented | ||
*/ | ||
Base.prototype.pipeParse = function pipeParse () { | ||
throw new NotImplemented() | ||
} | ||
/** | ||
* Base.prototype.pipeStringify - prototype for streams | ||
* | ||
* @throws {NotImplemented} This method must be implemented | ||
*/ | ||
Base.prototype.pipeStringify = function pipeStringify () { | ||
throw new NotImplemented() | ||
} | ||
module.exports = Base |
@@ -5,2 +5,4 @@ const Base = require('./Base') | ||
const csvStringify = require('csv-stringify/lib/sync') | ||
const csvParserStream = require('csv-parse') | ||
const csvStringifyStream = require('csv-stringify') | ||
@@ -20,7 +22,7 @@ /** | ||
* @param {string} data | ||
* @param {object} options | ||
* @param {boolean} options.headers - If should parse first line as the headers, default is true | ||
* @param {(string|Buffer)} options.delimiter - Which delimiters to use when parsing, defaults to comma `,` | ||
* @param {number} options.skipLines - How many lines it should skip before parsing, defaults to 1 | ||
* @param {number} options.offset - How many lines it should parse, defaults to -1 | ||
* @param {object} [options] | ||
* @param {(boolean|array|function)} [options.headers] - If should parse first line as the headers, default is true | ||
* @param {(string|Buffer)} [options.delimiter] - Which delimiters to use when parsing, defaults to comma `,` | ||
* @param {number} [options.skipLines] - How many lines it should skip before parsing, defaults to 1 | ||
* @param {number} [options.offset] - How many lines it should parse, defaults to -1 | ||
* @returns {array} | ||
@@ -36,4 +38,4 @@ */ | ||
if (options.headers === false) { | ||
config.columns = false | ||
if (Object.prototype.hasOwnProperty.apply(options, ['headers'])) { | ||
config.columns = options.headers | ||
} | ||
@@ -68,5 +70,5 @@ | ||
* @param {array} data | ||
* @param {object} options | ||
* @param {boolean} options.headers - If should set first line as the headers, default is true | ||
* @param {(array|object)} options.columns - Custom column mapping, see examples for more | ||
* @param {object} [options] | ||
* @param {boolean} [options.headers] - If should set first line as the headers, default is true | ||
* @param {(array|object)} [options.columns] - Custom column mapping, see examples for more | ||
* @returns {string} | ||
@@ -90,2 +92,40 @@ */ | ||
/** | ||
* Csv.prototype.pipeParse - allow streaming data | ||
* | ||
* @param {object} [options] | ||
* @param {(boolean|array|function)} [options.headers] - If should parse first line as the headers, default is true | ||
* @param {string} [options.delimiter] - Which delimiters to use when parsing, defaults to comma `,` | ||
*/ | ||
Csv.prototype.pipeParse = function pipeParse (options = {}) { | ||
const config = { | ||
delimiter: options.delimiter || ',', | ||
columns: Reflect.has(options, 'headers') ? options.headers : true | ||
} | ||
return csvParserStream(config) | ||
} | ||
/** | ||
* Csv.prototype.pipeStringify - stream | ||
* | ||
* @param {array} data | ||
* @param {object} [options] | ||
* @param {boolean} [options.headers] - If should set first line as the headers, default is true | ||
* @param {string} [options.delimiter] - Which delimiters to use when parsing, defaults to comma `,` | ||
* @param {(array|object)} [options.columns] - Custom column mapping, see examples for more | ||
*/ | ||
Csv.prototype.pipeStringify = function pipeStringify (options = {}) { | ||
const config = { | ||
delimiter: options.delimiter || ',', | ||
header: Reflect.has(options, 'headers') ? !!options.headers : true | ||
} | ||
if (Reflect.has(options, 'columns')) { | ||
config.columns = options.columns | ||
} | ||
return csvStringifyStream(config) | ||
} | ||
module.exports = Csv |
const Base = require('./Base') | ||
const ParserError = require('../errors/ParserError') | ||
const JSONStream = require('JSONStream') | ||
@@ -38,2 +39,36 @@ /** | ||
/** | ||
* Json.prototype.pipeStringify - helps to stream object or array into JSON valid data | ||
* | ||
* @param {object} [config] - sets config for stream | ||
* @param {string} [config.type='array'] - which type of data you're streaming, defaults do array | ||
* @returns {WritableStream} | ||
*/ | ||
Json.prototype.pipeStringify = function pipeStringify (config = {}) { | ||
config.type = config.type || 'array' | ||
const streams = { | ||
object: JSONStream.stringifyObject, | ||
array: JSONStream.stringify | ||
} | ||
const fn = streams[config.type] | ||
if (!fn) { | ||
throw new ParserError(`Supplied type "${config.type}" is not allowed. Use either "array" or "object"`) | ||
} | ||
return fn() | ||
} | ||
/** | ||
* Json.prototype.pipeStringify - helps to stream JSON data to JS | ||
* | ||
* @param {object} [config] - sets config for stream | ||
* @param {string} [config.path] - select which data path to be parsed from JSON to JS | ||
* @returns {Stream} | ||
*/ | ||
Json.prototype.pipeParse = function pipeParse (config) { | ||
return JSONStream.parse() | ||
} | ||
module.exports = Json |
25244
14
686
6
+ AddedJSONStream@^1.3.5
+ Addednode-xml-stream@^1.0.2
+ AddedJSONStream@1.3.5(transitive)
+ Addedjsonparse@1.3.1(transitive)
+ Addednode-xml-stream@1.0.2(transitive)
+ Addedthrough@2.3.8(transitive)