Skip to content

Commit

Permalink
new release
Browse files Browse the repository at this point in the history
  • Loading branch information
onhernandes committed Sep 17, 2020
1 parent bf20707 commit da75932
Show file tree
Hide file tree
Showing 16 changed files with 31,946 additions and 15,088 deletions.
12,271 changes: 8,931 additions & 3,340 deletions docs/ast/source/strategies/Csv.js.json

Large diffs are not rendered by default.

33,420 changes: 21,854 additions & 11,566 deletions docs/ast/source/strategies/Xml/index.js.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 10 additions & 8 deletions docs/coverage.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"coverage": "50.79%",
"expectCount": 63,
"actualCount": 32,
"coverage": "51.47%",
"expectCount": 68,
"actualCount": 35,
"files": {
"src/Parser.js": {
"expectCount": 8,
Expand Down Expand Up @@ -38,13 +38,15 @@
]
},
"src/strategies/Csv.js": {
"expectCount": 7,
"actualCount": 3,
"expectCount": 11,
"actualCount": 5,
"undocumentLines": [
1,
2,
3,
4
4,
5,
6
]
},
"src/strategies/Json.js": {
Expand All @@ -67,8 +69,8 @@
]
},
"src/strategies/Xml/index.js": {
"expectCount": 13,
"actualCount": 6,
"expectCount": 14,
"actualCount": 7,
"undocumentLines": [
1,
2,
Expand Down
56 changes: 48 additions & 8 deletions docs/file/src/strategies/Csv.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
const ParserError = require('../errors/ParserError')
const csvParser = require('csv-parse/lib/sync')
const csvStringify = require('csv-stringify/lib/sync')
const csvParserStream = require('csv-parse')
const csvStringifyStream = require('csv-stringify')

/**
* Csv - Support for CSV filetype
Expand All @@ -52,11 +54,11 @@
* Csv.prototype.parse - receives an CSV string and returns valid JS
*
* @param {string} data
* @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
* @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}
*/
Csv.prototype.parse = function parse (data, options = {}) {
Expand Down Expand Up @@ -98,9 +100,9 @@
* Csv.prototype.stringify - receives * valid JS data and returns it as CSV
*
* @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}
*/
Csv.prototype.stringify = function stringify (data, options = {}) {
Expand All @@ -119,6 +121,44 @@
return csvStringify(data, config)
}

/**
* 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
</code></pre>

Expand Down
72 changes: 66 additions & 6 deletions docs/file/src/strategies/Xml/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
* Xml.prototype.stringify - receives * valid JS data and returns it as XML
*
* @param {(object|array)} data
* @param {Object} options - options for turning JS data into XML
* @param {boolean} options.ignoreDeclaration - don&apos;t output XML version tag, default is true
* @param {Object} [options] - options for turning JS data into XML
* @param {boolean} [options.ignoreDeclaration] - don&apos;t output XML version tag, default is true
* @returns {string}
*/
Xml.prototype.stringify = function stringify (data, options = {}) {
Expand All @@ -117,10 +117,10 @@
* Xml.prototype.parse - receives an XML string and translate it to valid JavaScript
*
* @param {string} data
* @param {object} options
* @param {object} options.showDeclaration - force parsing XML declaration tag
* @param {boolean} options.verbose - makes xml2js return non compact mode, defaults to false
* @param {boolean} options.experimentalXmlTag - use experimental XmlTag prototype, default is false
* @param {object} [options]
* @param {boolean} [options.showDeclaration] - force parsing XML declaration tag
* @param {boolean} [options.verbose] - makes xml2js return non compact mode, defaults to false
* @param {boolean} [options.experimentalXmlTag] - use experimental XmlTag prototype, default is false
* @throws {NotImplemented} This method must be implemented
*/
Xml.prototype.parse = function parse (data, options = {}) {
Expand Down Expand Up @@ -313,6 +313,66 @@
})
}

/**
* Xml.prototype.pipeStringify - stream from JS data into XML
*
* @param {object} [options] - all options to stringify
* @param {object} [options.mainTag] - the wrapping tag
* @param {string} [options.mainTag.name] - the wrapping tag&apos;s name
*/
Xml.prototype.pipeStringify = function pipeStringify (options = {}) {
options.mainTag = options.mainTag || {}
const defaultContent = &apos;FAKE_CONTENT&apos;
const name = options.mainTag.name
const contents = options.mainTag.text || defaultContent
const tag = { [name || &apos;fake&apos;]: contents }
const stringified = this.stringify(tag)

const lastIndexOfArrow = stringified.lastIndexOf(&apos;&lt;&apos;)
let initialTag = stringified.substr(0, lastIndexOfArrow)

if (initialTag.indexOf(defaultContent) !== -1) {
initialTag.replace(defaultContent, &apos;&apos;)
}

let endingTag = stringified.substr(
lastIndexOfArrow,
stringified.length
)

if (Reflect.has(options.mainTag, &apos;name&apos;) === false) {
const firstArrowIndex = initialTag.indexOf(&apos;&gt;&apos;) + 1
initialTag = initialTag.substr(0, firstArrowIndex)
endingTag = &apos;&apos;
}

const xml = this
let isFirstData = true

return new Transform({
objectMode: true,
transform (chunk, encoding, ack) {
const options = {
ignoreDeclaration: true
}

if (isFirstData) {
this.push(initialTag)
isFirstData = false
}

const toBePushed = xml.stringify(chunk, options)
this.push(toBePushed)

ack()
},
flush (cb) {
this.push(endingTag)
cb()
}
})
}

module.exports = Xml
</code></pre>

Expand Down
Loading

0 comments on commit da75932

Please sign in to comment.