Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oniyi-utils-xml

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oniyi-utils-xml - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

lib/.eslintrc.js

64

lib/utils.js
'use strict';
/**
* XML NodeTypes
*
* http://www.w3schools.com/dom/dom_nodetype.asp
*
* 1 ELEMENT_NODE
* 2 ATTRIBUTE_NODE
* 3 TEXT_NODE
* 4 CDATA_SECTION_NODE
* 5 ENTITY_REFERENCE_NODE
* 6 ENTITY_NODE
* 7 PROCESSING_INSTRUCTION_NODE
* 8 COMMENT_NODE
* 9 DOCUMENT_NODE
* 10 DOCUMENT_TYPE_NODE
* 11 DOCUMENT_FRAGMENT_NODE
* 12 NOTATION_NODE
*/
// core node modules
var xmldom = require('xmldom'),
DOMParser = xmldom.DOMParser,
XMLSerializer = xmldom.XMLSerializer,
xpath = require('xpath');
// 3rd party modules
const xmldom = require('xmldom');
const xpath = require('xpath');
const isString = require('lodash.isstring');
exports.parse = function parse(xmlString, mimeType, parserOptions) {
parserOptions = parserOptions || {};
mimeType = (typeof mimeType === 'string') ? mimeType : 'text/xml';
// internal modules
var parser = new DOMParser(parserOptions);
return parser.parseFromString(xmlString, mimeType);
};
const DOMParser = xmldom.DOMParser;
const XMLSerializer = xmldom.XMLSerializer;
exports.selectUseNamespaces = function selectUseNamespaces(nameSpaces) {
return xpath.useNamespaces(nameSpaces);
const parse = (xmlString, mimeType = 'text/xml', parserOptions = {}) => {
const safeMimeType = (isString(mimeType) && mimeType) || 'text/xml';
const parser = new DOMParser(parserOptions);
return parser.parseFromString(xmlString, safeMimeType);
};
exports.serialize = function serialize() {
var serializer = new XMLSerializer();
return serializer.serializeToString.apply(serializer, Array.prototype.slice.call(arguments, 0));
const selectUseNamespaces = nameSpaces => xpath.useNamespaces(nameSpaces);
const serialize = (...args) => (new XMLSerializer()).serializeToString(...args);
const select = (...args) => xpath.select(...args);
const ensureXMLDoc = stringOrXMLDoc => (isString(stringOrXMLDoc) && parse(stringOrXMLDoc)) || stringOrXMLDoc;
module.exports = {
parse,
select,
serialize,
selectUseNamespaces,
ensureXMLDoc,
};
exports.select = function select() {
return xpath.select.apply(xpath, Array.prototype.slice.call(arguments, 0));
};

@@ -1,19 +0,17 @@

var util = require('util');
var StringDecoder = require('string_decoder').StringDecoder;
var Transform = require('stream').Transform;
/* eslint-disable no-underscore-dangle */
var xmlUtils = require('./utils');
'use strict';
var allowedEncodings = [
'ascii', // for 7 bit ASCII data only. This encoding method is way fast, but is limited to the ascii character set. To convert a null character into 0x00, you should use 'utf8'.
'utf8', // Multibyte encoded Unicode characters. It has become the dominant character encoding for the world wide web.
'utf16le', // 2 or 4 bytes, little endian encoded Unicode characters, surrogate pairs (U+10000 to U+10FFFF) are supported.
'ucs2', // Alias of 'utf16le'.
'base64', // Base64 string encoding.
'binary', // Method of encoding raw binary data into strings by using only the first 8 bits of each character. This encoding method is deprecated.
'hex' // This method is used to encode each byte as two hexadecimal characters.
];
// core node modules
const util = require('util');
const StringDecoder = require('string_decoder').StringDecoder;
const Transform = require('stream').Transform;
// 3rd party modules
// internal modules
const { parse } = require('./utils');
// Gets XML string data and emits the parsed XMLDocument object
function XMLParseStream(options, encoding) {
function XMLParseStream(options = {}, encoding) {
if (!(this instanceof XMLParseStream)) {

@@ -23,7 +21,6 @@ return new XMLParseStream(options, encoding);

options = options || {};
options.readableObjectMode = true;
Object.assign(options, { readableObjectMode: true });
Transform.call(this, options);
this._encoding = (encoding && allowedEncodings.indexOf(encoding) > -1) ? encoding : 'utf8';
this._encoding = (Buffer.isEncoding(encoding)) ? encoding : 'utf8';
this._decoder = new StringDecoder(this._encoding);

@@ -34,3 +31,3 @@ this._buffer = '';

XMLParseStream.prototype._transform = function(data, encoding, callback) {
XMLParseStream.prototype._transform = function transform(data, encoding, callback) {
// concatenate decoded string chunks in _buffer

@@ -41,8 +38,8 @@ this._buffer += this._decoder.write(data);

XMLParseStream.prototype._flush = function(callback) {
XMLParseStream.prototype._flush = function flush(callback) {
// make xmlDoc object from our _buffer
var xmlString = this._buffer.trim();
const xmlString = this._buffer.trim();
try {
var xmlDoc = xmlUtils.parse(xmlString);
const xmlDoc = parse(xmlString);
this.push(xmlDoc);

@@ -49,0 +46,0 @@ } catch (err) {

@@ -1,8 +0,16 @@

var util = require('util');
var Transform = require('stream').Transform;
/* eslint-disable no-underscore-dangle */
var xmlUtils = require('./utils');
'use strict';
// core node modules
const util = require('util');
const Transform = require('stream').Transform;
// 3rd party modules
// internal modules
const { serialize } = require('./utils');
// Gets XML Object data and emits the stringified XMLDocument
function XMLSerializeStream(options) {
function XMLSerializeStream(options = {}) {
if (!(this instanceof XMLSerializeStream)) {

@@ -12,4 +20,3 @@ return new XMLSerializeStream();

options = options || {};
options.writableObjectMode = true;
Object.assign(options, { writableObjectMode: true });
Transform.call(this, options);

@@ -19,5 +26,5 @@ }

XMLSerializeStream.prototype._transform = function(xmlDocument, encoding, callback) {
XMLSerializeStream.prototype._transform = function transform(xmlDocument, encoding, callback) {
try {
var xmlString = xmlUtils.serialize(xmlDocument);
const xmlString = serialize(xmlDocument);
this.push(xmlString);

@@ -24,0 +31,0 @@ } catch (err) {

{
"name": "oniyi-utils-xml",
"version": "0.1.0",
"version": "1.0.0",
"description": "utils for handling xml data",
"author": {
"name": "Benjamin Kroeger",
"email": "benjamin.kroeger@gmail.com"
"author": "Benjamin Kroeger <benjamin.kroeger@gmail.com>",
"repository": {
"type": "git",
"url": "git+https://github.com/benkroeger/oniyi-utils-xml.git"
},
"repository": "benkroeger/oniyi-utils-xml",
"license": "MIT",
"main": "lib/index.js",
"files": [

@@ -26,18 +27,24 @@ "lib",

"dependencies": {
"xmldom": "^0.1.19",
"xpath": "0.0.9"
"lodash.isstring": "4.0.1",
"xmldom": "0.1.19",
"xpath": "0.0.24"
},
"devDependencies": {
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.11.0",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-mocha-cli": "^1.12.0",
"jshint-stylish": "^1.0.1",
"load-grunt-tasks": "^3.1.0",
"time-grunt": "^1.1.0"
"ava": "0.19.1",
"eslint": "3.15.0",
"eslint-config-oniyi": "4.4.0",
"eslint-plugin-ava": "4.2.1"
},
"scripts": {
"test": "grunt"
"lint-fix": "eslint . --fix",
"lint": "eslint .",
"test": "ava --verbose"
},
"bugs": {
"url": "https://github.com/benkroeger/oniyi-utils-xml/issues"
},
"homepage": "https://github.com/benkroeger/oniyi-utils-xml#readme",
"directories": {
"test": "test"
}
}

@@ -29,4 +29,23 @@ > utils for handling xml data

## XML NodeTypes
http://www.w3schools.com/dom/dom_nodetype.asp
1 ELEMENT_NODE
2 ATTRIBUTE_NODE
3 TEXT_NODE
4 CDATA_SECTION_NODE
5 ENTITY_REFERENCE_NODE
6 ENTITY_NODE
7 PROCESSING_INSTRUCTION_NODE
8 COMMENT_NODE
9 DOCUMENT_NODE
10 DOCUMENT_TYPE_NODE
11 DOCUMENT_FRAGMENT_NODE
12 NOTATION_NODE
## License
MIT © [Benjamin Kroeger]()
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc