Comparing version 2.7.3 to 2.8.0
@@ -640,3 +640,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ltx = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
} | ||
return unescapeXMLTable[match] | ||
if (unescapeXMLTable[match]) { | ||
return unescapeXMLTable[match] || match | ||
} | ||
throw new Error('Illegal XML entity ' + match) | ||
} | ||
@@ -649,3 +652,21 @@ | ||
exports.unescapeXML = function unescapeXML (s) { | ||
return s.replace(/&(amp|lt|gt|quot|apos|#x[0-9a-fA-F]+|#[0-9]+);/g, unescapeXMLReplace) | ||
var result = '' | ||
var start = -1 | ||
var end = -1 | ||
var previous = 0 | ||
while ((start = s.indexOf('&', previous)) !== -1 && (end = s.indexOf(';', start + 1)) !== -1) { | ||
result = result + | ||
s.substring(previous, start) + | ||
unescapeXMLReplace(s.substring(start, end + 1)) | ||
previous = end + 1 | ||
} | ||
// shortcut if loop never entered: | ||
// return the original string without creating new objects | ||
if (previous === 0) return s | ||
// push the remaining characters | ||
result = result + s.substring(previous) | ||
return result | ||
} | ||
@@ -739,2 +760,3 @@ | ||
var attrQuote | ||
var attrQuoteChar | ||
var recordStart = 0 | ||
@@ -769,3 +791,3 @@ var attrName | ||
if (typeof recordStart === 'number') { | ||
var recorded = data.slice(recordStart, pos) | ||
var recorded = data.substring(recordStart, pos) | ||
recordStart = undefined | ||
@@ -777,2 +799,25 @@ return recorded | ||
for (; pos < data.length; pos++) { | ||
if (state === STATE_TEXT) { | ||
// if we're looping through text, fast-forward using indexOf to | ||
// the next '<' character | ||
const lt = data.indexOf('<', pos) | ||
if (lt !== -1 && pos !== lt) { | ||
pos = lt | ||
} | ||
} else if (state === STATE_ATTR_VALUE) { | ||
// if we're looping through an attribute, fast-forward using | ||
// indexOf to the next end quote character | ||
const quot = data.indexOf(attrQuoteChar, pos) | ||
if (quot !== -1) { | ||
pos = quot | ||
} | ||
} else if (state === STATE_IGNORE_COMMENT) { | ||
// if we're looping through a comment, fast-forward using | ||
// indexOf to the first end-comment character | ||
const endcomment = data.indexOf('-->', pos) | ||
if (endcomment !== -1) { | ||
pos = endcomment + 2 // target the '>' character | ||
} | ||
} | ||
var c = data.charCodeAt(pos) | ||
@@ -870,2 +915,3 @@ switch (state) { | ||
attrQuote = c | ||
attrQuoteChar = c === 34 ? '"' : "'" | ||
state = STATE_ATTR_VALUE | ||
@@ -892,9 +938,2 @@ recordStart = pos + 1 | ||
} | ||
/* | ||
var origEmit = this.emit | ||
this.emit = function() { | ||
console.log('ltx', arguments) | ||
origEmit.apply(this, arguments) | ||
} | ||
*/ | ||
} | ||
@@ -901,0 +940,0 @@ inherits(SaxLtx, EventEmitter) |
@@ -640,3 +640,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ltx = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
} | ||
return unescapeXMLTable[match] | ||
if (unescapeXMLTable[match]) { | ||
return unescapeXMLTable[match] || match | ||
} | ||
throw new Error('Illegal XML entity ' + match) | ||
} | ||
@@ -649,3 +652,21 @@ | ||
exports.unescapeXML = function unescapeXML (s) { | ||
return s.replace(/&(amp|lt|gt|quot|apos|#x[0-9a-fA-F]+|#[0-9]+);/g, unescapeXMLReplace) | ||
var result = '' | ||
var start = -1 | ||
var end = -1 | ||
var previous = 0 | ||
while ((start = s.indexOf('&', previous)) !== -1 && (end = s.indexOf(';', start + 1)) !== -1) { | ||
result = result + | ||
s.substring(previous, start) + | ||
unescapeXMLReplace(s.substring(start, end + 1)) | ||
previous = end + 1 | ||
} | ||
// shortcut if loop never entered: | ||
// return the original string without creating new objects | ||
if (previous === 0) return s | ||
// push the remaining characters | ||
result = result + s.substring(previous) | ||
return result | ||
} | ||
@@ -739,2 +760,3 @@ | ||
var attrQuote | ||
var attrQuoteChar | ||
var recordStart = 0 | ||
@@ -769,3 +791,3 @@ var attrName | ||
if (typeof recordStart === 'number') { | ||
var recorded = data.slice(recordStart, pos) | ||
var recorded = data.substring(recordStart, pos) | ||
recordStart = undefined | ||
@@ -777,2 +799,25 @@ return recorded | ||
for (; pos < data.length; pos++) { | ||
if (state === STATE_TEXT) { | ||
// if we're looping through text, fast-forward using indexOf to | ||
// the next '<' character | ||
const lt = data.indexOf('<', pos) | ||
if (lt !== -1 && pos !== lt) { | ||
pos = lt | ||
} | ||
} else if (state === STATE_ATTR_VALUE) { | ||
// if we're looping through an attribute, fast-forward using | ||
// indexOf to the next end quote character | ||
const quot = data.indexOf(attrQuoteChar, pos) | ||
if (quot !== -1) { | ||
pos = quot | ||
} | ||
} else if (state === STATE_IGNORE_COMMENT) { | ||
// if we're looping through a comment, fast-forward using | ||
// indexOf to the first end-comment character | ||
const endcomment = data.indexOf('-->', pos) | ||
if (endcomment !== -1) { | ||
pos = endcomment + 2 // target the '>' character | ||
} | ||
} | ||
var c = data.charCodeAt(pos) | ||
@@ -870,2 +915,3 @@ switch (state) { | ||
attrQuote = c | ||
attrQuoteChar = c === 34 ? '"' : "'" | ||
state = STATE_ATTR_VALUE | ||
@@ -892,9 +938,2 @@ recordStart = pos + 1 | ||
} | ||
/* | ||
var origEmit = this.emit | ||
this.emit = function() { | ||
console.log('ltx', arguments) | ||
origEmit.apply(this, arguments) | ||
} | ||
*/ | ||
} | ||
@@ -901,0 +940,0 @@ inherits(SaxLtx, EventEmitter) |
@@ -41,3 +41,6 @@ 'use strict' | ||
} | ||
return unescapeXMLTable[match] | ||
if (unescapeXMLTable[match]) { | ||
return unescapeXMLTable[match] || match | ||
} | ||
throw new Error('Illegal XML entity ' + match) | ||
} | ||
@@ -50,3 +53,21 @@ | ||
exports.unescapeXML = function unescapeXML (s) { | ||
return s.replace(/&(amp|lt|gt|quot|apos|#x[0-9a-fA-F]+|#[0-9]+);/g, unescapeXMLReplace) | ||
var result = '' | ||
var start = -1 | ||
var end = -1 | ||
var previous = 0 | ||
while ((start = s.indexOf('&', previous)) !== -1 && (end = s.indexOf(';', start + 1)) !== -1) { | ||
result = result + | ||
s.substring(previous, start) + | ||
unescapeXMLReplace(s.substring(start, end + 1)) | ||
previous = end + 1 | ||
} | ||
// shortcut if loop never entered: | ||
// return the original string without creating new objects | ||
if (previous === 0) return s | ||
// push the remaining characters | ||
result = result + s.substring(previous) | ||
return result | ||
} | ||
@@ -53,0 +74,0 @@ |
@@ -8,5 +8,6 @@ 'use strict' | ||
'node-expat', | ||
'ltx' | ||
'ltx', | ||
'saxes' | ||
].map(function (name) { | ||
return require('./' + name) | ||
}) |
@@ -28,2 +28,3 @@ 'use strict' | ||
var attrQuote | ||
var attrQuoteChar | ||
var recordStart = 0 | ||
@@ -58,3 +59,3 @@ var attrName | ||
if (typeof recordStart === 'number') { | ||
var recorded = data.slice(recordStart, pos) | ||
var recorded = data.substring(recordStart, pos) | ||
recordStart = undefined | ||
@@ -66,2 +67,25 @@ return recorded | ||
for (; pos < data.length; pos++) { | ||
if (state === STATE_TEXT) { | ||
// if we're looping through text, fast-forward using indexOf to | ||
// the next '<' character | ||
const lt = data.indexOf('<', pos) | ||
if (lt !== -1 && pos !== lt) { | ||
pos = lt | ||
} | ||
} else if (state === STATE_ATTR_VALUE) { | ||
// if we're looping through an attribute, fast-forward using | ||
// indexOf to the next end quote character | ||
const quot = data.indexOf(attrQuoteChar, pos) | ||
if (quot !== -1) { | ||
pos = quot | ||
} | ||
} else if (state === STATE_IGNORE_COMMENT) { | ||
// if we're looping through a comment, fast-forward using | ||
// indexOf to the first end-comment character | ||
const endcomment = data.indexOf('-->', pos) | ||
if (endcomment !== -1) { | ||
pos = endcomment + 2 // target the '>' character | ||
} | ||
} | ||
var c = data.charCodeAt(pos) | ||
@@ -159,2 +183,3 @@ switch (state) { | ||
attrQuote = c | ||
attrQuoteChar = c === 34 ? '"' : "'" | ||
state = STATE_ATTR_VALUE | ||
@@ -181,9 +206,2 @@ recordStart = pos + 1 | ||
} | ||
/* | ||
var origEmit = this.emit | ||
this.emit = function() { | ||
console.log('ltx', arguments) | ||
origEmit.apply(this, arguments) | ||
} | ||
*/ | ||
} | ||
@@ -190,0 +208,0 @@ inherits(SaxLtx, EventEmitter) |
{ | ||
"name": "ltx", | ||
"version": "2.7.3", | ||
"version": "2.8.0", | ||
"description": "<xml for=\"JavaScript\">", | ||
@@ -32,3 +32,3 @@ "author": "Astro", | ||
"benchmark": "^2.1.3", | ||
"browserify": "^16.2.2", | ||
"browserify": "^16.2.3", | ||
"libxmljs": "^0.19.5", | ||
@@ -39,2 +39,3 @@ "microtime": "^2.1.2", | ||
"sax": "^1.2.2", | ||
"saxes": "^3.1.3", | ||
"standard": "^12.0.1", | ||
@@ -41,0 +42,0 @@ "vows": "^0.8.1" |
@@ -32,12 +32,13 @@ ltx | ||
| parser | ops/sec | native | stream | | ||
| parser | ops/sec | JS | stream | | ||
|--------------------------------------------------------------------------------------------|--------:|:------:|:------:| | ||
| [sax-js](https://github.com/isaacs/sax-js) | 99,412 | ☐ | ☑ | | ||
| [node-xml](https://github.com/dylang/node-xml) | 130,631 | ☐ | ☑ | | ||
| [libxmljs](https://github.com/polotek/libxmljs) | 276,136 | ☑ | ☐ | | ||
| [node-expat](https://github.com/node-xmpp/node-expat) | 322,769 | ☑ | ☑ | | ||
| **[ltx/lib/parsers/ltx](https://github.com/node-xmpp/ltx/blob/master/lib/parsers/ltx.js)** | 641,327 | ☐ | ☑ | | ||
| [sax-js](https://github.com/isaacs/sax-js) | 43,058 | ☑ | ☑ | | ||
| [libxmljs](https://github.com/polotek/libxmljs) | 56,763 | ☐ | ☐ | | ||
| [saxes](https://github.com/lddubeau/saxes) | 62,246 | ☑ | ☑ | | ||
| [node-xml](https://github.com/dylang/node-xml) | 81,980 | ☑ | ☑ | | ||
| [node-expat](https://github.com/node-xmpp/node-expat) | 72,720 | ☐ | ☑ | | ||
| **[ltx/lib/parsers/ltx](https://github.com/node-xmpp/ltx/blob/master/lib/parsers/ltx.js)** | 490,593 | ☑ | ☑ | | ||
From [ltx/benchmarks/parsers.js](https://github.com/node-xmpp/ltx/blob/master/benchmarks/parsers.js), higher is better. | ||
Node.js v10.11.0 - i5-2520M | ||
@@ -44,0 +45,0 @@ ## Benchmark |
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
118685
26
3884
56
10