This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

6
node_modules/xmldoc/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,6 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- '4'
- '5'

87
node_modules/xmldoc/CHANGELOG.md generated vendored Normal file
View File

@ -0,0 +1,87 @@
# Change Log
## [v1.0.0](https://github.com/nfarina/xmldoc/tree/v1.0.0) (2016-12-26)
[Full Changelog](https://github.com/nfarina/xmldoc/compare/v0.5.1...v1.0.0)
**Closed issues:**
- Excellent library with a beautiful, clean API [\#42](https://github.com/nfarina/xmldoc/issues/42)
- Order of elements changed [\#41](https://github.com/nfarina/xmldoc/issues/41)
- While writing back xml document to a file it removes all comments [\#39](https://github.com/nfarina/xmldoc/issues/39)
- react native using xmldoc to parser xml [\#38](https://github.com/nfarina/xmldoc/issues/38)
- Order of val in relation to children? [\#37](https://github.com/nfarina/xmldoc/issues/37)
**Merged pull requests:**
- Fix CData overwriting bug [\#43](https://github.com/nfarina/xmldoc/pull/43) ([calebmer](https://github.com/calebmer))
## [v0.5.1](https://github.com/nfarina/xmldoc/tree/v0.5.1) (2016-05-12)
[Full Changelog](https://github.com/nfarina/xmldoc/compare/v0.5.0...v0.5.1)
**Closed issues:**
- Release notes for 0.5 [\#35](https://github.com/nfarina/xmldoc/issues/35)
**Merged pull requests:**
- GLOBAL is producing deprecation warnings in node V6 [\#36](https://github.com/nfarina/xmldoc/pull/36) ([jmalins](https://github.com/jmalins))
## [v0.5.0](https://github.com/nfarina/xmldoc/tree/v0.5.0) (2016-04-27)
[Full Changelog](https://github.com/nfarina/xmldoc/compare/v0.4.0...v0.5.0)
**Closed issues:**
- Incorrect escaping of < > [\#29](https://github.com/nfarina/xmldoc/issues/29)
- Update tag for v0.4.0 [\#28](https://github.com/nfarina/xmldoc/issues/28)
- Error parsing coments out of XML scope [\#27](https://github.com/nfarina/xmldoc/issues/27)
- Support of xml comments [\#22](https://github.com/nfarina/xmldoc/issues/22)
- Question on usage [\#20](https://github.com/nfarina/xmldoc/issues/20)
**Merged pull requests:**
- Handle "doctype" elements. [\#34](https://github.com/nfarina/xmldoc/pull/34) ([nfarina](https://github.com/nfarina))
- Support XML comments [\#33](https://github.com/nfarina/xmldoc/pull/33) ([nfarina](https://github.com/nfarina))
- Correctly handle \(discard\) tags that come after the root XML document node [\#32](https://github.com/nfarina/xmldoc/pull/32) ([nfarina](https://github.com/nfarina))
- Add tests [\#31](https://github.com/nfarina/xmldoc/pull/31) ([nfarina](https://github.com/nfarina))
- Fixing \#29 - Incorrect escaping of < > [\#30](https://github.com/nfarina/xmldoc/pull/30) ([buholzer](https://github.com/buholzer))
## [v0.4.0](https://github.com/nfarina/xmldoc/tree/v0.4.0) (2015-11-16)
[Full Changelog](https://github.com/nfarina/xmldoc/compare/v0.3.1...v0.4.0)
**Closed issues:**
- Support DOCTYPE or ignore it please [\#24](https://github.com/nfarina/xmldoc/issues/24)
**Merged pull requests:**
- Head [\#26](https://github.com/nfarina/xmldoc/pull/26) ([wotzisname](https://github.com/wotzisname))
- Fix escaping of xml values and attributes [\#25](https://github.com/nfarina/xmldoc/pull/25) ([wotzisname](https://github.com/wotzisname))
- encode attribute values to keep xml valid [\#21](https://github.com/nfarina/xmldoc/pull/21) ([dmvjs](https://github.com/dmvjs))
## [v0.3.1](https://github.com/nfarina/xmldoc/tree/v0.3.1) (2015-05-22)
**Closed issues:**
- xmldoc error [\#19](https://github.com/nfarina/xmldoc/issues/19)
- Add Error Reporting [\#17](https://github.com/nfarina/xmldoc/issues/17)
- Need Line Number [\#14](https://github.com/nfarina/xmldoc/issues/14)
- How to retrieve the value in a few level down the nodes? [\#13](https://github.com/nfarina/xmldoc/issues/13)
- childNamed returns null not undefined [\#12](https://github.com/nfarina/xmldoc/issues/12)
- New version for npm? [\#10](https://github.com/nfarina/xmldoc/issues/10)
- getValueWithPath - xml namespace not supported? [\#9](https://github.com/nfarina/xmldoc/issues/9)
- High byte characters are not coming in correctly. [\#8](https://github.com/nfarina/xmldoc/issues/8)
- Add text as child nodes [\#7](https://github.com/nfarina/xmldoc/issues/7)
- descendantWithPath\(\) not always finds valid path [\#6](https://github.com/nfarina/xmldoc/issues/6)
- TypeError: Cannot call method 'apply' of undefined when parsing VMware vCloud Director XML [\#5](https://github.com/nfarina/xmldoc/issues/5)
- Serialization [\#2](https://github.com/nfarina/xmldoc/issues/2)
- can't create new XMLDocument… it seems to be undefined [\#1](https://github.com/nfarina/xmldoc/issues/1)
**Merged pull requests:**
- Escape ampersands and quotes as well [\#18](https://github.com/nfarina/xmldoc/pull/18) ([protobi](https://github.com/protobi))
- Added parse information to XmlElement [\#15](https://github.com/nfarina/xmldoc/pull/15) ([EToreo](https://github.com/EToreo))
- Add escaping '\<' and '\>' in toString\(\) [\#11](https://github.com/nfarina/xmldoc/pull/11) ([martnst](https://github.com/martnst))
- add whole document serialization via toString\(whole=true, compressed=true\) [\#4](https://github.com/nfarina/xmldoc/pull/4) ([jankuca](https://github.com/jankuca))
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

23
node_modules/xmldoc/LICENSE generated vendored Normal file
View File

@ -0,0 +1,23 @@
Copyright 2012 Nick Farina.
All rights reserved.
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.

151
node_modules/xmldoc/README.md generated vendored Normal file
View File

@ -0,0 +1,151 @@
[![Build Status](https://travis-ci.org/nfarina/xmldoc.svg)](https://travis-ci.org/nfarina/xmldoc)
[![Coverage Status](https://coveralls.io/repos/github/nfarina/xmldoc/badge.svg?branch=master)](https://coveralls.io/github/nfarina/xmldoc?branch=master)
## Introduction
`xmldoc` lets you parse XML documents with ease. It's a pure-JavaScript, one-file XML document class with a single dependency on the excellent [`sax`][sax] parser.
For more on why I wrote this class, see the [blog post][blog].
[blog]: http://nfarina.com/post/34302964969/a-lightweight-xml-document-class-for-nodejs-javascript
## Release Notes
See [CHANGELOG.md](./CHANGELOG.md) for details (built with [GitHub Changelog Generator](https://skywinder.github.io/github-changelog-generator/)).
## Installation
npm install xmldoc
Or just download the repository and include it in your `node_modules` directly. Or just download the [single JS file][blob]!
[blob]: https://github.com/nfarina/xmldoc/blob/master/lib/xmldoc.js
## Installation - React Native
I haven't tested this myself but [installing `buffer` and `stream` separately](https://github.com/nfarina/xmldoc/issues/38) may be necessary for `xmldoc` to work on React Native:
npm install buffer stream xmldoc
## Usage
```js
var xmldoc = require('xmldoc');
var document = new xmldoc.XmlDocument("<some>xml</some>");
// do things
```
## Classes
The primary exported class is `XmlDocument`, which you'll use to consume your XML text. `XmlDocument` contains a hierarchy of `XmlElement` instances representing the XML structure.
Both `XmlElement` and `XmlDocument` contain the same members and methods you can call to traverse the document or a subtree.
## Members
* `name` - the node name, like "tat" for `<tat>`. XML "namespaces" are ignored by the underlying [sax-js](https://github.com/isaacs/sax-js) parser, so you'll simply get "office:body" for `<office:body>`.
* `attr` - an object dict containing attribute properties, like `bookNode.attr.title` for `<book title="...">`.
* `val` - the string "value" of the node, if any, like "world" for `<hello>world</hello>`.
* `children` - an array of `XmlElement` children of the node.
* `firstChild`, `lastChild` - pretty much what it sounds like; null if no children
* `line`, `column`, `position`, `startTagPosition` - information about the element's original position in the XML string.
Each member defaults to a sensible "empty" value like `{}` for `attr`, `[]` for `children`, and `""` for `val`.
## Methods
All methods with `child` in the name operate only on direct children; they do not do a deep/recursive search.
It's important to note that `xmldoc` is designed for when you know exactly what you want from your XML file. For instance, it's great for parsing API responses with known structures, but it's not great at teasing things out of HTML documents from the web.
If you need to do lots of searching through your XML document, I highly recommend trying a different library like [node-elementtree](https://github.com/racker/node-elementtree).
### eachChild(func)
Similar to [underscore's][underscore] `each` method, it will call `func(child, index, array)` for each child of the given node.
### childNamed(name)
Pass it the name of a child node and it will search for and return the first one found, or `undefined`.
### childrenNamed(name)
Like `childNamed` but returns all matching children in an array, or `[]`.
### childWithAttribute(name,value)
Searches for the first child with the given attribute value. You can omit `value` to just find the first node with the given attribute defined at all.
### descendantWithPath(path)
Searches for a specific "path" using dot notation. Example:
```xml
<book>
<author>
<name isProper="true">George R. R. Martin</name>
...
</author>
...
</book>
```
If you just want the `<name>` node and you have the `XmlElement` for the `<book>` node, you can say:
```js
var nameNode = bookNode.descendantWithPath("author.name"); // return <name> node
```
### valueWithPath(path)
Just like `descendantWithPath`, but goes deeper and extracts the `val` of the node. Example:
```js
var authorName = bookNode.valueWithPath("author.name"); // return "George R. R. Martin"
```
You can also use the `@` character to request the value of a particular _attribute_ instead:
```js
var authorIsProper = bookNode.valueWithPath("author.name@isProper"); // return "true"
```
This is not [XPath][]! It's just a thing I made up, OK?
### toString([options])
This is just an override of the standard JavaScript method, it will give you a string representation of your XML document or element. Note that this is for debugging only! It is not guaranteed to always output valid XML.
The default implementation of `toString()`, that is, the one you get when you just `console.log("Doc: " + myDoc)` will pretty-print the XML with linebreaks and indents. You can pass a couple options to control the output:
```js
xml.toString({compressed:true}) // strips indents and linebreaks
xml.toString({trimmed:true}) // trims long strings for easier debugging
xml.toString({preserveWhitespace:true}) // prevents whitespace being removed from around element values
```
Putting it all together:
```js
var xml = "<author><name>looooooong value</name></author>";
console.log("My document: \n" + new XmlDocument(xml).toString({trimmed:true}))
```
Prints:
My Document:
<hello>
loooooooo…
</hello>
## Feedback
Feel free to file issues or hit me up on [Twitter][twitter].
[underscore]: http://underscorejs.org
[XPath]: http://en.wikipedia.org/wiki/XPath
[twitter]: http://twitter.com/nfarina
[sax]: https://github.com/isaacs/sax-js

60
node_modules/xmldoc/examples/example.js generated vendored Normal file
View File

@ -0,0 +1,60 @@
// Designed to be run from Node.js - i.e. "node example.js"
var XmlDocument = require('../lib/xmldoc').XmlDocument;
// Demonstrate parsing an in-memory XML string
var xmlString = '<suggestions><book title="Twilight"/><book title="Twister"/></suggestions>';
var suggestions = new XmlDocument(xmlString);
// Demonstrate how toString() will pretty-print the XML for debugging
console.log("Parsed: \n%s", suggestions);
// Demonstrate a simple eachChild() loop, printing our book titles
suggestions.eachChild(function(book) {
console.log("Found book with title: '%s'", book.attr.title);
console.log("==> The <book> tag started at position %s and the complete element ended at line %s, column %s, position %s.", book.startTagPosition, book.line, book.column, book.position);
});
// Now load an XML file from disk and parse it
var fs = require('fs'),
path = require('path');
fs.readFile(path.join(__dirname, "test.xml"), 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
// Parse the XML
var results = new XmlDocument(data);
// Demonstrate toString() with an option to abbreviate long strings and compress the output
console.log("Parsed: \n%s", results.toString({trimmed:true, compressed:true}));
// Pull out the <books> node
var books = results.childNamed("books");
// Demonstrate firstChild/lastChild
console.log("First book has ISBN '%s', last book has ISBN '%s'", books.firstChild.attr.isbn, books.lastChild.attr.isbn);
// Print out the ISBNs
books.eachChild(function (book) {
console.log("Found book with ISBN '%s'", book.attr.isbn);
});
// Look for all children with a certain node name
var allBooks = books.childrenNamed("book");
// The result is an array of <book> XmlElement instances
console.log("Found %s books.", allBooks.length);
// Search for a particular book
var twilight = books.childWithAttribute("isbn","478-2-23-765712-2");
// Result is a single XmlElement instance for <book>
console.log("Title of book with given ISBN: '%s'", twilight.valueWithPath("title"));
return null;
});

25
node_modules/xmldoc/examples/test.html generated vendored Normal file
View File

@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<title>xmldoc browser test</title>
<script type="text/javascript" src="../node_modules/sax/lib/sax.js"></script>
<script type="text/javascript" src="../lib/xmldoc.js"></script>
<script type="text/javascript">
// Demonstrate parsing an in-memory XML string
var xmlString = '<suggestions><book title="Twilight"/><book title="Twister"/></suggestions>'
var suggestions = new XmlDocument(xmlString);
// Demonstrate how toString() will pretty-print an abbreviated version of the XML for debugging
console.log("Parsed: \n" + suggestions);
// Demonstrate a simple eachChild() loop, printing our book titles
suggestions.eachChild(function(book) {
document.write("<p>Found book with title: '" + book.attr.title + "'</p>");
});
</script>
</head>
<body>
</body>
</html>

20
node_modules/xmldoc/examples/test.xml generated vendored Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<results totalResults="74">
<books>
<book isbn="978-3-16-148410-0">
<title>Harry Potter and the Half-Blood Prince</title>
<price>29.95</price>
<authors>
<author>J.K. Rowling</author>
</authors>
</book>
<book isbn="478-2-23-765712-2">
<title>Twilight</title>
<price>19.95</price>
<authors>
<author>Stephenie Meyer</author>
<author>The Hand of God</author>
</authors>
</book>
</books>
</results>

3
node_modules/xmldoc/index.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
// This file is just added for convenience so this repository can be
// directly checked out into a project's deps folder
module.exports = require('./lib/xmldoc');

339
node_modules/xmldoc/lib/xmldoc.js generated vendored Normal file
View File

@ -0,0 +1,339 @@
(function () {
var sax;
if (typeof module !== 'undefined' && module.exports && !global.xmldocAssumeBrowser) {
// We're being used in a Node-like environment
sax = require('sax');
}
else {
// assume it's attached to the Window object in a browser
sax = this.sax;
if (!sax) // no sax for you!
throw new Error("Expected sax to be defined. Make sure you're including sax.js before this file.");
}
/*
XmlElement is our basic building block. Everything is an XmlElement; even XmlDocument
behaves like an XmlElement by inheriting its attributes and functions.
*/
function XmlElement(tag) {
// Capture the parser object off of the XmlDocument delegate
var parser = delegates[delegates.length - 1].parser;
this.name = tag.name;
this.attr = tag.attributes;
this.val = "";
this.children = [];
this.firstChild = null;
this.lastChild = null;
// Assign parse information
this.line = parser.line;
this.column = parser.column;
this.position = parser.position;
this.startTagPosition = parser.startTagPosition;
}
// Private methods
XmlElement.prototype._addChild = function(child) {
// add to our children array
this.children.push(child);
// update first/last pointers
if (!this.firstChild) this.firstChild = child;
this.lastChild = child;
};
// SaxParser handlers
XmlElement.prototype._opentag = function(tag) {
var child = new XmlElement(tag);
this._addChild(child);
delegates.unshift(child);
};
XmlElement.prototype._closetag = function() {
delegates.shift();
};
XmlElement.prototype._text = function(text) {
if (typeof this.children === 'undefined')
return
this.val += text;
this._addChild(new XmlTextNode(text));
};
XmlElement.prototype._cdata = function(cdata) {
this.val += cdata;
this._addChild(new XmlCDataNode(cdata));
};
XmlElement.prototype._comment = function(comment) {
if (typeof this.children === 'undefined')
return
this._addChild(new XmlCommentNode(comment));
};
XmlElement.prototype._error = function(err) {
throw err;
};
// Useful functions
XmlElement.prototype.eachChild = function(iterator, context) {
for (var i=0, l=this.children.length; i<l; i++)
if (this.children[i].type === "element")
if (iterator.call(context, this.children[i], i, this.children) === false) return;
};
XmlElement.prototype.childNamed = function(name) {
for (var i=0, l=this.children.length; i<l; i++) {
var child = this.children[i];
if (child.name === name) return child;
}
return undefined;
};
XmlElement.prototype.childrenNamed = function(name) {
var matches = [];
for (var i=0, l=this.children.length; i<l; i++)
if (this.children[i].name === name)
matches.push(this.children[i]);
return matches;
};
XmlElement.prototype.childWithAttribute = function(name,value) {
for (var i=0, l=this.children.length; i<l; i++) {
var child = this.children[i];
if (child.type === "element" && ((value && child.attr[name] === value) || (!value && child.attr[name])))
return child;
}
return undefined;
};
XmlElement.prototype.descendantWithPath = function(path) {
var descendant = this;
var components = path.split('.');
for (var i=0, l=components.length; i<l; i++)
if (descendant && descendant.type === "element")
descendant = descendant.childNamed(components[i]);
else
return undefined;
return descendant;
};
XmlElement.prototype.valueWithPath = function(path) {
var components = path.split('@');
var descendant = this.descendantWithPath(components[0]);
if (descendant)
return components.length > 1 ? descendant.attr[components[1]] : descendant.val;
else
return undefined;
};
// String formatting (for debugging)
XmlElement.prototype.toString = function(options) {
return this.toStringWithIndent("", options);
};
XmlElement.prototype.toStringWithIndent = function(indent, options) {
var s = indent + "<" + this.name;
var linebreak = options && options.compressed ? "" : "\n";
var preserveWhitespace = options && options.preserveWhitespace;
for (var name in this.attr)
if (Object.prototype.hasOwnProperty.call(this.attr, name))
s += " " + name + '="' + escapeXML(this.attr[name]) + '"';
if (this.children.length === 1 && this.children[0].type !== "element") {
s += ">" + this.children[0].toString(options) + "</" + this.name + ">";
}
else if (this.children.length) {
s += ">" + linebreak;
var childIndent = indent + (options && options.compressed ? "" : " ");
for (var i=0, l=this.children.length; i<l; i++) {
s += this.children[i].toStringWithIndent(childIndent, options) + linebreak;
}
s += indent + "</" + this.name + ">";
}
else if (options && options.html) {
var whiteList = [
"area", "base", "br", "col", "embed", "frame", "hr", "img", "input",
"keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"
];
if (whiteList.indexOf(this.name) !== -1) s += "/>";
else s += "></" + this.name + ">";
}
else {
s += "/>";
}
return s;
};
// Alternative XML nodes
function XmlTextNode (text) {
this.text = text;
}
XmlTextNode.prototype.toString = function(options) {
return formatText(escapeXML(this.text), options);
};
XmlTextNode.prototype.toStringWithIndent = function(indent, options) {
return indent+this.toString(options);
};
function XmlCDataNode (cdata) {
this.cdata = cdata;
}
XmlCDataNode.prototype.toString = function(options) {
return "<![CDATA["+formatText(this.cdata, options)+"]]>";
};
XmlCDataNode.prototype.toStringWithIndent = function(indent, options) {
return indent+this.toString(options);
};
function XmlCommentNode (comment) {
this.comment = comment;
}
XmlCommentNode.prototype.toString = function(options) {
return "<!--"+formatText(escapeXML(this.comment), options)+"-->";
};
XmlCommentNode.prototype.toStringWithIndent = function(indent, options) {
return indent+this.toString(options);
};
// Node type tag
XmlElement.prototype.type = "element";
XmlTextNode.prototype.type = "text";
XmlCDataNode.prototype.type = "cdata";
XmlCommentNode.prototype.type = "comment";
/*
XmlDocument is the class we expose to the user; it uses the sax parser to create a hierarchy
of XmlElements.
*/
function XmlDocument(xml) {
xml && (xml = xml.toString().trim());
if (!xml)
throw new Error("No XML to parse!");
// Stores doctype (if defined)
this.doctype = "";
// Expose the parser to the other delegates while the parser is running
this.parser = sax.parser(true); // strict
addParserEvents(this.parser);
// We'll use the file-scoped "delegates" var to remember what elements we're currently
// parsing; they will push and pop off the stack as we get deeper into the XML hierarchy.
// It's safe to use a global because JS is single-threaded.
delegates = [this];
this.parser.write(xml);
// Remove the parser as it is no longer needed and should not be exposed to clients
delete this.parser;
}
// make XmlDocument inherit XmlElement's methods
extend(XmlDocument.prototype, XmlElement.prototype);
XmlDocument.prototype._opentag = function(tag) {
if (typeof this.children === 'undefined')
// the first tag we encounter should be the root - we'll "become" the root XmlElement
XmlElement.call(this,tag);
else
// all other tags will be the root element's children
XmlElement.prototype._opentag.apply(this,arguments);
};
XmlDocument.prototype._doctype = function(doctype) {
this.doctype += doctype;
}
// file-scoped global stack of delegates
var delegates = null;
/*
Helper functions
*/
function addParserEvents(parser) {
parser.onopentag = parser_opentag;
parser.onclosetag = parser_closetag;
parser.ontext = parser_text;
parser.oncdata = parser_cdata;
parser.oncomment = parser_comment;
parser.ondoctype = parser_doctype;
parser.onerror = parser_error;
}
// create these closures and cache them by keeping them file-scoped
function parser_opentag() { delegates[0] && delegates[0]._opentag.apply(delegates[0],arguments) }
function parser_closetag() { delegates[0] && delegates[0]._closetag.apply(delegates[0],arguments) }
function parser_text() { delegates[0] && delegates[0]._text.apply(delegates[0],arguments) }
function parser_cdata() { delegates[0] && delegates[0]._cdata.apply(delegates[0],arguments) }
function parser_comment() { delegates[0] && delegates[0]._comment.apply(delegates[0],arguments) }
function parser_doctype() { delegates[0] && delegates[0]._doctype.apply(delegates[0],arguments) }
function parser_error() { delegates[0] && delegates[0]._error.apply(delegates[0],arguments) }
// a relatively standard extend method
function extend(destination, source) {
for (var prop in source)
if (source.hasOwnProperty(prop))
destination[prop] = source[prop];
}
// escapes XML entities like "<", "&", etc.
function escapeXML(value){
return value.toString().replace(/&/g, '&amp;').replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, '&apos;').replace(/"/g, '&quot;');
}
// formats some text for debugging given a few options
function formatText(text, options) {
var finalText = text;
if (options && options.trimmed && text.length > 25)
finalText = finalText.substring(0,25).trim() + "…";
if (!(options && options.preserveWhitespace))
finalText = finalText.trim();
return finalText;
}
// Are we being used in a Node-like environment?
if (typeof module !== 'undefined' && module.exports && !global.xmldocAssumeBrowser)
module.exports.XmlDocument = XmlDocument;
else
this.XmlDocument = XmlDocument;
})();

40
node_modules/xmldoc/package.json generated vendored Normal file
View File

@ -0,0 +1,40 @@
{
"name": "xmldoc",
"description": "A lightweight XML Document class for JavaScript.",
"author": {
"name": "Nick Farina",
"email": "nfarina@gmail.com",
"url": "http://nfarina.com"
},
"version": "1.1.2",
"main": "./index",
"scripts": {
"test": "tap test/*.js",
"coverage": "npm test -- --cov --coverage-report=html"
},
"dependencies": {
"sax": "^1.2.1"
},
"license": {
"type": "MIT",
"url": "https://raw.github.com/nfarina/xmldoc-js/master/LICENSE"
},
"repository": {
"type": "git",
"url": "git://github.com/nfarina/xmldoc.git"
},
"contributors": [
{
"name": "Nick Farina",
"email": "nfarina@gmail.com"
},
{
"name": "Caleb Meredith",
"email": "calebmeredith8@gmail.com"
}
],
"readmeFilename": "README.md",
"devDependencies": {
"tap": "^8.0.1"
}
}

441
node_modules/xmldoc/test/basic.js generated vendored Normal file
View File

@ -0,0 +1,441 @@
var XmlDocument = require('../').XmlDocument
var t = require('tap')
t.test('verify sax global in browser', function (t) {
// "un-require" the xmldoc module that we loaded up top
delete require.cache[require.resolve('../')];
// also un-require the actual xmldoc module pulled in by index.js ('../')
delete require.cache[require.resolve('../lib/xmldoc.js')];
// this signal will be picked up on by xmldoc.js
global.xmldocAssumeBrowser = true;
t.throws(function() {
require('../');
});
// try again, but this time satisfy the sax check
delete require.cache[require.resolve('../')];
delete require.cache[require.resolve('../lib/xmldoc.js')];
global.sax = {};
require('../');
t.ok(global.XmlDocument);
t.end();
})
t.test('extend util', function(t) {
delete require.cache[require.resolve('../')];
delete require.cache[require.resolve('../lib/xmldoc.js')];
Object.prototype.cruftyExtension = "blah";
try {
require('../');
}
finally {
delete Object.prototype.cruftyExtension;
}
t.end();
})
t.test('parse xml', function (t) {
var xmlString = '<hello>world</hello>';
var parsed = new XmlDocument(xmlString);
t.ok(parsed);
t.throws(function() { new XmlDocument(); });
t.throws(function() { new XmlDocument(" "); });
t.end();
})
t.test('cdata handling', function (t) {
var xmlString = '<hello><![CDATA[<world>]]></hello>';
var parsed = new XmlDocument(xmlString);
t.equal(parsed.val, "<world>");
t.end();
})
t.test('cdata and text handling', function (t) {
var xmlString = '<hello>(<![CDATA[<world>]]>)</hello>';
var parsed = new XmlDocument(xmlString);
t.equal(parsed.val, "(<world>)");
t.end();
})
t.test('doctype handling', function (t) {
var docWithType = new XmlDocument('<!DOCTYPE HelloWorld><hello>world</hello>');
t.equal(docWithType.doctype, " HelloWorld");
var docWithoutType = new XmlDocument('<hello>world</hello>');
t.equal(docWithoutType.doctype, "");
t.throws(function() {
new XmlDocument('<hello><!DOCTYPE HelloWorld>world</hello>');
});
t.end();
})
t.test('comment handling', function (t) {
var xmlString = '<hello><!-- World --></hello>';
var parsed = new XmlDocument(xmlString);
t.equal(parsed.val, "");
t.end();
})
t.test('comment and text handling', function (t) {
var xmlString = '<hello>(<!-- World -->)</hello>';
var parsed = new XmlDocument(xmlString);
t.equal(parsed.val, "()");
t.end();
})
t.test('text, cdata, and comment handling', function (t) {
var xmlString = '<hello>Hello<!-- , --> <![CDATA[<world>]]>!</hello>';
var parsed = new XmlDocument(xmlString);
t.equal(parsed.val, "Hello <world>!");
t.end();
})
t.test('text with elements handling', function (t) {
var xmlString = '<hello>hello, <world/>!</hello>';
var parsed = new XmlDocument(xmlString);
t.equal(parsed.val, "hello, !");
t.end();
})
t.test('text before root node', function (t) {
var xmlString = '\n\n<hello>*</hello>';
var xml = new XmlDocument(xmlString);
t.equal(xml.val, '*');
t.equal(xml.children.length, 1);
t.end();
})
t.test('text after root node', function (t) {
var xmlString = '<hello>*</hello>\n\n';
var xml = new XmlDocument(xmlString);
t.equal(xml.val, '*');
t.equal(xml.children.length, 1);
t.end();
})
t.test('text before root node with version', function (t) {
var xmlString = '<?xml version="1.0"?>\n\n<hello>*</hello>';
var xml = new XmlDocument(xmlString);
t.equal(xml.val, '*');
t.equal(xml.children.length, 1);
t.end();
})
t.test('text after root node with version', function (t) {
var xmlString = '<?xml version="1.0"?><hello>*</hello>\n\n';
var xml = new XmlDocument(xmlString);
t.equal(xml.val, '*');
t.equal(xml.children.length, 1);
t.end();
})
t.test('comment before root node', function (t) {
var xmlString = '<!-- hello --><world>*</world>';
var xml = new XmlDocument(xmlString);
t.equal(xml.val, '*');
t.equal(xml.children.length, 1);
t.end();
})
t.test('comment after root node', function (t) {
var xmlString = '<hello>*</hello><!-- world -->';
var xml = new XmlDocument(xmlString);
t.equal(xml.val, '*');
t.equal(xml.children.length, 1);
t.end();
})
t.test('error handling', function (t) {
var xmlString = '<hello><unclosed-tag></hello>';
t.throws(function() {
var parsed = new XmlDocument(xmlString);
});
t.end();
})
t.test('tag locations', function (t) {
var xmlString = '<books><book title="Twilight"/></books>';
var books = new XmlDocument(xmlString);
var book = books.children[0];
t.equal(book.attr.title, "Twilight");
t.equal(book.startTagPosition, 8);
t.equal(book.line, 0);
t.equal(book.column, 31);
t.equal(book.position, 31);
t.end();
})
t.test('eachChild', function (t) {
var xmlString = '<books><book title="Twilight"/><book title="Twister"/></books>';
var books = new XmlDocument(xmlString);
expectedTitles = ["Twilight", "Twister"];
books.eachChild(function(book, i, books) {
t.equal(book.attr.title, expectedTitles[i]);
});
called = 0;
books.eachChild(function(book, i, books) {
called++;
return false; // test that returning false short-circuits the loop
});
t.equal(called, 1);
t.end();
})
t.test('eachChild with text and comments', function (t) {
var xmlString = '<books><book title="Twilight"/>text!<book title="Twister"/><!--comment!--></books>';
var books = new XmlDocument(xmlString);
expectedTitles = ["Twilight", "Twister"];
var elI = 0;
books.eachChild(function(book, i, books) {
t.equal(book.attr.title, expectedTitles[elI++]);
});
called = 0;
books.eachChild(function(book, i, books) {
called++;
return false; // test that returning false short-circuits the loop
});
t.equal(called, 1);
t.end();
})
t.test('childNamed', function (t) {
var xmlString = '<books><book/><good-book/></books>';
var books = new XmlDocument(xmlString);
var goodBook = books.childNamed('good-book');
t.equal(goodBook.name, 'good-book');
var badBook = books.childNamed('bad-book');
t.equal(badBook, undefined);
t.end();
})
t.test('childNamed with text', function (t) {
var xmlString = '<books><book/>text<good-book/></books>';
var books = new XmlDocument(xmlString);
var goodBook = books.childNamed('good-book');
t.equal(goodBook.name, 'good-book');
var badBook = books.childNamed('bad-book');
t.equal(badBook, undefined);
t.end();
})
t.test('childNamed', function (t) {
var xmlString = '<fruits><apple sweet="yes"/><orange/><apple sweet="no"/><banana/></fruits>';
var fruits = new XmlDocument(xmlString);
var apples = fruits.childrenNamed('apple');
t.equal(apples.length, 2);
t.equal(apples[0].attr.sweet, 'yes');
t.equal(apples[1].attr.sweet, 'no');
t.end();
})
t.test('childWithAttribute', function (t) {
var xmlString = '<fruits><apple pick="no"/><orange rotten="yes"/><apple pick="yes"/><banana/></fruits>';
var fruits = new XmlDocument(xmlString);
var pickedFruit = fruits.childWithAttribute('pick', 'yes');
t.equal(pickedFruit.name, 'apple');
t.equal(pickedFruit.attr.pick, 'yes');
var rottenFruit = fruits.childWithAttribute('rotten');
t.equal(rottenFruit.name, 'orange');
var peeled = fruits.childWithAttribute('peeled');
t.equal(peeled, undefined);
t.end();
})
t.test('childWithAttribute with text', function (t) {
var xmlString = '<fruits><apple pick="no"/><orange rotten="yes"/>text<apple pick="yes"/><banana/></fruits>';
var fruits = new XmlDocument(xmlString);
var pickedFruit = fruits.childWithAttribute('pick', 'yes');
t.equal(pickedFruit.name, 'apple');
t.equal(pickedFruit.attr.pick, 'yes');
var rottenFruit = fruits.childWithAttribute('rotten');
t.equal(rottenFruit.name, 'orange');
var peeled = fruits.childWithAttribute('peeled');
t.equal(peeled, undefined);
t.end();
})
t.test('descendantWithPath', function (t) {
var xmlString = '<book><author><first>George R.R.</first><last>Martin</last></author></book>';
var book = new XmlDocument(xmlString);
var lastNameNode = book.descendantWithPath('author.last');
t.equal(lastNameNode.val, 'Martin');
var middleNameNode = book.descendantWithPath('author.middle');
t.equal(middleNameNode, undefined);
var publisherNameNode = book.descendantWithPath('publisher.first');
t.equal(publisherNameNode, undefined);
t.end();
})
t.test('descendantWithPath with text', function (t) {
var xmlString = '<book><author>text<first>George R.R.</first><last>Martin</last></author></book>';
var book = new XmlDocument(xmlString);
var lastNameNode = book.descendantWithPath('author.last');
t.equal(lastNameNode.val, 'Martin');
var middleNameNode = book.descendantWithPath('author.middle');
t.equal(middleNameNode, undefined);
var publisherNameNode = book.descendantWithPath('publisher.first');
t.equal(publisherNameNode, undefined);
t.end();
})
t.test('valueWithPath', function (t) {
var xmlString = '<book><author><first>George R.R.</first><last hyphenated="no">Martin</last></author></book>';
var book = new XmlDocument(xmlString);
var lastName = book.valueWithPath('author.last');
t.equal(lastName, 'Martin');
var lastNameHyphenated = book.valueWithPath('author.last@hyphenated');
t.equal(lastNameHyphenated, "no");
var publisherName = book.valueWithPath('publisher.last@hyphenated');
t.equal(publisherName, undefined);
t.end();
})
t.test('valueWithPath with text', function (t) {
var xmlString = '<book><author>text<first>George R.R.</first><last hyphenated="no">Martin</last></author></book>';
var book = new XmlDocument(xmlString);
var lastName = book.valueWithPath('author.last');
t.equal(lastName, 'Martin');
var lastNameHyphenated = book.valueWithPath('author.last@hyphenated');
t.equal(lastNameHyphenated, "no");
var publisherName = book.valueWithPath('publisher.last@hyphenated');
t.equal(publisherName, undefined);
t.end();
})
t.test('toString', function (t) {
var xmlString = '<books><book title="Twilight"/></books>';
var doc = new XmlDocument(xmlString);
t.equal(doc.toString(), '<books>\n <book title="Twilight"/>\n</books>');
t.equal(doc.toString({compressed:true}), '<books><book title="Twilight"/></books>');
xmlString = '<hello> world </hello>';
doc = new XmlDocument(xmlString);
t.equal(doc.toString(), '<hello>world</hello>');
t.equal(doc.toString({preserveWhitespace:true}), '<hello> world </hello>');
xmlString = '<hello><![CDATA[<world>]]></hello>';
doc = new XmlDocument(xmlString);
t.equal(doc.toString(), '<hello><![CDATA[<world>]]></hello>');
xmlString = '<hello>Hello<!-- , --> <![CDATA[<world>]]>!</hello>';
doc = new XmlDocument(xmlString);
t.equal(doc.toString({preserveWhitespace:true}), '<hello>\n Hello\n <!-- , -->\n \n <![CDATA[<world>]]>\n !\n</hello>');
xmlString = '<hello>hello, <world/>!</hello>';
doc = new XmlDocument(xmlString);
t.equal(doc.toString(), '<hello>\n hello,\n <world/>\n !\n</hello>');
xmlString = '<hello>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et accumsan nisi.</hello>';
doc = new XmlDocument(xmlString);
t.equal(doc.toString(), xmlString);
t.equal(doc.toString({trimmed:true}), '<hello>Lorem ipsum dolor sit ame…</hello>')
try {
// test that adding stuff to the Object prototype doesn't interfere with attribute exporting
Object.prototype.cruftyExtension = "You don't want this string to be exported!";
var xmlString = '<books><book title="Twilight"/></books>';
var doc = new XmlDocument(xmlString);
t.equal(doc.toString(), '<books>\n <book title="Twilight"/>\n</books>');
}
finally {
delete Object.prototype.cruftyExtensionMethod;
}
xmlString = '<hello>world<earth/><moon/></hello>';
doc = new XmlDocument(xmlString);
t.equal(doc.toString({compressed:true}), xmlString);
t.end();
})

22
node_modules/xmldoc/test/issues.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
var XmlDocument = require('../').XmlDocument
var t = require('tap')
t.test('parsing comments outside XML scope [#27]', function (t) {
var xmlString = '<hello>world</hello>\n<!--Thank you for your business!-->';
var parsed = new XmlDocument(xmlString);
// verify that the trailing comment is ignored (no sensible place to put it)
t.equal(parsed.toString(), '<hello>world</hello>');
t.end();
})
t.test('validating escaping of &lt; &gt; [#29]', function (t) {
var xmlString = '<root><command>&lt; &gt;</command></root>';
var parsed = new XmlDocument(xmlString);
var result = parsed.toString({compressed:true})
t.equal(result, xmlString);
t.end();
})