Comparing version 0.25.0 to 0.25.1
370
index.d.ts
@@ -7,48 +7,57 @@ import { EventEmitter } from 'events'; | ||
// tslint:disable-next-line:strict-export-declare-modifiers | ||
interface StringMap { [key: string]: string; } | ||
interface StringMap { | ||
[key: string]: string; | ||
} | ||
// tslint:disable-next-line:strict-export-declare-modifiers | ||
interface ParserOptions { | ||
recover?: boolean; | ||
noent?: boolean; | ||
dtdload?: boolean; | ||
doctype?: boolean; | ||
dtdattr?: any; | ||
dtdvalid?: boolean; | ||
noerror?: boolean; | ||
errors?: boolean; | ||
nowarning?: boolean; | ||
warnings?: boolean; | ||
pedantic?: boolean; | ||
noblanks?: boolean; | ||
blanks?: boolean; | ||
sax1?: boolean; | ||
xinclude?: boolean; | ||
nonet?: boolean; | ||
net?: boolean; | ||
nodict?: boolean; | ||
dict?: boolean; | ||
nsclean?: boolean; | ||
implied?: boolean; | ||
nocdata?: boolean; | ||
cdata?: boolean; | ||
noxincnode?: boolean; | ||
compact?: boolean; | ||
old?: boolean; | ||
nobasefix?: boolean; | ||
basefix?: boolean; | ||
huge?: boolean; | ||
oldsax?: boolean; | ||
ignore_enc?: boolean; | ||
big_lines?: boolean; | ||
baseUrl?: string; | ||
recover?: boolean; | ||
noent?: boolean; | ||
dtdload?: boolean; | ||
doctype?: boolean; | ||
dtdattr?: any; | ||
dtdvalid?: boolean; | ||
noerror?: boolean; | ||
errors?: boolean; | ||
nowarning?: boolean; | ||
warnings?: boolean; | ||
pedantic?: boolean; | ||
noblanks?: boolean; | ||
blanks?: boolean; | ||
sax1?: boolean; | ||
xinclude?: boolean; | ||
nonet?: boolean; | ||
net?: boolean; | ||
nodict?: boolean; | ||
dict?: boolean; | ||
nsclean?: boolean; | ||
implied?: boolean; | ||
nocdata?: boolean; | ||
cdata?: boolean; | ||
noxincnode?: boolean; | ||
compact?: boolean; | ||
old?: boolean; | ||
nobasefix?: boolean; | ||
basefix?: boolean; | ||
huge?: boolean; | ||
oldsax?: boolean; | ||
ignore_enc?: boolean; | ||
big_lines?: boolean; | ||
baseUrl?: string; | ||
} | ||
export function parseXml(source: string, options?: ParserOptions): Document; | ||
export function parseXmlString(source: string, options?: ParserOptions): Document; | ||
export function parseXmlString( | ||
source: string, | ||
options?: ParserOptions | ||
): Document; | ||
export function parseHtml(source: string, options?: ParserOptions): Document; | ||
export function parseHtmlString(source: string, options?: ParserOptions): Document; | ||
export function parseHtmlFragment(source: string, options?: ParserOptions): Document; | ||
export function parseHtmlString( | ||
source: string, | ||
options?: ParserOptions | ||
): Document; | ||
export function parseHtmlFragment( | ||
source: string, | ||
options?: ParserOptions | ||
): Document; | ||
@@ -59,165 +68,200 @@ export function memoryUsage(): number; | ||
export class Document { | ||
/** | ||
* Create a new XML Document | ||
* @param version XML document version, defaults to 1.0 | ||
* @param encoding Encoding, defaults to utf8 | ||
*/ | ||
constructor(version?: number, encoding?: string); | ||
/** | ||
* Create a new XML Document | ||
* @param version XML document version, defaults to 1.0 | ||
* @param encoding Encoding, defaults to utf8 | ||
*/ | ||
constructor(version?: string, encoding?: string); | ||
errors: SyntaxError[]; | ||
validationErrors: ValidationError[]; | ||
errors: SyntaxError[]; | ||
validationErrors: ValidationError[]; | ||
child(idx: number): Node|null; | ||
childNodes(): Node[]; | ||
encoding(): string; | ||
encoding(enc: string): this; | ||
find<T extends Node = Node>(xpath: string, ns_uri?: string): T[]; | ||
find<T extends Node = Node>(xpath: string, namespaces: StringMap): T[]; | ||
get<T extends Node = Node>(xpath: string, ns_uri?: string): T|null; | ||
get<T extends Node = Node>(xpath: string, namespaces: StringMap): T|null; | ||
node(name: string, content?: string): Element; | ||
root(): Element|null; | ||
root(newRoot: Node): Node; | ||
toString(formatted?: boolean): string; | ||
type(): 'document'; | ||
validate(xsdDoc: Document): boolean; | ||
version(): string; | ||
setDtd(name: string, ext: string, sys: string): void; | ||
getDtd(): { | ||
name: string; | ||
externalId: string; | ||
systemId: string; | ||
}; | ||
child(idx: number): Node | null; | ||
childNodes(): Node[]; | ||
encoding(): string; | ||
encoding(enc: string): this; | ||
find<T extends Node = Node>(xpath: string, ns_uri?: string): T[]; | ||
find<T extends Node = Node>(xpath: string, namespaces: StringMap): T[]; | ||
get<T extends Node = Node>(xpath: string, ns_uri?: string): T | null; | ||
get<T extends Node = Node>(xpath: string, namespaces: StringMap): T | null; | ||
node(name: string, content?: string): Element; | ||
root(): Element | null; | ||
root(newRoot: Node): Node; | ||
toString(formatted?: boolean): string; | ||
type(): 'document'; | ||
validate(xsdDoc: Document): boolean; | ||
version(): string; | ||
setDtd(name: string, ext: string, sys: string): void; | ||
getDtd(): { | ||
name: string; | ||
externalId: string; | ||
systemId: string; | ||
}; | ||
} | ||
export class Node { | ||
doc(): Document; | ||
parent(): Element|Document; | ||
/** | ||
* The namespace or null in case of comment nodes | ||
*/ | ||
namespace(): Namespace|null; | ||
doc(): Document; | ||
parent(): Element | Document; | ||
/** | ||
* The namespace or null in case of comment nodes | ||
*/ | ||
namespace(): Namespace | null; | ||
/** | ||
* An array of namespaces that the object belongs to. | ||
* | ||
* @param local If it is true, only the namespace declarations local to this | ||
* node are returned, rather than all of the namespaces in scope | ||
* at this node (including the ones from the parent elements). | ||
*/ | ||
namespaces(local?: boolean): Namespace[]; | ||
/** | ||
* An array of namespaces that the object belongs to. | ||
* | ||
* @param local If it is true, only the namespace declarations local to this | ||
* node are returned, rather than all of the namespaces in scope | ||
* at this node (including the ones from the parent elements). | ||
*/ | ||
namespaces(local?: boolean): Namespace[]; | ||
prevSibling(): Node|null; | ||
nextSibling(): Node|null; | ||
prevSibling(): Node | null; | ||
nextSibling(): Node | null; | ||
line(): number; | ||
type(): 'comment'|'element'|'text'|'attribute'; | ||
remove(): this; | ||
clone(): this; | ||
/** | ||
* Serializes the node to a string. The string will contain all contents of the node formatted as XML and can be used to print the node. | ||
*/ | ||
toString(format?: boolean|{ | ||
declaration: boolean; | ||
selfCloseEmpty: boolean; | ||
whitespace: boolean; | ||
type: 'xml'|'html'|'xhtml' | ||
}): string; | ||
line(): number; | ||
type(): 'comment' | 'element' | 'text' | 'attribute' | 'pi'; | ||
remove(): this; | ||
clone(): this; | ||
/** | ||
* Serializes the node to a string. The string will contain all contents of the node formatted as XML and can be used to print the node. | ||
*/ | ||
toString( | ||
format?: | ||
| boolean | ||
| { | ||
declaration: boolean; | ||
selfCloseEmpty: boolean; | ||
whitespace: boolean; | ||
type: 'xml' | 'html' | 'xhtml'; | ||
} | ||
): string; | ||
} | ||
export class Element extends Node { | ||
constructor(doc: Document, name: string, content?: string); | ||
node(name: string, content?: string): Element; | ||
name(): string; | ||
name(newName: string): this; | ||
text(): string; | ||
text(newText: string): this; | ||
attr(name: string): Attribute|null; //getter | ||
attr(name: string, value: string): this; //setter | ||
attr(attrObject: StringMap): this; //setter using stringMap | ||
attrs(): Attribute[]; | ||
cdata(data: string): this; | ||
constructor(doc: Document, name: string, content?: string); | ||
node(name: string, content?: string): Element; | ||
name(): string; | ||
name(newName: string): this; | ||
text(): string; | ||
text(newText: string): this; | ||
attr(name: string): Attribute | null; //getter | ||
attr(name: string, value: string): this; //setter | ||
attr(attrObject: StringMap): this; //setter using stringMap | ||
attrs(): Attribute[]; | ||
cdata(data: string): this; | ||
doc(): Document; | ||
child(idx: number): Node | null; | ||
childNodes(): Node[]; | ||
doc(): Document; | ||
child(idx: number): Node | null; | ||
childNodes(): Node[]; | ||
/** | ||
* @return The original element, not the child. | ||
*/ | ||
addChild(child: Element): this; | ||
/** | ||
* @return The original element, not the child. | ||
*/ | ||
addChild(child: Element): this; | ||
prevElement(): Element|null; | ||
nextElement(): Element|null; | ||
addNextSibling(siblingNode: Node): Node; | ||
addPrevSibling(siblingNode: Node): Node; | ||
prevElement(): Element | null; | ||
nextElement(): Element | null; | ||
addNextSibling<T extends Node>(siblingNode: T): T; | ||
addPrevSibling<T extends Node>(siblingNode: T): T; | ||
find<T extends Node = Node>(xpath: string, ns_uri?: string): T[]; | ||
find<T extends Node = Node>(xpath: string, namespaces: StringMap): T[]; | ||
get<T extends Node = Node>(xpath: string, ns_uri?: string): T|null; | ||
get<T extends Node = Node>(xpath: string, namespaces: StringMap): T|null; | ||
find<T extends Node = Node>(xpath: string, ns_uri?: string): T[]; | ||
find<T extends Node = Node>(xpath: string, namespaces: StringMap): T[]; | ||
get<T extends Node = Node>(xpath: string, ns_uri?: string): T | null; | ||
get<T extends Node = Node>(xpath: string, namespaces: StringMap): T | null; | ||
defineNamespace(prefixOrHref: string, hrefInCaseOfPrefix?: string): Namespace; | ||
defineNamespace(prefixOrHref: string, hrefInCaseOfPrefix?: string): Namespace; | ||
namespace(): Namespace|null; | ||
namespace(newNamespace: Namespace): this; | ||
namespace(prefixOrHref: string, hrefInCaseOfPrefix?: string): this; | ||
namespace(): Namespace | null; | ||
namespace(newNamespace: Namespace): this; | ||
namespace(prefixOrHref: string, hrefInCaseOfPrefix?: string): this; | ||
replace(replacement: string): string; | ||
replace(replacement: Element): Element; | ||
replace(replacement: string): string; | ||
replace<T extends Node>(replacement: T): T; | ||
path(): string; | ||
path(): string; | ||
} | ||
export class Attribute { | ||
name(): string; | ||
value(): string; | ||
value(newValue: string): Attribute; | ||
namespace(): Namespace; | ||
export class Attribute extends Node { | ||
name(): string; | ||
node(): Element; | ||
value(): string; | ||
value(newValue: string): Attribute; | ||
namespace(): Namespace | null; | ||
} | ||
remove(): void; | ||
export class Text extends Node { | ||
constructor(doc: Document, content: string); | ||
addNextSibling<T extends Node>(siblingNode: T): T; | ||
addPrevSibling<T extends Node>(siblingNode: T): T; | ||
nextElement(): Element | null; | ||
prevElement(): Element | null; | ||
replace(replacement: string): string; | ||
replace<T extends Node>(replacement: T): T; | ||
text(): string; | ||
text(newContent: string): this; | ||
} | ||
export class Comment extends Node { | ||
constructor(doc: Document, content?: string); | ||
text(): string; | ||
text(newContent: string): this; | ||
} | ||
export class ProcessingInstruction extends Node { | ||
constructor(doc: Document, name: string, content?: string); | ||
name(): string; | ||
name(newName: string): this; | ||
text(): string; | ||
text(newContent: string): this; | ||
} | ||
export class Namespace { | ||
href(): string; | ||
prefix(): string; | ||
href(): string; | ||
prefix(): string; | ||
} | ||
export class SaxParser extends EventEmitter { | ||
constructor(); | ||
parseString(source: string): boolean; | ||
constructor(); | ||
parseString(source: string): boolean; | ||
} | ||
export class SaxPushParser extends EventEmitter { | ||
constructor(); | ||
push(source: string): boolean; | ||
constructor(); | ||
push(source: string): boolean; | ||
} | ||
export interface SyntaxError extends Error { | ||
domain: number|null; | ||
code: number|null; | ||
level: number|null; | ||
file: string|null; | ||
line: number|null; | ||
/** | ||
* 1-based column number, 0 if not applicable/available. | ||
*/ | ||
column: number; | ||
domain: number | null; | ||
code: number | null; | ||
level: number | null; | ||
file: string | null; | ||
line: number | null; | ||
/** | ||
* 1-based column number, 0 if not applicable/available. | ||
*/ | ||
column: number; | ||
str1: number|null; | ||
str2: number|null; | ||
str3: number|null; | ||
int1: number|null; | ||
str1: number | null; | ||
str2: number | null; | ||
str3: number | null; | ||
int1: number | null; | ||
} | ||
export interface ValidationError extends Error { | ||
domain: number|null; | ||
code: number|null; | ||
level: number|null; | ||
domain: number | null; | ||
code: number | null; | ||
level: number | null; | ||
line: number|null; | ||
/** | ||
* 1-based column number, 0 if not applicable/available. | ||
*/ | ||
column: number; | ||
line: number | null; | ||
/** | ||
* 1-based column number, 0 if not applicable/available. | ||
*/ | ||
column: number; | ||
} |
@@ -45,2 +45,2 @@ // js acts as a wrapper to the c++ bindings | ||
module.exports.TextWriter = require('./lib/textwriter.js'); | ||
module.exports.TextWriter = bindings.TextWriter; |
@@ -12,14 +12,4 @@ /* eslint-disable no-underscore-dangle */ | ||
// / 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); | ||
const Document = bindings.Document; | ||
doc.encoding(encoding); | ||
return doc; | ||
} | ||
Document.prototype = bindings.Document.prototype; | ||
@@ -67,31 +57,2 @@ | ||
// / @return a string representation of the document | ||
Document.prototype.toString = function toString(formatted = true) { | ||
return this._toString(formatted); | ||
}; | ||
// / @return whether the XmlDocument is valid | ||
Document.prototype.validate = function validate(xsd) { | ||
if (!xsd) { | ||
throw new Error('Must pass xsd'); | ||
} | ||
if (!(xsd instanceof Document)) { | ||
throw new Error('Must pass XmlDocument'); | ||
} | ||
return this._validate(xsd); | ||
}; | ||
// / @return whether the XmlDocument is valid using Relaxed NG | ||
Document.prototype.rngValidate = function rngValidate(rng) { | ||
if (!rng) { | ||
throw new Error('Must pass xsd'); | ||
} | ||
if (!(rng instanceof Document)) { | ||
throw new Error('Must pass XmlDocument'); | ||
} | ||
return this._rngValidate(rng); | ||
}; | ||
Document.prototype.setDtd = function setDtd(name, ext, sys) { | ||
@@ -98,0 +59,0 @@ if (!name) { |
@@ -16,3 +16,3 @@ { | ||
"description": "libxml bindings for v8 javascript engine", | ||
"version": "0.25.0", | ||
"version": "0.25.1", | ||
"scripts": { | ||
@@ -19,0 +19,0 @@ "build": "node-pre-gyp install --build-from-source", |
@@ -6,3 +6,3 @@ const libxml = require('../index'); | ||
it('throws without new', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -27,3 +27,3 @@ expect(() => libxml.Comment(doc, 'Test')).toThrow( | ||
it('throw if doc is wrong object', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const text = new libxml.Text(doc, 'test Text'); | ||
@@ -37,3 +37,3 @@ | ||
it('new', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const comm = new libxml.Comment(doc, 'comment1'); | ||
@@ -46,3 +46,3 @@ | ||
it('text', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const comm = new libxml.Comment(doc); | ||
@@ -55,3 +55,3 @@ | ||
it('textWithSpecialCharacters', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const comm = new libxml.Comment(doc); | ||
@@ -65,3 +65,3 @@ const theText = 'my comment <has> special ch&r&cters'; | ||
it('toStringWithSpecialCharacters', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const comm = new libxml.Comment(doc); | ||
@@ -68,0 +68,0 @@ const theText = 'my comment <has> special ch&r&cters'; |
@@ -56,3 +56,3 @@ const libxml = require('../index'); | ||
it('setDtd', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -86,3 +86,3 @@ doc.setDtd('html'); | ||
it('blank', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -94,3 +94,3 @@ expect('1.0').toBe(doc.version()); | ||
it('version', () => { | ||
const doc = libxml.Document('2.0'); | ||
const doc = new libxml.Document('2.0'); | ||
@@ -102,3 +102,3 @@ expect('2.0').toBe(doc.version()); | ||
it('type', () => { | ||
const doc = libxml.Document('2.0'); | ||
const doc = new libxml.Document('2.0'); | ||
@@ -109,3 +109,3 @@ expect('document').toBe(doc.type()); | ||
it('full', () => { | ||
const doc = libxml.Document('2.0', 'UTF-8'); | ||
const doc = new libxml.Document('2.0', 'UTF-8'); | ||
@@ -117,3 +117,3 @@ expect('2.0').toBe(doc.version()); | ||
it('null root', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -124,3 +124,3 @@ expect(doc.root()).toBeNull(); | ||
it('new root', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -139,3 +139,3 @@ | ||
it('one child', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -153,3 +153,3 @@ doc | ||
it('root children', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -166,3 +166,3 @@ doc | ||
it('xpath', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -178,3 +178,3 @@ doc | ||
it('xpath child', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -202,3 +202,3 @@ doc | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -347,2 +347,6 @@ | ||
expect(() => xmlDocValid.rngValidate()).toThrow('Must pass xsd'); | ||
expect(() => xmlDocValid.rngValidate(undefined)).toThrow('Must pass xsd'); | ||
expect(() => xmlDocValid.rngValidate(null)).toThrow('Must pass xsd'); | ||
expect(() => xmlDocValid.rngValidate(0)).toThrow('Must pass XmlDocument'); | ||
expect(xmlDocValid.rngValidate(rngDoc)).toBe(true); | ||
@@ -349,0 +353,0 @@ expect(xmlDocValid.validationErrors.length).toBe(0); |
@@ -5,3 +5,3 @@ const libxml = require('../index'); | ||
it('new', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = libxml.Element(doc, 'name1'); | ||
@@ -15,3 +15,3 @@ | ||
it('newWithContent', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = libxml.Element(doc, 'name1', 'content && more content <>'); | ||
@@ -26,3 +26,3 @@ | ||
it('setters', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -42,3 +42,3 @@ | ||
it('getters', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -51,3 +51,3 @@ | ||
it('remove', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -63,3 +63,3 @@ const child = elem.node('child'); | ||
it('toString', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -85,3 +85,3 @@ | ||
it('path', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -96,3 +96,3 @@ const gchild = root.node('child').node('grandchild'); | ||
it('move', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -112,3 +112,3 @@ const child = elem.node('child'); | ||
it('addChild', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -122,3 +122,3 @@ const newChild = libxml.Element(doc, 'new-child'); | ||
it('add prev sibling', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -140,3 +140,3 @@ | ||
it('add next sibling', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -159,3 +159,3 @@ | ||
it('import', () => { | ||
let doc = libxml.Document(); | ||
let doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -167,3 +167,3 @@ | ||
const newdoc = libxml.Document(); | ||
const newdoc = new libxml.Document(); | ||
@@ -186,3 +186,3 @@ newdoc.node('newdoc'); | ||
it('clone', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('child'); | ||
@@ -265,3 +265,3 @@ const elem2 = elem.clone(); | ||
it('add cdata', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const element = new libxml.Element(doc, 'name', 'content'); | ||
@@ -268,0 +268,0 @@ const cdataResult = element.cdata('cdata'); |
@@ -5,3 +5,3 @@ const libxml = require('../index'); | ||
it('create', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -17,3 +17,3 @@ const ns = elem.defineNamespace('http://my-namespace.com'); | ||
it('set', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -31,3 +31,3 @@ | ||
it('with prefix', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -82,3 +82,3 @@ const ns = elem.defineNamespace('pref', 'http://my-namespace.com'); | ||
it('existing', () => { | ||
let doc = libxml.Document(); | ||
let doc = new libxml.Document(); | ||
let elem = doc.node('name1'); | ||
@@ -91,3 +91,3 @@ let ns = elem.defineNamespace('http://my-namespace.com'); | ||
doc = libxml.Document(); | ||
doc = new libxml.Document(); | ||
elem = doc.node('name1'); | ||
@@ -101,3 +101,3 @@ ns = elem.defineNamespace('pref', 'http://my-namespace.com'); | ||
it('remove', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name1'); | ||
@@ -113,3 +113,3 @@ const ns = elem.namespace('http://my-namespace.com').namespace(); | ||
it('all', () => { | ||
const document = libxml.Document(); | ||
const document = new libxml.Document(); | ||
const root = document.node('root'); | ||
@@ -134,3 +134,3 @@ const list = []; | ||
it('empty', () => { | ||
const document = libxml.Document(); | ||
const document = new libxml.Document(); | ||
const root = document.node('root'); | ||
@@ -142,3 +142,3 @@ | ||
it('nested', () => { | ||
const document = libxml.Document(); | ||
const document = new libxml.Document(); | ||
const root = document.node('root'); | ||
@@ -145,0 +145,0 @@ |
@@ -6,3 +6,3 @@ const libxml = require('../index'); | ||
// reading a node is implied during all tests | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name').attr({ to: 'wongfoo' }); | ||
@@ -14,3 +14,3 @@ | ||
it('null', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name'); | ||
@@ -22,3 +22,3 @@ | ||
it('assign_object', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name'); | ||
@@ -31,3 +31,3 @@ | ||
it('change', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('name').attr({ to: 'wongfoo' }); | ||
@@ -41,3 +41,3 @@ | ||
it('attrs', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('root'); | ||
@@ -60,3 +60,3 @@ | ||
it('siblings', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc | ||
@@ -75,3 +75,3 @@ .node('root') | ||
it('getters', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = doc.node('root').attr({ foo: 'bar' }); | ||
@@ -78,0 +78,0 @@ |
@@ -25,3 +25,3 @@ const libxml = require('../index'); | ||
it('new', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const pi = new libxml.ProcessingInstruction(doc, 'mypi', 'mycontent'); | ||
@@ -38,3 +38,3 @@ | ||
it('name', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const pi = new libxml.ProcessingInstruction(doc, 'mypi'); | ||
@@ -47,3 +47,3 @@ | ||
it('text', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const pi = new libxml.ProcessingInstruction(doc, 'mypi'); | ||
@@ -50,0 +50,0 @@ |
@@ -36,3 +36,3 @@ const libxml = require('../index'); | ||
it('gc', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -39,0 +39,0 @@ doc |
@@ -5,3 +5,3 @@ const libxml = require('../index'); | ||
it('get', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -19,3 +19,3 @@ const child = root.node('child'); | ||
it('get_missing', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -30,3 +30,3 @@ doc.node('root'); | ||
it('get_attr', () => { | ||
let doc = libxml.Document(); | ||
let doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -64,3 +64,3 @@ const child = root.node('child'); | ||
it('get_non_nodeset', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -77,3 +77,3 @@ doc.node('root'); | ||
const children = []; | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -100,3 +100,3 @@ | ||
it('get', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -116,3 +116,3 @@ const child = root.node('child'); | ||
const children = []; | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -139,3 +139,3 @@ | ||
it('get', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -161,3 +161,3 @@ const child = root.node('child'); | ||
const children = []; | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -164,0 +164,0 @@ |
@@ -5,3 +5,3 @@ const libxml = require('../index'); | ||
it('invalid_new', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -24,3 +24,3 @@ expect(() => new libxml.Text(undefined, '')).toThrow( | ||
it('new', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = new libxml.Text(doc, 'node content'); | ||
@@ -33,3 +33,3 @@ | ||
it('setters', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = new libxml.Text(doc, 'node content'); | ||
@@ -44,3 +44,3 @@ | ||
it('getters', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = new libxml.Text(doc, 'getters'); | ||
@@ -56,3 +56,3 @@ | ||
it('remove', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = new libxml.Text(doc, 'node content'); | ||
@@ -69,3 +69,3 @@ | ||
it('toString', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const elem = new libxml.Text(doc, 'node content'); | ||
@@ -78,3 +78,3 @@ | ||
it('addChild', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -98,3 +98,3 @@ const newTextNode = new libxml.Text(doc, 'my text'); | ||
it('addSiblings', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
@@ -101,0 +101,0 @@ const parentNode = new libxml.Element(doc, 'div'); |
@@ -5,3 +5,3 @@ const libxml = require('../index'); | ||
it('built', () => { | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const child = doc.node('root').node('child'); | ||
@@ -23,3 +23,3 @@ const sibling = doc.root().node('sibling'); | ||
const children = []; | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -39,3 +39,3 @@ | ||
const children = []; | ||
const doc = libxml.Document(); | ||
const doc = new libxml.Document(); | ||
const root = doc.node('root'); | ||
@@ -42,0 +42,0 @@ |
const libxml = require('../index'); | ||
describe('xml textwriter', () => { | ||
describe('error handling', () => { | ||
it('endElement should throw an error if underlying method returned -1', () => { | ||
const writer = new libxml.TextWriter(); | ||
expect(() => writer.endElement()).toThrow('Failed to end element'); | ||
}); | ||
}); | ||
it('should write an XML preamble to memory', () => { | ||
@@ -37,2 +44,64 @@ let writer; | ||
describe('standalone handling', () => { | ||
it('true === yes', () => { | ||
const writer = new libxml.TextWriter(); | ||
writer.startDocument('1.0', 'UTF-8', true); | ||
writer.endDocument(); | ||
expect(writer.outputMemory()).toBe( | ||
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n\n' | ||
); | ||
}); | ||
it('false === no', () => { | ||
const writer = new libxml.TextWriter(); | ||
writer.startDocument('1.0', 'UTF-8', false); | ||
writer.endDocument(); | ||
expect(writer.outputMemory()).toBe( | ||
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n\n' | ||
); | ||
}); | ||
it('default === no', () => { | ||
const writer = new libxml.TextWriter(); | ||
writer.startDocument('1.0', 'UTF-8', false); | ||
writer.endDocument(); | ||
expect(writer.outputMemory()).toBe( | ||
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n\n' | ||
); | ||
}); | ||
it('falsy === NULL', () => { | ||
const writer = new libxml.TextWriter(); | ||
writer.startDocument('1.0', 'UTF-8', 0); | ||
writer.endDocument(); | ||
expect(writer.outputMemory()).toBe( | ||
'<?xml version="1.0" encoding="UTF-8"?>\n\n' | ||
); | ||
}); | ||
it('missing === NULL', () => { | ||
const writer = new libxml.TextWriter(); | ||
writer.startDocument('1.0', 'UTF-8'); | ||
writer.endDocument(); | ||
expect(writer.outputMemory()).toBe( | ||
'<?xml version="1.0" encoding="UTF-8"?>\n\n' | ||
); | ||
}); | ||
it('undefined === NULL', () => { | ||
const writer = new libxml.TextWriter(); | ||
writer.startDocument('1.0', 'UTF-8', undefined); | ||
writer.endDocument(); | ||
expect(writer.outputMemory()).toBe( | ||
'<?xml version="1.0" encoding="UTF-8"?>\n\n' | ||
); | ||
}); | ||
}); | ||
it('should write elements without namespace', () => { | ||
@@ -39,0 +108,0 @@ const writer = new libxml.TextWriter(); |
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
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
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
7236870
197
2832