Comparing version 1.0.8 to 1.0.9
@@ -35,2 +35,3 @@ /// <reference types="node" /> | ||
encoding(value?: string): string; | ||
getParseFlags(): number; | ||
type(): string; | ||
@@ -37,0 +38,0 @@ toString(options?: XMLSaveOptions | boolean): string; |
@@ -283,2 +283,5 @@ "use strict"; | ||
}; | ||
XMLDocument.prototype.getParseFlags = function () { | ||
return this.getNativeReference().parseFlags; | ||
}; | ||
XMLDocument.prototype.type = function () { | ||
@@ -285,0 +288,0 @@ return "document"; |
/// <reference types="node" /> | ||
import { FROM_BUFFER_ASYNC_TYPE, HTMLParseOptions, XMLParseOptions } from "./types"; | ||
import { XMLDocument, HTMLDocument } from "./document"; | ||
import { HTMLParseOptions, XMLParseOptions } from "./types"; | ||
import { HTMLDocument, XMLDocument } from "./document"; | ||
export declare const parseXml: (buffer: string | Buffer, options?: XMLParseOptions) => XMLDocument; | ||
export declare const parseHtml: (buffer: string | Buffer, options?: HTMLParseOptions) => HTMLDocument; | ||
export declare const parseBufferAsync: (type: FROM_BUFFER_ASYNC_TYPE, buffer: string | Buffer, options: HTMLParseOptions | XMLParseOptions) => Promise<XMLDocument | HTMLDocument>; | ||
export declare const parseHtmlAsync: (buffer: string | Buffer, options?: HTMLParseOptions) => Promise<HTMLDocument>; | ||
export declare const parseXmlAsync: (buffer: string | Buffer, options?: XMLParseOptions) => Promise<XMLDocument>; |
@@ -39,3 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseXmlAsync = exports.parseHtmlAsync = exports.parseBufferAsync = exports.parseHtml = exports.parseXml = void 0; | ||
exports.parseXmlAsync = exports.parseHtmlAsync = exports.parseHtml = exports.parseXml = void 0; | ||
var bindings_1 = require("./bindings"); | ||
@@ -225,24 +225,21 @@ var types_1 = require("./types"); | ||
exports.parseHtml = parseHtml; | ||
var parseBufferAsync = function (type, buffer, options) { return new Promise(function (resolve, reject) { | ||
(0, functions_1.fromBufferAsync)(type, buffer, typeof buffer === "string" ? Buffer.byteLength(buffer) : buffer.length, options.url || types_1.DEFAULT_HTML_PARSE_OPTIONS.url || "", options.encoding || types_1.DEFAULT_HTML_PARSE_OPTIONS.encoding || "", flagsToInt(options.flags || types_1.DEFAULT_HTML_PARSE_OPTIONS.flags || []), function (error, document) { | ||
if (error) { | ||
reject(error); | ||
} | ||
else if (document === null) { | ||
reject(new Error(types_1.XMLDocumentError.NO_REF)); | ||
} | ||
else if (type === types_1.FROM_BUFFER_ASYNC_TYPE.HTML) { | ||
resolve((0, bindings_1.createXMLReferenceOrThrow)(document_1.HTMLDocument, document, types_1.XMLDocumentError.NO_REF)); | ||
} | ||
else { | ||
resolve((0, bindings_1.createXMLReferenceOrThrow)(document_1.XMLDocument, document, types_1.XMLDocumentError.NO_REF)); | ||
} | ||
}); | ||
}); }; | ||
exports.parseBufferAsync = parseBufferAsync; | ||
var parseHtmlAsync = function (buffer, options) { | ||
if (options === void 0) { options = types_1.DEFAULT_HTML_PARSE_OPTIONS; } | ||
return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2, (0, exports.parseBufferAsync)(types_1.FROM_BUFFER_ASYNC_TYPE.HTML, buffer, options)]; | ||
}); }); | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2, new Promise(function (resolve, reject) { | ||
(0, functions_1.fromBufferAsync)(types_1.FROM_BUFFER_ASYNC_TYPE.HTML, buffer, typeof buffer === "string" ? Buffer.byteLength(buffer) : buffer.length, options.url || types_1.DEFAULT_HTML_PARSE_OPTIONS.url || "", options.encoding || types_1.DEFAULT_HTML_PARSE_OPTIONS.encoding || "", htmlOptionsToFlags(options), function (error, document) { | ||
if (error) { | ||
reject(error); | ||
} | ||
else if (document === null) { | ||
reject(new Error(types_1.XMLDocumentError.NO_REF)); | ||
} | ||
else { | ||
resolve((0, bindings_1.createXMLReferenceOrThrow)(document_1.HTMLDocument, document, types_1.XMLDocumentError.NO_REF)); | ||
} | ||
}); | ||
})]; | ||
}); | ||
}); | ||
}; | ||
@@ -252,7 +249,21 @@ exports.parseHtmlAsync = parseHtmlAsync; | ||
if (options === void 0) { options = types_1.DEFAULT_XML_PARSE_OPTIONS; } | ||
return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2, (0, exports.parseBufferAsync)(types_1.FROM_BUFFER_ASYNC_TYPE.XML, buffer, options)]; | ||
}); }); | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2, new Promise(function (resolve, reject) { | ||
(0, functions_1.fromBufferAsync)(types_1.FROM_BUFFER_ASYNC_TYPE.XML, buffer, typeof buffer === "string" ? Buffer.byteLength(buffer) : buffer.length, options.url || types_1.DEFAULT_XML_PARSE_OPTIONS.url || "", options.encoding || types_1.DEFAULT_XML_PARSE_OPTIONS.encoding || "", xmlOptionsToFlags(options), function (error, document) { | ||
if (error) { | ||
reject(error); | ||
} | ||
else if (document === null) { | ||
reject(new Error(types_1.XMLDocumentError.NO_REF)); | ||
} | ||
else { | ||
resolve((0, bindings_1.createXMLReferenceOrThrow)(document_1.XMLDocument, document, types_1.XMLDocumentError.NO_REF)); | ||
} | ||
}); | ||
})]; | ||
}); | ||
}); | ||
}; | ||
exports.parseXmlAsync = parseXmlAsync; | ||
//# sourceMappingURL=parse.js.map |
@@ -24,2 +24,9 @@ "use strict"; | ||
}; | ||
module.exports.parse_with_flags = function (assert) { | ||
var filename = __dirname + "/../../test/fixtures/parser.xml"; | ||
var str = fs.readFileSync(filename, "utf8").replace(/[\r]+/g, ''); | ||
var doc = libxml.parseXml(str, { replaceEntities: true, validateEntities: true }); | ||
assert.equal(18, doc.getParseFlags()); | ||
assert.done(); | ||
}; | ||
module.exports.parseAsync = function (assert) { | ||
@@ -47,2 +54,12 @@ var filename = __dirname + "/../../test/fixtures/parser.xml"; | ||
}; | ||
module.exports.parse_async_with_replace = function (assert) { | ||
var filename = __dirname + "/../../test/fixtures/parser.xml"; | ||
var str = fs.readFileSync(filename, "utf8").replace(/[\r]+/g, ''); | ||
var x = 0; | ||
libxml.parseXmlAsync(str, { replaceEntities: true, validateEntities: true }).then(function (doc) { | ||
assert.equal(18, doc.getParseFlags()); | ||
assert.done(); | ||
}); | ||
assert.equal(++x, 1); | ||
}; | ||
module.exports.parse_buffer = function (assert) { | ||
@@ -49,0 +66,0 @@ var _a; |
@@ -423,2 +423,6 @@ import { XMLElement, XMLDTD, XPathNamespace, XMLNode, XMLText, XMLNodeError, XMLNamespace } from "./node"; | ||
public getParseFlags(): number { | ||
return this.getNativeReference().parseFlags; | ||
} | ||
public type(): string { | ||
@@ -425,0 +429,0 @@ return "document"; |
"use strict"; | ||
import { createXMLReference, createXMLReferenceOrThrow } from "./bindings"; | ||
import { createXMLReferenceOrThrow } from "./bindings"; | ||
import { xmlDocPtr } from "./bindings/types"; | ||
import { DEFAULT_HTML_PARSE_OPTIONS, DEFAULT_XML_PARSE_OPTIONS, FROM_BUFFER_ASYNC_TYPE, HTMLParseFlags, HTMLParseOptions, XMLDocumentError, XMLParseFlags, XMLParseOptions, XMLStructuredError } from "./types"; | ||
import { | ||
xmlReadMemory, | ||
DEFAULT_HTML_PARSE_OPTIONS, | ||
DEFAULT_XML_PARSE_OPTIONS, | ||
FROM_BUFFER_ASYNC_TYPE, | ||
HTMLParseFlags, | ||
HTMLParseOptions, | ||
XMLDocumentError, | ||
XMLParseFlags, | ||
XMLParseOptions, | ||
XMLStructuredError, | ||
} from "./types"; | ||
import { | ||
fromBufferAsync, | ||
htmlReadMemory, | ||
fromBufferAsync, | ||
withStructuredErrors, | ||
withGenericErrors, | ||
xmlDocHasRootElement, | ||
xmlGetLastError, | ||
xmlDocGetRootElement, | ||
xmlDocHasRootElement, | ||
xmlReadMemory, | ||
} from "./bindings/functions"; | ||
import { XMLDocument, HTMLDocument } from "./document"; | ||
import { HTMLDocument, XMLDocument } from "./document"; | ||
import { XMLNodeError } from "./node"; | ||
const htmlOptionsToFlags = (options: HTMLParseOptions) => { | ||
const htmlOptionsToFlags = (options: HTMLParseOptions): number => { | ||
const flags: HTMLParseFlags[] = []; | ||
@@ -87,3 +95,3 @@ | ||
const xmlOptionsToFlags = (options: XMLParseOptions) => { | ||
const xmlOptionsToFlags = (options: XMLParseOptions): number => { | ||
let flags: XMLParseFlags[] = []; | ||
@@ -281,9 +289,8 @@ | ||
export const parseBufferAsync = ( | ||
type: FROM_BUFFER_ASYNC_TYPE, | ||
export const parseHtmlAsync = async ( | ||
buffer: string | Buffer, | ||
options: HTMLParseOptions | XMLParseOptions, | ||
) => new Promise<XMLDocument|HTMLDocument>((resolve, reject) => { | ||
options: HTMLParseOptions = DEFAULT_HTML_PARSE_OPTIONS | ||
): Promise<HTMLDocument> => new Promise<HTMLDocument>((resolve, reject) => { | ||
fromBufferAsync( | ||
type, | ||
FROM_BUFFER_ASYNC_TYPE.HTML, | ||
buffer, | ||
@@ -293,3 +300,3 @@ typeof buffer === "string" ? Buffer.byteLength(buffer) : buffer.length, | ||
options.encoding || DEFAULT_HTML_PARSE_OPTIONS.encoding || "", | ||
flagsToInt(options.flags || DEFAULT_HTML_PARSE_OPTIONS.flags || []), | ||
htmlOptionsToFlags(options), | ||
(error: Error | null, document: xmlDocPtr | null) => { | ||
@@ -300,6 +307,4 @@ if (error) { | ||
reject(new Error(XMLDocumentError.NO_REF)); | ||
} else if (type === FROM_BUFFER_ASYNC_TYPE.HTML) { | ||
} else { | ||
resolve(createXMLReferenceOrThrow(HTMLDocument, document, XMLDocumentError.NO_REF)); | ||
} else { | ||
resolve(createXMLReferenceOrThrow(XMLDocument, document, XMLDocumentError.NO_REF)); | ||
} | ||
@@ -310,10 +315,23 @@ } | ||
export const parseHtmlAsync = async ( | ||
buffer: string | Buffer, | ||
options: HTMLParseOptions = DEFAULT_HTML_PARSE_OPTIONS | ||
): Promise<HTMLDocument> => parseBufferAsync(FROM_BUFFER_ASYNC_TYPE.HTML, buffer, options); | ||
export const parseXmlAsync = async ( | ||
buffer: string | Buffer, | ||
options: XMLParseOptions = DEFAULT_XML_PARSE_OPTIONS | ||
): Promise<XMLDocument> => parseBufferAsync(FROM_BUFFER_ASYNC_TYPE.XML, buffer, options); | ||
): Promise<XMLDocument> => new Promise<HTMLDocument>((resolve, reject) => { | ||
fromBufferAsync( | ||
FROM_BUFFER_ASYNC_TYPE.XML, | ||
buffer, | ||
typeof buffer === "string" ? Buffer.byteLength(buffer) : buffer.length, | ||
options.url || DEFAULT_XML_PARSE_OPTIONS.url || "", | ||
options.encoding || DEFAULT_XML_PARSE_OPTIONS.encoding || "", | ||
xmlOptionsToFlags(options), | ||
(error: Error | null, document: xmlDocPtr | null) => { | ||
if (error) { | ||
reject(error); | ||
} else if (document === null) { | ||
reject(new Error(XMLDocumentError.NO_REF)); | ||
} else { | ||
resolve(createXMLReferenceOrThrow(XMLDocument, document, XMLDocumentError.NO_REF)); | ||
} | ||
} | ||
); | ||
}); |
@@ -11,3 +11,3 @@ { | ||
"description": "libxml bindings for v8 javascript engine", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"repository": { | ||
@@ -14,0 +14,0 @@ "type": "git", |
@@ -24,2 +24,11 @@ import * as fs from "fs"; | ||
module.exports.parse_with_flags = function (assert: any) { | ||
const filename = __dirname + "/../../test/fixtures/parser.xml"; | ||
const str = fs.readFileSync(filename, "utf8").replace(/[\r]+/g, ''); | ||
const doc = libxml.parseXml(str, {replaceEntities: true, validateEntities: true}); | ||
assert.equal(18, doc.getParseFlags()); | ||
assert.done(); | ||
} | ||
module.exports.parseAsync = function (assert: any) { | ||
@@ -50,2 +59,15 @@ var filename = __dirname + "/../../test/fixtures/parser.xml"; | ||
module.exports.parse_async_with_replace = function (assert: any) { | ||
const filename = __dirname + "/../../test/fixtures/parser.xml"; | ||
const str = fs.readFileSync(filename, "utf8").replace(/[\r]+/g, ''); | ||
let x = 0; | ||
libxml.parseXmlAsync(str, {replaceEntities: true, validateEntities: true}).then((doc) => { | ||
assert.equal(18, doc.getParseFlags()); | ||
assert.done(); | ||
}); | ||
assert.equal(++x, 1); | ||
} | ||
module.exports.parse_buffer = function (assert: any) { | ||
@@ -52,0 +74,0 @@ var filename = __dirname + "/../../test/fixtures/parser-utf16.xml"; |
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
17660656
33946