oniyi-utils-xml
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -8,3 +8,3 @@ 'use strict'; | ||
const xpath = require('xpath'); | ||
const isString = require('lodash.isstring'); | ||
const _ = require('lodash'); | ||
@@ -17,3 +17,3 @@ // internal modules | ||
const parse = (xmlString, mimeType = 'text/xml', parserOptions = {}) => { | ||
const safeMimeType = (isString(mimeType) && mimeType) || 'text/xml'; | ||
const safeMimeType = (_.isString(mimeType) && mimeType) || 'text/xml'; | ||
@@ -30,4 +30,30 @@ const parser = new DOMParser(parserOptions); | ||
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); | ||
if (!_.isPlainObject(spec)) { return result; } | ||
const selected = xpathSelect(spec.selector, node, !spec.multi); | ||
if (_.isUndefined(selected)) { return result; } | ||
if (!_.isFunction(spec.transform)) { | ||
/* beautify preserve:start */ | ||
return Object.assign(result, { [selectorKey]: selected }); | ||
/* beautify preserve:end */ | ||
} | ||
/* beautify preserve:start */ | ||
return Object.assign(result, { [selectorKey]: spec.transform(selected) }); | ||
/* beautify preserve:end */ | ||
}, {}); | ||
module.exports = { | ||
@@ -39,2 +65,3 @@ parse, | ||
ensureXMLDoc, | ||
parseXMLNode, | ||
}; |
{ | ||
"name": "oniyi-utils-xml", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "utils for handling xml data", | ||
@@ -27,8 +27,8 @@ "author": "Benjamin Kroeger <benjamin.kroeger@gmail.com>", | ||
"dependencies": { | ||
"lodash.isstring": "4.0.1", | ||
"xmldom": "0.1.19", | ||
"lodash": "4.17.4", | ||
"xmldom": "0.1.27", | ||
"xpath": "0.0.24" | ||
}, | ||
"devDependencies": { | ||
"ava": "0.19.1", | ||
"ava": "0.21.0", | ||
"eslint": "3.15.0", | ||
@@ -35,0 +35,0 @@ "eslint-config-oniyi": "4.4.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
6259
130
+ Addedlodash@4.17.4
+ Addedlodash@4.17.4(transitive)
+ Addedxmldom@0.1.27(transitive)
- Removedlodash.isstring@4.0.1
- Removedlodash.isstring@4.0.1(transitive)
- Removedxmldom@0.1.19(transitive)
Updatedxmldom@0.1.27