oniyi-utils-xml
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -12,4 +12,4 @@ 'use strict'; | ||
const DOMParser = xmldom.DOMParser; | ||
const XMLSerializer = xmldom.XMLSerializer; | ||
const { DOMParser } = xmldom; | ||
const { XMLSerializer } = xmldom; | ||
@@ -25,34 +25,46 @@ const parse = (xmlString, mimeType = 'text/xml', parserOptions = {}) => { | ||
const serialize = (...args) => (new XMLSerializer()).serializeToString(...args); | ||
const serialize = (...args) => new XMLSerializer().serializeToString(...args); | ||
const select = (...args) => xpath.select(...args); | ||
const ensureXMLDoc = stringOrXMLDoc => (_.isString(stringOrXMLDoc) && parse(stringOrXMLDoc)) || stringOrXMLDoc; | ||
const ensureXMLDoc = stringOrXMLDoc => | ||
(_.isString(stringOrXMLDoc) && parse(stringOrXMLDoc)) || stringOrXMLDoc; | ||
const parseXMLNode = (node, selectors, xpathSelect) => | ||
_.reduce(selectors, (result, value, selectorKey) => { | ||
// normalize the selector value to a spec object for future steps | ||
const spec = ((input) => { | ||
if (_.isPlainObject(input)) { return input; } | ||
if (_.isString(input)) { return { selector: input }; } | ||
return undefined; | ||
})(value); | ||
_.reduce( | ||
selectors, | ||
(result, value, selectorKey) => { | ||
// normalize the selector value to a spec object for future steps | ||
const spec = (input => { | ||
if (_.isPlainObject(input)) { | ||
return input; | ||
} | ||
if (_.isString(input)) { | ||
return { selector: input }; | ||
} | ||
return undefined; | ||
})(value); | ||
if (!_.isPlainObject(spec)) { return result; } | ||
if (!_.isPlainObject(spec)) { | ||
return result; | ||
} | ||
const selected = xpathSelect(spec.selector, node, !spec.multi); | ||
if (_.isUndefined(selected)) { return result; } | ||
const selected = xpathSelect(spec.selector, node, !spec.multi); | ||
if (_.isUndefined(selected)) { | ||
return result; | ||
} | ||
if (!_.isFunction(spec.transform)) { | ||
if (!_.isFunction(spec.transform)) { | ||
/* beautify preserve:start */ | ||
return Object.assign(result, { [selectorKey]: selected }); | ||
/* beautify preserve:end */ | ||
} | ||
/* beautify preserve:start */ | ||
return Object.assign(result, { [selectorKey]: selected }); | ||
return Object.assign(result, { [selectorKey]: spec.transform(selected) }); | ||
/* beautify preserve:end */ | ||
} | ||
}, | ||
{}, | ||
); | ||
/* beautify preserve:start */ | ||
return Object.assign(result, { [selectorKey]: spec.transform(selected) }); | ||
/* beautify preserve:end */ | ||
}, {}); | ||
module.exports = { | ||
@@ -59,0 +71,0 @@ parse, |
@@ -7,4 +7,4 @@ /* eslint-disable no-underscore-dangle */ | ||
const util = require('util'); | ||
const StringDecoder = require('string_decoder').StringDecoder; | ||
const Transform = require('stream').Transform; | ||
const { StringDecoder } = require('string_decoder'); | ||
const { Transform } = require('stream'); | ||
@@ -25,3 +25,3 @@ // 3rd party modules | ||
this._encoding = (Buffer.isEncoding(encoding)) ? encoding : 'utf8'; | ||
this._encoding = Buffer.isEncoding(encoding) ? encoding : 'utf8'; | ||
this._decoder = new StringDecoder(this._encoding); | ||
@@ -32,3 +32,7 @@ this._buffer = ''; | ||
XMLParseStream.prototype._transform = function transform(data, encoding, callback) { | ||
XMLParseStream.prototype._transform = function transform( | ||
data, | ||
encoding, | ||
callback, | ||
) { | ||
// concatenate decoded string chunks in _buffer | ||
@@ -35,0 +39,0 @@ this._buffer += this._decoder.write(data); |
@@ -7,3 +7,3 @@ /* eslint-disable no-underscore-dangle */ | ||
const util = require('util'); | ||
const Transform = require('stream').Transform; | ||
const { Transform } = require('stream'); | ||
@@ -26,3 +26,7 @@ // 3rd party modules | ||
XMLSerializeStream.prototype._transform = function transform(xmlDocument, encoding, callback) { | ||
XMLSerializeStream.prototype._transform = function transform( | ||
xmlDocument, | ||
encoding, | ||
callback, | ||
) { | ||
try { | ||
@@ -29,0 +33,0 @@ const xmlString = serialize(xmlDocument); |
{ | ||
"name": "oniyi-utils-xml", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "utils for handling xml data", | ||
@@ -27,15 +27,23 @@ "author": "Benjamin Kroeger <benjamin.kroeger@gmail.com>", | ||
"dependencies": { | ||
"lodash": "4.17.4", | ||
"lodash": "4.17.11", | ||
"xmldom": "0.1.27", | ||
"xpath": "0.0.24" | ||
"xpath": "0.0.27" | ||
}, | ||
"devDependencies": { | ||
"ava": "0.21.0", | ||
"eslint": "3.15.0", | ||
"eslint-config-oniyi": "4.4.0", | ||
"eslint-plugin-ava": "4.2.1" | ||
"ava": "1.4.1", | ||
"eslint": "5.16.0", | ||
"eslint-config-airbnb-base": "13.1.0", | ||
"eslint-config-prettier": "4.1.0", | ||
"eslint-plugin-ava": "6.0.0", | ||
"eslint-plugin-import": "2.16.0", | ||
"eslint-plugin-prettier": "3.0.1", | ||
"husky": "1.3.1", | ||
"jest": "24.7.1", | ||
"lint-staged": "8.1.5", | ||
"prettier": "1.16.4" | ||
}, | ||
"scripts": { | ||
"lint-fix": "eslint . --fix", | ||
"format": "prettier --write \"**/*.{js,json}\"", | ||
"lint": "eslint .", | ||
"pretest": "eslint .", | ||
"test": "ava --verbose" | ||
@@ -42,0 +50,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6577
148
11
6
+ Addedlodash@4.17.11(transitive)
+ Addedxpath@0.0.27(transitive)
- Removedlodash@4.17.4(transitive)
- Removedxpath@0.0.24(transitive)
Updatedlodash@4.17.11
Updatedxpath@0.0.27