Comparing version 0.24.0 to 0.25.0
@@ -10,2 +10,5 @@ module.exports = { | ||
}, | ||
rules: { | ||
'guard-for-in': 0, | ||
} | ||
}; |
@@ -137,2 +137,3 @@ import { EventEmitter } from 'events'; | ||
attrs(): Attribute[]; | ||
cdata(data: string): this; | ||
@@ -197,3 +198,2 @@ doc(): Document; | ||
code: number|null; | ||
message: string|null; | ||
level: number|null; | ||
@@ -223,2 +223,2 @@ file: string|null; | ||
column: number; | ||
} | ||
} |
@@ -24,7 +24,7 @@ // js acts as a wrapper to the c++ bindings | ||
// lib exports | ||
module.exports.Comment = require('./lib/comment'); | ||
module.exports.Comment = bindings.Comment; | ||
module.exports.Document = Document; | ||
module.exports.Element = require('./lib/element'); | ||
module.exports.ProcessingInstruction = require('./lib/pi'); | ||
module.exports.Text = require('./lib/text'); | ||
module.exports.ProcessingInstruction = bindings.ProcessingInstruction; | ||
module.exports.Text = bindings.Text; | ||
@@ -31,0 +31,0 @@ // Compatibility synonyms |
@@ -1,4 +0,5 @@ | ||
var bindings = require('./bindings'); | ||
/* eslint-disable no-underscore-dangle */ | ||
const bindings = require('./bindings'); | ||
var Element = require('./element'); | ||
const Element = require('./element'); | ||
@@ -11,10 +12,11 @@ function assertRoot(doc) { | ||
/// Create a new document | ||
/// @param {string} version xml version, default 1.0 | ||
/// @param {string} encoding the encoding, default utf8 | ||
/// @constructor | ||
function Document(version, encoding) { | ||
version = version || '1.0'; | ||
var doc = new bindings.Document(version); | ||
doc.encoding(encoding || 'utf8'); | ||
// / Create a new document | ||
// / @param {string} version xml version, default 1.0 | ||
// / @param {string} encoding the encoding, default utf8 | ||
// / @constructor | ||
function Document(version = '1.0', encoding = 'utf8') { | ||
const doc = new bindings.Document(version); | ||
doc.encoding(encoding); | ||
return doc; | ||
@@ -25,18 +27,11 @@ } | ||
/// get or set the root element | ||
/// if called without any arguments, this will return the document root | ||
/// @param {Element} [elem] if specified, this will become the new document root | ||
Document.prototype.root = function(elem) { | ||
return this._root(elem); | ||
}; | ||
/// add a child node to the document | ||
/// this will set the document root | ||
Document.prototype.node = function(name, content) { | ||
// / add a child node to the document | ||
// / this will set the document root | ||
Document.prototype.node = function node(name, content) { | ||
return this.root(Element(this, name, content)); | ||
}; | ||
/// xpath search | ||
/// @return array of matching elements | ||
Document.prototype.find = function(xpath, ns_uri) { | ||
// / xpath search | ||
// / @return array of matching elements | ||
Document.prototype.find = function find(xpath, ns_uri) { | ||
assertRoot(this); | ||
@@ -47,5 +42,5 @@ | ||
/// xpath search | ||
/// @return first element matching | ||
Document.prototype.get = function(xpath, ns_uri) { | ||
// / xpath search | ||
// / @return first element matching | ||
Document.prototype.get = function get(xpath, ns_uri) { | ||
assertRoot(this); | ||
@@ -56,4 +51,4 @@ | ||
/// @return a given child | ||
Document.prototype.child = function(id) { | ||
// / @return a given child | ||
Document.prototype.child = function child(id) { | ||
if (id === undefined || typeof id !== 'number') { | ||
@@ -68,4 +63,4 @@ throw new Error('id argument required for #child'); | ||
/// @return an Array of child nodes of the document root | ||
Document.prototype.childNodes = function() { | ||
// / @return an Array of child nodes of the document root | ||
Document.prototype.childNodes = function childNodes() { | ||
assertRoot(this); | ||
@@ -76,19 +71,9 @@ | ||
/// @return a string representation of the document | ||
Document.prototype.toString = function(formatted) { | ||
return this._toString(formatted !== undefined ? formatted : true); | ||
// / @return a string representation of the document | ||
Document.prototype.toString = function toString(formatted = true) { | ||
return this._toString(formatted); | ||
}; | ||
/// @return the document version | ||
Document.prototype.version = function() { | ||
return this._version(); | ||
}; | ||
/// @return the document encoding | ||
Document.prototype.encoding = function(encoding) { | ||
return this._encoding(encoding); | ||
}; | ||
/// @return whether the XmlDocument is valid | ||
Document.prototype.validate = function(xsd) { | ||
// / @return whether the XmlDocument is valid | ||
Document.prototype.validate = function validate(xsd) { | ||
if (!xsd) { | ||
@@ -100,7 +85,8 @@ throw new Error('Must pass xsd'); | ||
} | ||
return this._validate(xsd); | ||
}; | ||
/// @return whether the XmlDocument is valid using Relaxed NG | ||
Document.prototype.rngValidate = function(rng) { | ||
// / @return whether the XmlDocument is valid using Relaxed NG | ||
Document.prototype.rngValidate = function rngValidate(rng) { | ||
if (!rng) { | ||
@@ -112,10 +98,7 @@ throw new Error('Must pass xsd'); | ||
} | ||
return this._rngValidate(rng); | ||
}; | ||
Document.prototype.getDtd = function() { | ||
return this._getDtd(); | ||
}; | ||
Document.prototype.setDtd = function(name, ext, sys) { | ||
Document.prototype.setDtd = function setDtd(name, ext, sys) { | ||
if (!name) { | ||
@@ -127,3 +110,4 @@ throw new Error('Must pass in a DTD name'); | ||
var params = [name]; | ||
const params = [name]; | ||
if (typeof ext !== 'undefined') { | ||
@@ -136,7 +120,7 @@ params.push(ext); | ||
return this._setDtd.apply(this, params); | ||
return this._setDtd(...params); | ||
}; | ||
/// @return array of namespaces in document | ||
Document.prototype.namespaces = function() { | ||
// / @return array of namespaces in document | ||
Document.prototype.namespaces = function namespaces() { | ||
assertRoot(this); | ||
@@ -147,15 +131,9 @@ | ||
Document.prototype.type = function() { | ||
return 'document'; | ||
}; | ||
module.exports = Document; | ||
/// parse a string into a html document | ||
/// @param string html string to parse | ||
/// @param {encoding:string, baseUrl:string} opts html string to parse | ||
/// @return a Document | ||
module.exports.fromHtml = function(string, opts) { | ||
opts = opts || {}; | ||
// / parse a string into a html document | ||
// / @param string html string to parse | ||
// / @param {encoding:string, baseUrl:string} opts html string to parse | ||
// / @return a Document | ||
module.exports.fromHtml = function fromHtml(string, opts = {}) { | ||
// if for some reason user did not specify an object for the options | ||
@@ -169,9 +147,7 @@ if (typeof opts !== 'object') { | ||
/// parse a string into a html document fragment | ||
/// @param string html string to parse | ||
/// @param {encoding:string, baseUrl:string} opts html string to parse | ||
/// @return a Document | ||
module.exports.fromHtmlFragment = function(string, opts) { | ||
opts = opts || {}; | ||
// / parse a string into a html document fragment | ||
// / @param string html string to parse | ||
// / @param {encoding:string, baseUrl:string} opts html string to parse | ||
// / @return a Document | ||
module.exports.fromHtmlFragment = function fromHtmlFragment(string, opts = {}) { | ||
// if for some reason user did not specify an object for the options | ||
@@ -188,7 +164,7 @@ if (typeof opts !== 'object') { | ||
/// parse a string into a xml document | ||
/// @param string xml string to parse | ||
/// @return a Document | ||
module.exports.fromXml = function(string, options) { | ||
return bindings.fromXml(string, options || {}); | ||
// / parse a string into a xml document | ||
// / @param string xml string to parse | ||
// / @return a Document | ||
module.exports.fromXml = function fromXml(string, options = {}) { | ||
return bindings.fromXml(string, options); | ||
}; |
@@ -1,19 +0,20 @@ | ||
var bindings = require('./bindings'); | ||
/* eslint-disable no-underscore-dangle */ | ||
/* eslint-disable no-param-reassign */ | ||
const bindings = require('./bindings'); | ||
/// create a new element on the given document | ||
/// @param doc the Document to create the element for | ||
/// @param name the element name | ||
/// @param {String} [content] element content | ||
/// @constructor | ||
// / create a new element on the given document | ||
// / @param doc the Document to create the element for | ||
// / @param name the element name | ||
// / @param {String} [content] element content | ||
// / @constructor | ||
function Element(doc, name, content) { | ||
if (!doc) { | ||
throw new Error('document argument required'); | ||
} else if (! (doc instanceof bindings.Document)) { | ||
throw new Error('document argument must be an ' + | ||
'instance of Document'); | ||
} else if (!name) { | ||
throw new Error('name argument required'); | ||
} | ||
if (!doc) { | ||
throw new Error('document argument required'); | ||
} else if (!(doc instanceof bindings.Document)) { | ||
throw new Error('document argument must be an instance of Document'); | ||
} else if (!name) { | ||
throw new Error('name argument required'); | ||
} | ||
return new bindings.Element(doc, name, content); | ||
return new bindings.Element(doc, name, content); | ||
} | ||
@@ -23,60 +24,60 @@ | ||
Element.prototype.attr = function() { | ||
if (arguments.length === 1) { | ||
var arg = arguments[0]; | ||
if (typeof arg === 'object') { | ||
// object setter | ||
// iterate keys/value to set attributes | ||
for (var k in arg) { | ||
this._attr(k, arg[k]); | ||
}; | ||
return this; | ||
} else if (typeof arg === 'string') { | ||
// getter | ||
return this._attr(arg); | ||
} | ||
} else if (arguments.length === 2) { | ||
// 2 arg setter | ||
var name = arguments[0]; | ||
var value = arguments[1]; | ||
this._attr(name, value); | ||
return this; | ||
Element.prototype.attr = function attr(...args) { | ||
if (args.length === 1) { | ||
const arg = args[0]; | ||
if (typeof arg === 'object') { | ||
// object setter | ||
// iterate keys/value to set attributes | ||
for (const k in arg) { | ||
this._attr(k, arg[k]); | ||
} | ||
return this; | ||
} else if (typeof arg === 'string') { | ||
// getter | ||
return this._attr(arg); | ||
} | ||
}; | ||
} else if (args.length === 2) { | ||
// 2 arg setter | ||
const name = args[0]; | ||
const value = args[1]; | ||
/// helper method to attach a new node to this element | ||
/// @param name the element name | ||
/// @param {String} [content] element content | ||
Element.prototype.node = function(name, content) { | ||
var elem = Element(this.doc(), name, content); | ||
this.addChild(elem); | ||
return elem; | ||
this._attr(name, value); | ||
return this; | ||
} | ||
}; | ||
/// helper method to attach a cdata to this element | ||
/// @param name the element name | ||
/// @param {String} [content] element content | ||
Element.prototype.cdata = function(content) { | ||
this.addCData(content); | ||
return this; | ||
// / helper method to attach a new node to this element | ||
// / @param name the element name | ||
// / @param {String} [content] element content | ||
Element.prototype.node = function node(name, content) { | ||
const elem = Element(this.doc(), name, content); | ||
this.addChild(elem); | ||
return elem; | ||
}; | ||
Element.prototype.get = function() { | ||
var res = this.find.apply(this, arguments); | ||
if (Array.isArray(res)) { | ||
return res[0]; | ||
} else { | ||
return res; | ||
} | ||
Element.prototype.get = function get(...args) { | ||
const res = this.find(...args); | ||
if (Array.isArray(res)) { | ||
return res[0]; | ||
} | ||
return res; | ||
}; | ||
Element.prototype.defineNamespace = function(prefix, href) { | ||
// if no prefix specified | ||
if (!href) { | ||
href = prefix; | ||
prefix = null; | ||
} | ||
return new bindings.Namespace(this, prefix, href); | ||
Element.prototype.defineNamespace = function defineNamespace(prefix, href) { | ||
// if no prefix specified | ||
if (!href) { | ||
href = prefix; | ||
prefix = null; | ||
} | ||
return new bindings.Namespace(this, prefix, href); | ||
}; | ||
module.exports = Element; |
@@ -1,14 +0,14 @@ | ||
var events = require('events'); | ||
const events = require('events'); | ||
var bindings = require('./bindings'); | ||
const bindings = require('./bindings'); | ||
var SaxParser = function(callbacks) { | ||
var parser = new bindings.SaxParser(); | ||
const SaxParser = function SaxParser(callbacks) { | ||
const parser = new bindings.SaxParser(); | ||
// attach callbacks | ||
for (var callback in callbacks) { | ||
parser.on(callback, callbacks[callback]); | ||
} | ||
// attach callbacks | ||
for (const callback in callbacks) { | ||
parser.on(callback, callbacks[callback]); | ||
} | ||
return parser; | ||
return parser; | ||
}; | ||
@@ -18,14 +18,14 @@ | ||
// Copy over the methods instead. | ||
for (var k in events.EventEmitter.prototype) | ||
bindings.SaxParser.prototype[k] = events.EventEmitter.prototype[k]; | ||
for (const k in events.EventEmitter.prototype) | ||
bindings.SaxParser.prototype[k] = events.EventEmitter.prototype[k]; | ||
var SaxPushParser = function(callbacks) { | ||
var parser = new bindings.SaxPushParser(); | ||
const SaxPushParser = function SaxPushParser(callbacks) { | ||
const parser = new bindings.SaxPushParser(); | ||
// attach callbacks | ||
for (var callback in callbacks) { | ||
parser.on(callback, callbacks[callback]); | ||
} | ||
// attach callbacks | ||
for (const callback in callbacks) { | ||
parser.on(callback, callbacks[callback]); | ||
} | ||
return parser; | ||
return parser; | ||
}; | ||
@@ -35,7 +35,6 @@ | ||
// Copy over the methods instead. | ||
for (var k in events.EventEmitter.prototype) | ||
bindings.SaxPushParser.prototype[k] = events.EventEmitter.prototype[k]; | ||
for (const k in events.EventEmitter.prototype) | ||
bindings.SaxPushParser.prototype[k] = events.EventEmitter.prototype[k]; | ||
module.exports.SaxParser = SaxParser; | ||
module.exports.SaxPushParser = SaxPushParser; | ||
@@ -1,9 +0,12 @@ | ||
var bindings = require('./bindings'); | ||
/* eslint-disable no-underscore-dangle */ | ||
const bindings = require('./bindings'); | ||
/// Create a new TextWriter instance | ||
/// @constructor | ||
var TextWriter = function() { | ||
var writer = new bindings.TextWriter(); | ||
writer._openMemory(); | ||
return writer; | ||
// / Create a new TextWriter instance | ||
// / @constructor | ||
const TextWriter = function TextWriter() { | ||
const writer = new bindings.TextWriter(); | ||
writer._openMemory(); | ||
return writer; | ||
}; | ||
@@ -13,189 +16,170 @@ | ||
/// Return the content of the output buffer. | ||
/// @return buffer content | ||
TextWriter.prototype.toString = function() { | ||
return this._bufferContent(); | ||
} | ||
// / Return the content of the output buffer. | ||
// / @param {boolean} [clear] clear the buffer afterwards. | ||
TextWriter.prototype.outputMemory = function outputMemory(clear) { | ||
const result = this.toString(); | ||
/// Empty the memory buffer | ||
/// @return buffer content | ||
TextWriter.prototype.clear = function() { | ||
this._bufferEmpty(); | ||
} | ||
if (clear || typeof clear === 'undefined') { | ||
this.clear(); | ||
} | ||
/// Return the content of the output buffer. | ||
/// @param {boolean} [clear] clear the buffer afterwards. | ||
TextWriter.prototype.outputMemory = function(clear) { | ||
var result = this.toString(); | ||
if (clear || typeof clear === 'undefined') { | ||
this.clear(); | ||
} | ||
return result; | ||
} | ||
return result; | ||
}; | ||
/// Write document preamble | ||
/// @param {string} [version] xml version, default 1.0 | ||
/// @param {string} [encoding] the encoding, default undefined | ||
/// @param {string} [standalone] (yes or no), default undefined | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startDocument = function(version, encoding, standalone) { | ||
var result; | ||
// / Write document preamble | ||
// / @param {string} [version] xml version, default 1.0 | ||
// / @param {string} [encoding] the encoding, default undefined | ||
// / @param {string} [standalone] (yes or no), default undefined | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startDocument = function startDocument( | ||
version, | ||
encoding, | ||
standalone | ||
) { | ||
if (typeof standalone === 'boolean') { | ||
// eslint-disable-next-line no-param-reassign | ||
standalone = standalone ? 'yes' : 'no'; | ||
} | ||
if (typeof standalone === 'boolean') { | ||
standalone = standalone ? "yes" : "no"; | ||
} | ||
const result = this._startDocument(version, encoding, standalone); | ||
result = this._startDocument(version, encoding, standalone); | ||
if (result === -1) { | ||
throw new Error('Failed to start document'); | ||
} | ||
}; | ||
if (result === -1) { | ||
throw new Error("Failed to start document"); | ||
} | ||
} | ||
// / Close all elements and end the document | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endDocument = function endDocument() { | ||
const result = this._endDocument(); | ||
/// Close all elements and end the document | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endDocument = function() { | ||
var result; | ||
if (result === -1) { | ||
throw new Error('Failed to end document'); | ||
} | ||
result = this._endDocument(); | ||
return result; | ||
}; | ||
if (result === -1) { | ||
throw new Error("Failed to end document"); | ||
} | ||
// / Start an element | ||
// / @param {string} [prefix] namespace prefix | ||
// / @param {string} name element local name | ||
// / @param {string} [namespaceURI] namespace URI or NULL | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startElementNS = function startElementNs( | ||
prefix, | ||
name, | ||
namespaceURI | ||
) { | ||
const result = this._startElementNS(prefix, name, namespaceURI); | ||
return result; | ||
} | ||
if (result === -1) { | ||
throw new Error('Failed to start element'); | ||
} | ||
/// Start an element | ||
/// @param {string} [prefix] namespace prefix | ||
/// @param {string} name element local name | ||
/// @param {string} [namespaceURI] namespace URI or NULL | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startElementNS = function(prefix, name, namespaceURI) { | ||
var result; | ||
return result; | ||
}; | ||
result = this._startElementNS(prefix, name, namespaceURI); | ||
// / End the current element | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endElement = function endElement() { | ||
const result = this._endElement(); | ||
if (result === -1) { | ||
throw new Error("Failed to start element"); | ||
} | ||
if (result === -1) { | ||
throw new Error('Failed to end element'); | ||
} | ||
return result; | ||
} | ||
return result; | ||
}; | ||
/// End the current element | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endElement = function() { | ||
var result; | ||
// / Start an attribute | ||
// / @param {string} [prefix] namespace prefix | ||
// / @param {string} name local name | ||
// / @param {string} [namespaceURI] namespace URI or NULL | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startAttributeNS = function startAttributeNS( | ||
prefix, | ||
name, | ||
namespaceURI | ||
) { | ||
const result = this._startAttributeNS(prefix, name, namespaceURI); | ||
result = this._endElement(); | ||
if (result === -1) { | ||
throw new Error('Failed to start attribute'); | ||
} | ||
if (result === -1) { | ||
throw new Error("Failed to end element"); | ||
} | ||
return result; | ||
}; | ||
return result; | ||
} | ||
// / End the current attribute | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endAttribute = function endAttribute() { | ||
const result = this._endAttribute(); | ||
/// Start an attribute | ||
/// @param {string} [prefix] namespace prefix | ||
/// @param {string} name local name | ||
/// @param {string} [namespaceURI] namespace URI or NULL | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startAttributeNS = function(prefix, name, namespaceURI) { | ||
var result; | ||
if (result === -1) { | ||
throw new Error('Failed to end attribute'); | ||
} | ||
result = this._startAttributeNS(prefix, name, namespaceURI); | ||
return result; | ||
}; | ||
if (result === -1) { | ||
throw new Error("Failed to start attribute"); | ||
} | ||
// / Start a CDATA section | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startCdata = function startCdata() { | ||
const result = this._startCdata(); | ||
return result; | ||
} | ||
if (result === -1) { | ||
throw new Error('Failed to start CDATA section'); | ||
} | ||
/// End the current attribute | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endAttribute = function() { | ||
var result; | ||
return result; | ||
}; | ||
result = this._endAttribute(); | ||
// / End a CDATA section | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endCdata = function endCdata() { | ||
const result = this._endCdata(); | ||
if (result === -1) { | ||
throw new Error("Failed to end attribute"); | ||
} | ||
if (result === -1) { | ||
throw new Error('Failed to end CDATA section'); | ||
} | ||
return result; | ||
} | ||
return result; | ||
}; | ||
/// Start a CDATA section | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startCdata = function() { | ||
var result; | ||
// / Start a comment | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startComment = function startComment() { | ||
const result = this._startComment(); | ||
result = this._startCdata(); | ||
if (result === -1) { | ||
throw new Error('Failed to start Comment section'); | ||
} | ||
if (result === -1) { | ||
throw new Error("Failed to start CDATA section"); | ||
} | ||
return result; | ||
}; | ||
return result; | ||
} | ||
// / End a comment | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endComment = function endComment() { | ||
const result = this._endComment(); | ||
/// End a CDATA section | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endCdata = function() { | ||
var result; | ||
if (result === -1) { | ||
throw new Error('Failed to end Comment section'); | ||
} | ||
result = this._endCdata(); | ||
return result; | ||
}; | ||
if (result === -1) { | ||
throw new Error("Failed to end CDATA section"); | ||
} | ||
// / Write text | ||
// / @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.writeString = function writeString(text) { | ||
const result = this._writeString(text); | ||
return result; | ||
} | ||
if (result === -1) { | ||
throw new Error('Failed to write string'); | ||
} | ||
/// Start a comment | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.startComment = function() { | ||
var result; | ||
return result; | ||
}; | ||
result = this._startComment(); | ||
if (result === -1) { | ||
throw new Error("Failed to start Comment section"); | ||
} | ||
return result; | ||
} | ||
/// End a comment | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.endComment = function() { | ||
var result; | ||
result = this._endComment(); | ||
if (result === -1) { | ||
throw new Error("Failed to end Comment section"); | ||
} | ||
return result; | ||
} | ||
/// Write text | ||
/// @return number of bytes written (may be 0 because of buffering) | ||
TextWriter.prototype.writeString = function(text) { | ||
var result; | ||
result = this._writeString(text); | ||
if (result === -1) { | ||
throw new Error("Failed to write string"); | ||
} | ||
return result; | ||
} | ||
module.exports = TextWriter; |
@@ -16,3 +16,3 @@ { | ||
"description": "libxml bindings for v8 javascript engine", | ||
"version": "0.24.0", | ||
"version": "0.25.0", | ||
"scripts": { | ||
@@ -22,3 +22,4 @@ "build": "node-pre-gyp install --build-from-source", | ||
"test": "node --expose_gc ./node_modules/jest/bin/jest.js", | ||
"lint": "eslint index.js test" | ||
"lint": "eslint index.js test", | ||
"tsd": "tsd" | ||
}, | ||
@@ -46,14 +47,15 @@ "repository": { | ||
"eslint-config-marudor": "^7.2.0", | ||
"eslint-config-prettier": "^6.9.0", | ||
"eslint-config-prettier": "^6.10.0", | ||
"eslint-plugin-babel": "^5.3.0", | ||
"eslint-plugin-import": "^2.19.1", | ||
"eslint-plugin-jest": "^23.4.0", | ||
"eslint-plugin-import": "^2.20.0", | ||
"eslint-plugin-jest": "^23.6.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"eslint-plugin-sort-imports-es6-autofix": "^0.5.0", | ||
"eslint-plugin-testing-library": "^1.3.4", | ||
"eslint-plugin-testing-library": "^2.0.0", | ||
"github-release-cli": "^1.3.1", | ||
"jest": "^24.9.0", | ||
"jest": "^25.1.0", | ||
"jest-watch-typeahead": "^0.4.2", | ||
"prettier": "^1.19.1" | ||
"prettier": "^1.19.1", | ||
"tsd": "^0.11.0" | ||
} | ||
} |
const libxml = require('../index'); | ||
describe('comment', () => { | ||
describe('throws', () => { | ||
it('throws without new', () => { | ||
const doc = libxml.Document(); | ||
expect(() => libxml.Comment(doc, 'Test')).toThrow( | ||
"Class constructor Comment cannot be invoked without 'new'" | ||
); | ||
}); | ||
it('throws without doc', () => { | ||
expect(() => new libxml.Comment()).toThrow('document argument required'); | ||
}); | ||
it('throws if doc is a primitive', () => { | ||
expect(() => new libxml.Comment('test')).toThrow( | ||
'document argument must be an instance of Document' | ||
); | ||
}); | ||
it('throw if doc is empty object', () => { | ||
expect(() => new libxml.Comment({})).toThrow( | ||
'document argument must be an instance of Document' | ||
); | ||
}); | ||
it('throw if doc is wrong object', () => { | ||
const doc = libxml.Document(); | ||
const text = new libxml.Text(doc, 'test Text'); | ||
expect(() => new libxml.Comment(text)).toThrow( | ||
'document argument must be an instance of Document' | ||
); | ||
}); | ||
}); | ||
it('new', () => { | ||
const doc = libxml.Document(); | ||
const comm = libxml.Comment(doc, 'comment1'); | ||
const comm = new libxml.Comment(doc, 'comment1'); | ||
@@ -14,3 +44,3 @@ doc.root(comm); | ||
const doc = libxml.Document(); | ||
const comm = libxml.Comment(doc); | ||
const comm = new libxml.Comment(doc); | ||
@@ -23,3 +53,3 @@ comm.text('comment2'); | ||
const doc = libxml.Document(); | ||
const comm = libxml.Comment(doc); | ||
const comm = new libxml.Comment(doc); | ||
const theText = 'my comment <has> special ch&r&cters'; | ||
@@ -33,3 +63,3 @@ | ||
const doc = libxml.Document(); | ||
const comm = libxml.Comment(doc); | ||
const comm = new libxml.Comment(doc); | ||
const theText = 'my comment <has> special ch&r&cters'; | ||
@@ -36,0 +66,0 @@ |
@@ -249,2 +249,11 @@ const libxml = require('../index'); | ||
}); | ||
it('add cdata', () => { | ||
const doc = libxml.Document(); | ||
const element = new libxml.Element(doc, 'name', 'content'); | ||
const cdataResult = element.cdata('cdata'); | ||
expect(cdataResult).toBe(element); | ||
expect(element.toString()).toContain('[CDATA[cdata]]'); | ||
}); | ||
}); |
@@ -7,4 +7,15 @@ const libxml = require('../index'); | ||
expect(() => libxml.Text()).toThrow(); | ||
expect(() => libxml.Text(doc)).toThrow(); | ||
expect(() => new libxml.Text(undefined, '')).toThrow( | ||
'document argument required' | ||
); | ||
expect(() => new libxml.Text()).toThrow('document argument required'); | ||
expect(() => new libxml.Text({}, '')).toThrow( | ||
'document argument must be an instance of Document' | ||
); | ||
expect(() => new libxml.Text(doc)).toThrow( | ||
'content argument must be of type string' | ||
); | ||
expect(() => new libxml.Text(doc, 1)).toThrow( | ||
'content argument must be of type string' | ||
); | ||
}); | ||
@@ -14,3 +25,3 @@ | ||
const doc = libxml.Document(); | ||
const elem = libxml.Text(doc, 'node content'); | ||
const elem = new libxml.Text(doc, 'node content'); | ||
@@ -23,3 +34,3 @@ doc.root(elem); | ||
const doc = libxml.Document(); | ||
const elem = libxml.Text(doc, 'node content'); | ||
const elem = new libxml.Text(doc, 'node content'); | ||
@@ -34,3 +45,3 @@ // change content | ||
const doc = libxml.Document(); | ||
const elem = libxml.Text(doc, 'getters'); | ||
const elem = new libxml.Text(doc, 'getters'); | ||
@@ -46,3 +57,3 @@ expect(() => { | ||
const doc = libxml.Document(); | ||
const elem = libxml.Text(doc, 'node content'); | ||
const elem = new libxml.Text(doc, 'node content'); | ||
@@ -59,3 +70,3 @@ doc.root(elem); | ||
const doc = libxml.Document(); | ||
const elem = libxml.Text(doc, 'node content'); | ||
const elem = new libxml.Text(doc, 'node content'); | ||
@@ -80,3 +91,3 @@ doc.root(elem); | ||
doc.root().addChild(libxml.Text(doc, 'x&x')); | ||
doc.root().addChild(new libxml.Text(doc, 'x&x')); | ||
@@ -83,0 +94,0 @@ expect(doc.root().toString()).toBe('<p>x&x</p>'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
7239381
15
199
2911