Comparing version 2.2.0 to 2.2.1
686
bundle.js
(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 e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
function EventEmitter() { | ||
this._events = this._events || {}; | ||
this._maxListeners = this._maxListeners || undefined; | ||
} | ||
module.exports = EventEmitter; | ||
// Backwards-compat with node 0.10.x | ||
EventEmitter.EventEmitter = EventEmitter; | ||
EventEmitter.prototype._events = undefined; | ||
EventEmitter.prototype._maxListeners = undefined; | ||
// By default EventEmitters will print a warning if more than 10 listeners are | ||
// added to it. This is a useful default which helps finding memory leaks. | ||
EventEmitter.defaultMaxListeners = 10; | ||
// Obviously not all Emitters should be limited to 10. This function allows | ||
// that to be increased. Set to zero for unlimited. | ||
EventEmitter.prototype.setMaxListeners = function(n) { | ||
if (!isNumber(n) || n < 0 || isNaN(n)) | ||
throw TypeError('n must be a positive number'); | ||
this._maxListeners = n; | ||
return this; | ||
}; | ||
EventEmitter.prototype.emit = function(type) { | ||
var er, handler, len, args, i, listeners; | ||
if (!this._events) | ||
this._events = {}; | ||
// If there is no 'error' event listener then throw. | ||
if (type === 'error') { | ||
if (!this._events.error || | ||
(isObject(this._events.error) && !this._events.error.length)) { | ||
er = arguments[1]; | ||
if (er instanceof Error) { | ||
throw er; // Unhandled 'error' event | ||
} | ||
throw TypeError('Uncaught, unspecified "error" event.'); | ||
} | ||
} | ||
handler = this._events[type]; | ||
if (isUndefined(handler)) | ||
return false; | ||
if (isFunction(handler)) { | ||
switch (arguments.length) { | ||
// fast cases | ||
case 1: | ||
handler.call(this); | ||
break; | ||
case 2: | ||
handler.call(this, arguments[1]); | ||
break; | ||
case 3: | ||
handler.call(this, arguments[1], arguments[2]); | ||
break; | ||
// slower | ||
default: | ||
args = Array.prototype.slice.call(arguments, 1); | ||
handler.apply(this, args); | ||
} | ||
} else if (isObject(handler)) { | ||
args = Array.prototype.slice.call(arguments, 1); | ||
listeners = handler.slice(); | ||
len = listeners.length; | ||
for (i = 0; i < len; i++) | ||
listeners[i].apply(this, args); | ||
} | ||
return true; | ||
}; | ||
EventEmitter.prototype.addListener = function(type, listener) { | ||
var m; | ||
if (!isFunction(listener)) | ||
throw TypeError('listener must be a function'); | ||
if (!this._events) | ||
this._events = {}; | ||
// To avoid recursion in the case that type === "newListener"! Before | ||
// adding it to the listeners, first emit "newListener". | ||
if (this._events.newListener) | ||
this.emit('newListener', type, | ||
isFunction(listener.listener) ? | ||
listener.listener : listener); | ||
if (!this._events[type]) | ||
// Optimize the case of one listener. Don't need the extra array object. | ||
this._events[type] = listener; | ||
else if (isObject(this._events[type])) | ||
// If we've already got an array, just append. | ||
this._events[type].push(listener); | ||
else | ||
// Adding the second element, need to change to array. | ||
this._events[type] = [this._events[type], listener]; | ||
// Check for listener leak | ||
if (isObject(this._events[type]) && !this._events[type].warned) { | ||
if (!isUndefined(this._maxListeners)) { | ||
m = this._maxListeners; | ||
} else { | ||
m = EventEmitter.defaultMaxListeners; | ||
} | ||
if (m && m > 0 && this._events[type].length > m) { | ||
this._events[type].warned = true; | ||
console.error('(node) warning: possible EventEmitter memory ' + | ||
'leak detected. %d listeners added. ' + | ||
'Use emitter.setMaxListeners() to increase limit.', | ||
this._events[type].length); | ||
if (typeof console.trace === 'function') { | ||
// not supported in IE 10 | ||
console.trace(); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.on = EventEmitter.prototype.addListener; | ||
EventEmitter.prototype.once = function(type, listener) { | ||
if (!isFunction(listener)) | ||
throw TypeError('listener must be a function'); | ||
var fired = false; | ||
function g() { | ||
this.removeListener(type, g); | ||
if (!fired) { | ||
fired = true; | ||
listener.apply(this, arguments); | ||
} | ||
} | ||
g.listener = listener; | ||
this.on(type, g); | ||
return this; | ||
}; | ||
// emits a 'removeListener' event iff the listener was removed | ||
EventEmitter.prototype.removeListener = function(type, listener) { | ||
var list, position, length, i; | ||
if (!isFunction(listener)) | ||
throw TypeError('listener must be a function'); | ||
if (!this._events || !this._events[type]) | ||
return this; | ||
list = this._events[type]; | ||
length = list.length; | ||
position = -1; | ||
if (list === listener || | ||
(isFunction(list.listener) && list.listener === listener)) { | ||
delete this._events[type]; | ||
if (this._events.removeListener) | ||
this.emit('removeListener', type, listener); | ||
} else if (isObject(list)) { | ||
for (i = length; i-- > 0;) { | ||
if (list[i] === listener || | ||
(list[i].listener && list[i].listener === listener)) { | ||
position = i; | ||
break; | ||
} | ||
} | ||
if (position < 0) | ||
return this; | ||
if (list.length === 1) { | ||
list.length = 0; | ||
delete this._events[type]; | ||
} else { | ||
list.splice(position, 1); | ||
} | ||
if (this._events.removeListener) | ||
this.emit('removeListener', type, listener); | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.removeAllListeners = function(type) { | ||
var key, listeners; | ||
if (!this._events) | ||
return this; | ||
// not listening for removeListener, no need to emit | ||
if (!this._events.removeListener) { | ||
if (arguments.length === 0) | ||
this._events = {}; | ||
else if (this._events[type]) | ||
delete this._events[type]; | ||
return this; | ||
} | ||
// emit removeListener for all listeners on all events | ||
if (arguments.length === 0) { | ||
for (key in this._events) { | ||
if (key === 'removeListener') continue; | ||
this.removeAllListeners(key); | ||
} | ||
this.removeAllListeners('removeListener'); | ||
this._events = {}; | ||
return this; | ||
} | ||
listeners = this._events[type]; | ||
if (isFunction(listeners)) { | ||
this.removeListener(type, listeners); | ||
} else if (listeners) { | ||
// LIFO order | ||
while (listeners.length) | ||
this.removeListener(type, listeners[listeners.length - 1]); | ||
} | ||
delete this._events[type]; | ||
return this; | ||
}; | ||
EventEmitter.prototype.listeners = function(type) { | ||
var ret; | ||
if (!this._events || !this._events[type]) | ||
ret = []; | ||
else if (isFunction(this._events[type])) | ||
ret = [this._events[type]]; | ||
else | ||
ret = this._events[type].slice(); | ||
return ret; | ||
}; | ||
EventEmitter.prototype.listenerCount = function(type) { | ||
if (this._events) { | ||
var evlistener = this._events[type]; | ||
if (isFunction(evlistener)) | ||
return 1; | ||
else if (evlistener) | ||
return evlistener.length; | ||
} | ||
return 0; | ||
}; | ||
EventEmitter.listenerCount = function(emitter, type) { | ||
return emitter.listenerCount(type); | ||
}; | ||
function isFunction(arg) { | ||
return typeof arg === 'function'; | ||
} | ||
function isNumber(arg) { | ||
return typeof arg === 'number'; | ||
} | ||
function isObject(arg) { | ||
return typeof arg === 'object' && arg !== null; | ||
} | ||
function isUndefined(arg) { | ||
return arg === void 0; | ||
} | ||
},{}],2:[function(require,module,exports){ | ||
'use strict' | ||
@@ -10,3 +310,6 @@ | ||
var createElement = require('./lib/createElement') | ||
var tag = require('./lib/tag') | ||
exports = module.exports = tag | ||
exports.Element = Element | ||
@@ -22,3 +325,5 @@ | ||
exports.escapeXML = escape.escapeXML | ||
exports.unescapeXML = escape.unescapeXML | ||
exports.escapeXMLText = escape.escapeXMLText | ||
exports.unescapeXMLText = escape.unescapeXMLText | ||
@@ -28,3 +333,5 @@ exports.Parser = Parser | ||
},{"./lib/Element":2,"./lib/Parser":3,"./lib/createElement":4,"./lib/equal":5,"./lib/escape":6,"./lib/parse":7}],2:[function(require,module,exports){ | ||
exports.tag = tag | ||
},{"./lib/Element":3,"./lib/Parser":4,"./lib/createElement":5,"./lib/equal":6,"./lib/escape":7,"./lib/parse":8,"./lib/tag":10}],3:[function(require,module,exports){ | ||
'use strict' | ||
@@ -52,2 +359,3 @@ | ||
this.children = [] | ||
this.attrs = {} | ||
this.setAttrs(attrs) | ||
@@ -128,4 +436,2 @@ } | ||
Element.prototype.setAttrs = function (attrs) { | ||
this.attrs = {} | ||
if (typeof attrs === 'string') { | ||
@@ -437,3 +743,3 @@ this.attrs.xmlns = attrs | ||
},{"./equal":5,"./escape":6}],3:[function(require,module,exports){ | ||
},{"./equal":6,"./escape":7}],4:[function(require,module,exports){ | ||
'use strict' | ||
@@ -511,5 +817,7 @@ | ||
},{"./Element":2,"./parsers/ltx":8,"events":10,"inherits":9}],4:[function(require,module,exports){ | ||
},{"./Element":3,"./parsers/ltx":9,"events":1,"inherits":11}],5:[function(require,module,exports){ | ||
'use strict' | ||
// JSX compatible | ||
var Element = require('./Element') | ||
@@ -528,3 +836,3 @@ | ||
},{"./Element":2}],5:[function(require,module,exports){ | ||
},{"./Element":3}],6:[function(require,module,exports){ | ||
'use strict' | ||
@@ -546,4 +854,5 @@ | ||
if (value !== b.attrs[key]) return false | ||
} else if (value.toString() !== b.attrs[key].toString()) { | ||
return false | ||
} | ||
else if (value.toString() !== b.attrs[key].toString()) return false | ||
} | ||
@@ -580,3 +889,3 @@ return true | ||
},{}],6:[function(require,module,exports){ | ||
},{}],7:[function(require,module,exports){ | ||
'use strict' | ||
@@ -590,5 +899,14 @@ | ||
.replace(/"/g, '"') | ||
.replace(/"/g, ''') | ||
.replace(/'/g, ''') | ||
} | ||
exports.unescapeXML = function unescapeXML (s) { | ||
return s | ||
.replace(/\&(amp|#38);/g, '&') | ||
.replace(/\&(lt|#60);/g, '<') | ||
.replace(/\&(gt|#62);/g, '>') | ||
.replace(/\&(quot|#34);/g, '"') | ||
.replace(/\&(apos|#39);/g, "'") | ||
} | ||
exports.escapeXMLText = function escapeXMLText (s) { | ||
@@ -601,3 +919,10 @@ return s | ||
},{}],7:[function(require,module,exports){ | ||
exports.unescapeXMLText = function unescapeXMLText (s) { | ||
return s | ||
.replace(/\&(amp|#38);/g, '&') | ||
.replace(/\&(lt|#60);/g, '<') | ||
.replace(/\&(gt|#62);/g, '>') | ||
} | ||
},{}],8:[function(require,module,exports){ | ||
'use strict' | ||
@@ -635,3 +960,3 @@ | ||
},{"./Parser":3}],8:[function(require,module,exports){ | ||
},{"./Parser":4}],9:[function(require,module,exports){ | ||
'use strict' | ||
@@ -641,2 +966,3 @@ | ||
var EventEmitter = require('events').EventEmitter | ||
var unescapeXML = require('../escape').unescapeXML | ||
@@ -705,3 +1031,3 @@ var STATE_TEXT = 0 | ||
if (text) { | ||
this.emit('text', unescapeXml(text)) | ||
this.emit('text', unescapeXML(text)) | ||
} | ||
@@ -768,3 +1094,3 @@ state = STATE_TAG_NAME | ||
if (c === attrQuote) { | ||
var value = unescapeXml(endRecording()) | ||
var value = unescapeXML(endRecording()) | ||
attrs[attrName] = value | ||
@@ -803,13 +1129,24 @@ attrName = undefined | ||
function unescapeXml (s) { | ||
return s | ||
.replace(/\&(amp|#38);/g, '&') | ||
.replace(/\&(lt|#60);/g, '<') | ||
.replace(/\&(gt|#62);/g, '>') | ||
.replace(/\&(quot|#34);/g, '"') | ||
.replace(/\&(apos|#39);/g, "'") | ||
.replace(/\&(nbsp|#160);/g, '\n') | ||
},{"../escape":7,"events":1,"inherits":11}],10:[function(require,module,exports){ | ||
'use strict' | ||
var escape = require('./escape').escapeXML | ||
var parse = require('./parse') | ||
module.exports = function tag (/* [literals], ...substitutions */) { | ||
var literals = arguments[0] | ||
var substitutions = Array.prototype.slice.call(arguments, 1) | ||
var str = '' | ||
for (var i = 0; i < substitutions.length; i++) { | ||
str += literals[i] | ||
str += escape(substitutions[i]) | ||
} | ||
str += literals[literals.length - 1] | ||
return parse(str) | ||
} | ||
},{"events":10,"inherits":9}],9:[function(require,module,exports){ | ||
},{"./escape":7,"./parse":8}],11:[function(require,module,exports){ | ||
if (typeof Object.create === 'function') { | ||
@@ -839,306 +1176,3 @@ // implementation from standard node.js 'util' module | ||
},{}],10:[function(require,module,exports){ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
function EventEmitter() { | ||
this._events = this._events || {}; | ||
this._maxListeners = this._maxListeners || undefined; | ||
} | ||
module.exports = EventEmitter; | ||
// Backwards-compat with node 0.10.x | ||
EventEmitter.EventEmitter = EventEmitter; | ||
EventEmitter.prototype._events = undefined; | ||
EventEmitter.prototype._maxListeners = undefined; | ||
// By default EventEmitters will print a warning if more than 10 listeners are | ||
// added to it. This is a useful default which helps finding memory leaks. | ||
EventEmitter.defaultMaxListeners = 10; | ||
// Obviously not all Emitters should be limited to 10. This function allows | ||
// that to be increased. Set to zero for unlimited. | ||
EventEmitter.prototype.setMaxListeners = function(n) { | ||
if (!isNumber(n) || n < 0 || isNaN(n)) | ||
throw TypeError('n must be a positive number'); | ||
this._maxListeners = n; | ||
return this; | ||
}; | ||
EventEmitter.prototype.emit = function(type) { | ||
var er, handler, len, args, i, listeners; | ||
if (!this._events) | ||
this._events = {}; | ||
// If there is no 'error' event listener then throw. | ||
if (type === 'error') { | ||
if (!this._events.error || | ||
(isObject(this._events.error) && !this._events.error.length)) { | ||
er = arguments[1]; | ||
if (er instanceof Error) { | ||
throw er; // Unhandled 'error' event | ||
} | ||
throw TypeError('Uncaught, unspecified "error" event.'); | ||
} | ||
} | ||
handler = this._events[type]; | ||
if (isUndefined(handler)) | ||
return false; | ||
if (isFunction(handler)) { | ||
switch (arguments.length) { | ||
// fast cases | ||
case 1: | ||
handler.call(this); | ||
break; | ||
case 2: | ||
handler.call(this, arguments[1]); | ||
break; | ||
case 3: | ||
handler.call(this, arguments[1], arguments[2]); | ||
break; | ||
// slower | ||
default: | ||
len = arguments.length; | ||
args = new Array(len - 1); | ||
for (i = 1; i < len; i++) | ||
args[i - 1] = arguments[i]; | ||
handler.apply(this, args); | ||
} | ||
} else if (isObject(handler)) { | ||
len = arguments.length; | ||
args = new Array(len - 1); | ||
for (i = 1; i < len; i++) | ||
args[i - 1] = arguments[i]; | ||
listeners = handler.slice(); | ||
len = listeners.length; | ||
for (i = 0; i < len; i++) | ||
listeners[i].apply(this, args); | ||
} | ||
return true; | ||
}; | ||
EventEmitter.prototype.addListener = function(type, listener) { | ||
var m; | ||
if (!isFunction(listener)) | ||
throw TypeError('listener must be a function'); | ||
if (!this._events) | ||
this._events = {}; | ||
// To avoid recursion in the case that type === "newListener"! Before | ||
// adding it to the listeners, first emit "newListener". | ||
if (this._events.newListener) | ||
this.emit('newListener', type, | ||
isFunction(listener.listener) ? | ||
listener.listener : listener); | ||
if (!this._events[type]) | ||
// Optimize the case of one listener. Don't need the extra array object. | ||
this._events[type] = listener; | ||
else if (isObject(this._events[type])) | ||
// If we've already got an array, just append. | ||
this._events[type].push(listener); | ||
else | ||
// Adding the second element, need to change to array. | ||
this._events[type] = [this._events[type], listener]; | ||
// Check for listener leak | ||
if (isObject(this._events[type]) && !this._events[type].warned) { | ||
var m; | ||
if (!isUndefined(this._maxListeners)) { | ||
m = this._maxListeners; | ||
} else { | ||
m = EventEmitter.defaultMaxListeners; | ||
} | ||
if (m && m > 0 && this._events[type].length > m) { | ||
this._events[type].warned = true; | ||
console.error('(node) warning: possible EventEmitter memory ' + | ||
'leak detected. %d listeners added. ' + | ||
'Use emitter.setMaxListeners() to increase limit.', | ||
this._events[type].length); | ||
if (typeof console.trace === 'function') { | ||
// not supported in IE 10 | ||
console.trace(); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.on = EventEmitter.prototype.addListener; | ||
EventEmitter.prototype.once = function(type, listener) { | ||
if (!isFunction(listener)) | ||
throw TypeError('listener must be a function'); | ||
var fired = false; | ||
function g() { | ||
this.removeListener(type, g); | ||
if (!fired) { | ||
fired = true; | ||
listener.apply(this, arguments); | ||
} | ||
} | ||
g.listener = listener; | ||
this.on(type, g); | ||
return this; | ||
}; | ||
// emits a 'removeListener' event iff the listener was removed | ||
EventEmitter.prototype.removeListener = function(type, listener) { | ||
var list, position, length, i; | ||
if (!isFunction(listener)) | ||
throw TypeError('listener must be a function'); | ||
if (!this._events || !this._events[type]) | ||
return this; | ||
list = this._events[type]; | ||
length = list.length; | ||
position = -1; | ||
if (list === listener || | ||
(isFunction(list.listener) && list.listener === listener)) { | ||
delete this._events[type]; | ||
if (this._events.removeListener) | ||
this.emit('removeListener', type, listener); | ||
} else if (isObject(list)) { | ||
for (i = length; i-- > 0;) { | ||
if (list[i] === listener || | ||
(list[i].listener && list[i].listener === listener)) { | ||
position = i; | ||
break; | ||
} | ||
} | ||
if (position < 0) | ||
return this; | ||
if (list.length === 1) { | ||
list.length = 0; | ||
delete this._events[type]; | ||
} else { | ||
list.splice(position, 1); | ||
} | ||
if (this._events.removeListener) | ||
this.emit('removeListener', type, listener); | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.removeAllListeners = function(type) { | ||
var key, listeners; | ||
if (!this._events) | ||
return this; | ||
// not listening for removeListener, no need to emit | ||
if (!this._events.removeListener) { | ||
if (arguments.length === 0) | ||
this._events = {}; | ||
else if (this._events[type]) | ||
delete this._events[type]; | ||
return this; | ||
} | ||
// emit removeListener for all listeners on all events | ||
if (arguments.length === 0) { | ||
for (key in this._events) { | ||
if (key === 'removeListener') continue; | ||
this.removeAllListeners(key); | ||
} | ||
this.removeAllListeners('removeListener'); | ||
this._events = {}; | ||
return this; | ||
} | ||
listeners = this._events[type]; | ||
if (isFunction(listeners)) { | ||
this.removeListener(type, listeners); | ||
} else { | ||
// LIFO order | ||
while (listeners.length) | ||
this.removeListener(type, listeners[listeners.length - 1]); | ||
} | ||
delete this._events[type]; | ||
return this; | ||
}; | ||
EventEmitter.prototype.listeners = function(type) { | ||
var ret; | ||
if (!this._events || !this._events[type]) | ||
ret = []; | ||
else if (isFunction(this._events[type])) | ||
ret = [this._events[type]]; | ||
else | ||
ret = this._events[type].slice(); | ||
return ret; | ||
}; | ||
EventEmitter.listenerCount = function(emitter, type) { | ||
var ret; | ||
if (!emitter._events || !emitter._events[type]) | ||
ret = 0; | ||
else if (isFunction(emitter._events[type])) | ||
ret = 1; | ||
else | ||
ret = emitter._events[type].length; | ||
return ret; | ||
}; | ||
function isFunction(arg) { | ||
return typeof arg === 'function'; | ||
} | ||
function isNumber(arg) { | ||
return typeof arg === 'number'; | ||
} | ||
function isObject(arg) { | ||
return typeof arg === 'object' && arg !== null; | ||
} | ||
function isUndefined(arg) { | ||
return arg === void 0; | ||
} | ||
},{}]},{},[1])(1) | ||
},{}]},{},[2])(2) | ||
}); |
@@ -9,3 +9,6 @@ 'use strict' | ||
var createElement = require('./lib/createElement') | ||
var tag = require('./lib/tag') | ||
exports = module.exports = tag | ||
exports.Element = Element | ||
@@ -21,5 +24,9 @@ | ||
exports.escapeXML = escape.escapeXML | ||
exports.unescapeXML = escape.unescapeXML | ||
exports.escapeXMLText = escape.escapeXMLText | ||
exports.unescapeXMLText = escape.unescapeXMLText | ||
exports.Parser = Parser | ||
exports.parse = parse | ||
exports.tag = tag |
'use strict' | ||
// JSX compatible | ||
var Element = require('./Element') | ||
@@ -4,0 +6,0 @@ |
@@ -23,2 +23,3 @@ 'use strict' | ||
this.children = [] | ||
this.attrs = {} | ||
this.setAttrs(attrs) | ||
@@ -99,4 +100,2 @@ } | ||
Element.prototype.setAttrs = function (attrs) { | ||
this.attrs = {} | ||
if (typeof attrs === 'string') { | ||
@@ -103,0 +102,0 @@ this.attrs.xmlns = attrs |
@@ -17,4 +17,5 @@ 'use strict' | ||
if (value !== b.attrs[key]) return false | ||
} else if (value.toString() !== b.attrs[key].toString()) { | ||
return false | ||
} | ||
else if (value.toString() !== b.attrs[key].toString()) return false | ||
} | ||
@@ -21,0 +22,0 @@ return true |
@@ -9,5 +9,14 @@ 'use strict' | ||
.replace(/"/g, '"') | ||
.replace(/"/g, ''') | ||
.replace(/'/g, ''') | ||
} | ||
exports.unescapeXML = function unescapeXML (s) { | ||
return s | ||
.replace(/\&(amp|#38);/g, '&') | ||
.replace(/\&(lt|#60);/g, '<') | ||
.replace(/\&(gt|#62);/g, '>') | ||
.replace(/\&(quot|#34);/g, '"') | ||
.replace(/\&(apos|#39);/g, "'") | ||
} | ||
exports.escapeXMLText = function escapeXMLText (s) { | ||
@@ -19,1 +28,8 @@ return s | ||
} | ||
exports.unescapeXMLText = function unescapeXMLText (s) { | ||
return s | ||
.replace(/\&(amp|#38);/g, '&') | ||
.replace(/\&(lt|#60);/g, '<') | ||
.replace(/\&(gt|#62);/g, '>') | ||
} |
'use strict' | ||
module.exports = [ | ||
// 'easysax', | ||
'ltx', | ||
'sax-js', | ||
'node-xml', | ||
'libxmljs', | ||
'node-expat', | ||
'node-xml', | ||
'sax' | ||
'ltx' | ||
].map(function (name) { | ||
return require('./' + name) | ||
}) |
@@ -5,2 +5,3 @@ 'use strict' | ||
var EventEmitter = require('events').EventEmitter | ||
var unescapeXML = require('../escape').unescapeXML | ||
@@ -69,3 +70,3 @@ var STATE_TEXT = 0 | ||
if (text) { | ||
this.emit('text', unescapeXml(text)) | ||
this.emit('text', unescapeXML(text)) | ||
} | ||
@@ -132,3 +133,3 @@ state = STATE_TAG_NAME | ||
if (c === attrQuote) { | ||
var value = unescapeXml(endRecording()) | ||
var value = unescapeXML(endRecording()) | ||
attrs[attrName] = value | ||
@@ -166,11 +167,1 @@ attrName = undefined | ||
} | ||
function unescapeXml (s) { | ||
return s | ||
.replace(/\&(amp|#38);/g, '&') | ||
.replace(/\&(lt|#60);/g, '<') | ||
.replace(/\&(gt|#62);/g, '>') | ||
.replace(/\&(quot|#34);/g, '"') | ||
.replace(/\&(apos|#39);/g, "'") | ||
.replace(/\&(nbsp|#160);/g, '\n') | ||
} |
@@ -6,2 +6,3 @@ 'use strict' | ||
var xml = require('node-xml') | ||
var unescapeXML = require('../escape').unescapeXML | ||
@@ -24,3 +25,3 @@ /** | ||
var attr = attrs[i] | ||
attrsHash[attr[0]] = unescapeXml(attr[1]) | ||
attrsHash[attr[0]] = unescapeXML(attr[1]) | ||
} | ||
@@ -30,3 +31,3 @@ for (i = 0; i < namespaces.length; i++) { | ||
var k = !namespace[0] ? 'xmlns' : 'xmlns:' + namespace[0] | ||
attrsHash[k] = unescapeXml(namespace[1]) | ||
attrsHash[k] = unescapeXML(namespace[1]) | ||
} | ||
@@ -65,10 +66,1 @@ self.emit('startElement', elem, attrsHash) | ||
} | ||
function unescapeXml (s) { | ||
return s | ||
.replace(/\&/g, '&') | ||
.replace(/\</g, '<') | ||
.replace(/\>/g, '>') | ||
.replace(/\"/g, '"') | ||
.replace(/\'/g, "'") | ||
} |
{ | ||
"name": "ltx", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "<xml for=\"JavaScript\">", | ||
@@ -32,3 +32,5 @@ "author": "Astro", | ||
"scripts": { | ||
"prepublish": "npm run bundle", | ||
"preversion": "npm test", | ||
"benchmark": "node benchmarks/", | ||
"bundle": "browserify -s ltx index.js -o bundle.js", | ||
@@ -43,10 +45,10 @@ "unit": "vows --spec", | ||
"devDependencies": { | ||
"benchmark": "^1.0.0", | ||
"easysax": "^0.1.14", | ||
"benchmark": "^2.1.0", | ||
"libxmljs": "^0.17.1", | ||
"microtime": "^2.0.0", | ||
"node-expat": "^2.3.10", | ||
"node-expat": "^2.3.13", | ||
"node-xml": "^1.0.2", | ||
"sax": "^1.1.2", | ||
"sax": "^1.1.5", | ||
"vows": "^0.8.1" | ||
} | ||
} |
@@ -8,27 +8,44 @@ # Less-Than XML | ||
* *Element:* any XML Element | ||
* Text nodes are Strings | ||
* Runs on Node.js and browsers | ||
ltx is a fast XML builder, parser and manipulation library for JavaScript. | ||
# Documentation | ||
The builder is a convenient and succinct API to build XML documents represented in memory as JavaScript primitives that can be serialized to XML strings. It provides a [JSX](https://facebook.github.io/jsx/) compatible API as well. | ||
The parser can parse XML documents or streams and support different backends. | ||
Features: | ||
* Succinct API to build and manipulate XML objects | ||
* parse XML strings | ||
* parse XML streams | ||
* multiple parser backends | ||
* [sax-js](https://github.com/isaacs/sax-js) | ||
* [node-xml](https://github.com/dylang/node-xml) | ||
* [node-expat](https://github.com/node-xmpp/node-expat) | ||
* [libxmljs](https://github.com/polotek/libxmljs) | ||
* [ltx](https://github.com/node-xmpp/ltx/blob/master/lib/parsers/ltx.js) (default and fastest see [Benchmark](#benchmark)) | ||
* [JSX](https://facebook.github.io/jsx/) compatible (use `ltx.createElement` pragma) | ||
* [tagged template](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) support `` ltx`<foo bar="${baz}">` `` | ||
## Install | ||
`npm install ltx` | ||
## Documentation | ||
For documentation please see http://node-xmpp.org/doc/ltx.html | ||
# Test | ||
## Benchmark | ||
``` | ||
npm install -g standard browserify | ||
npm run benchmark | ||
``` | ||
## Test | ||
``` | ||
npm install -g standard browserify | ||
npm test | ||
``` | ||
## Licence | ||
## TODO | ||
* More documentation | ||
* More tests (Using [Vows](http://vowsjs.org/)) | ||
# Licence | ||
MIT | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
59540
19
1993
51
0