arraybuffer-xml-parser
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -11,20 +11,18 @@ export function arrayIndexOf(array, referenceArray, index = 0) { | ||
} | ||
else { | ||
if (found > 0) { | ||
let j = 0; | ||
for (; j <= found && array[foundIndex + j] === array[foundIndex + found]; j++) | ||
; | ||
if (j < found + 1) { | ||
foundIndex = -1; | ||
found = 0; | ||
} | ||
else { | ||
foundIndex++; | ||
} | ||
else if (found > 0) { | ||
let j = 0; | ||
for (; j <= found && array[foundIndex + j] === array[foundIndex + found]; j++) | ||
; | ||
if (j < found + 1) { | ||
foundIndex = -1; | ||
found = 0; | ||
} | ||
else { | ||
found = 0; | ||
foundIndex = -1; | ||
foundIndex++; | ||
} | ||
} | ||
else { | ||
found = 0; | ||
foundIndex = -1; | ||
} | ||
} | ||
@@ -31,0 +29,0 @@ if (found !== referenceArray.length) { |
@@ -5,3 +5,3 @@ import { ParseOptions } from './traversable/defaultOptions'; | ||
*/ | ||
export declare function parse(xmlData: string | Uint8Array | ArrayBufferLike, options?: ParseOptions): string | Uint8Array | Record<string, string | Uint8Array>; | ||
export declare function parse(xmlData: string | Uint8Array | ArrayBufferLike, options?: ParseOptions): import("./XMLNode").XMLNodeValue | Record<string, import("./XMLNode").XMLNodeValue>; | ||
//# sourceMappingURL=parse.d.ts.map |
@@ -5,3 +5,3 @@ import { StreamParseOptions } from './traversable/defaultOptions'; | ||
*/ | ||
export declare function parseStream(readableStream: ReadableStream, lookupTagName: string, options?: StreamParseOptions): AsyncGenerator<string | Uint8Array | Record<string, string | Uint8Array>, void, unknown>; | ||
export declare function parseStream(readableStream: ReadableStream, lookupTagName: string, options?: StreamParseOptions): AsyncGenerator<import("./XMLNode").XMLNodeValue | Record<string, import("./XMLNode").XMLNodeValue>, void, unknown>; | ||
//# sourceMappingURL=parseStream.d.ts.map |
@@ -117,3 +117,3 @@ import { XMLNode } from '../XMLNode'; | ||
const parsedOpeningTag = closingIndexForOpeningTag(xmlData, i + 1); | ||
let tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const closeIndex = parsedOpeningTag.index; | ||
@@ -120,0 +120,0 @@ const separatorIndex = tagData.indexOf(' '); |
@@ -31,2 +31,3 @@ import { XMLNode } from '../XMLNode'; | ||
while (currentLength < maxBufferSize && !endStream) { | ||
// eslint-disable-next-line no-await-in-loop | ||
chunk = await reader.read(); | ||
@@ -44,3 +45,3 @@ endStream = chunk.done; | ||
currentShift += xmlData.length; | ||
for (let chunk of newChunks) { | ||
for (const chunk of newChunks) { | ||
newXmlData.set(chunk, currentShift); | ||
@@ -148,6 +149,4 @@ currentShift += chunk.length; | ||
} | ||
else { | ||
if (currentNode) { | ||
currentNode.value = concat(currentNode.value, tagExp); | ||
} | ||
else if (currentNode) { | ||
currentNode.value = concat(currentNode.value, tagExp); | ||
} | ||
@@ -161,3 +160,3 @@ i = closeIndex + 2; | ||
const parsedOpeningTag = closingIndexForOpeningTag(xmlData, i + 1); | ||
let tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const closeIndex = parsedOpeningTag.index; | ||
@@ -207,2 +206,3 @@ const separatorIndex = tagData.indexOf(' '); | ||
//opening tag | ||
// eslint-disable-next-line no-lonely-if | ||
if (currentNode || tagName === lookupTagName) { | ||
@@ -209,0 +209,0 @@ const childNode = new XMLNode(tagName, currentNode); |
@@ -14,3 +14,3 @@ import { getAllMatches, isEmptyObject } from '../util'; | ||
const attributes = {}; | ||
for (let match of matches) { | ||
for (const match of matches) { | ||
const attrName = resolveNameSpace(match[1], options); | ||
@@ -17,0 +17,0 @@ if (attrName.length) { |
@@ -1,2 +0,3 @@ | ||
export declare function concat(a?: string | ArrayLike<number> | undefined, b?: string | ArrayLike<number>): string | Uint8Array; | ||
import { XMLNodeValue } from '../../XMLNode'; | ||
export declare function concat(a?: XMLNodeValue, b?: XMLNodeValue): string | Uint8Array; | ||
//# sourceMappingURL=concat.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { XMLNode } from './XMLNode'; | ||
import { XMLNode, XMLNodeValue } from './XMLNode'; | ||
import { ParseOptions } from './traversable/defaultOptions'; | ||
@@ -10,3 +10,3 @@ /** | ||
*/ | ||
export declare function traversableToJSON(node: XMLNode, options: ParseOptions, parentTagName?: string): string | Uint8Array | Record<string, string | Uint8Array>; | ||
export declare function traversableToJSON(node: XMLNode, options: ParseOptions, parentTagName?: string): XMLNodeValue | Record<string, XMLNodeValue>; | ||
//# sourceMappingURL=traversableToJSON.d.ts.map |
@@ -0,4 +1,3 @@ | ||
import { parseString } from 'dynamic-typing'; | ||
import { isTagNameInArrayMode, merge, isEmptyObject } from './util'; | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { parseString } = require('dynamic-typing'); | ||
/** | ||
@@ -27,3 +26,6 @@ * | ||
// otherwise create a textnode if node has some text | ||
if (node.value !== undefined && node.value.length !== 0) { | ||
if (node.value !== undefined && | ||
(typeof node.value === 'number' || | ||
typeof node.value === 'boolean' || | ||
node.value.length !== 0)) { | ||
const asArray = isTagNameInArrayMode(node.tagName, arrayMode, parentTagName); | ||
@@ -39,3 +41,3 @@ result[options.textNodeName] = asArray | ||
const renamedAttributes = {}; | ||
for (let attributeName in node.attributes) { | ||
for (const attributeName in node.attributes) { | ||
const newAttributeName = attributeNameProcessor | ||
@@ -50,3 +52,3 @@ ? attributeNameProcessor(attributeName) | ||
if (options.attributesNodeName) { | ||
let encapsulatedAttributes = {}; | ||
const encapsulatedAttributes = {}; | ||
encapsulatedAttributes[options.attributesNodeName] = attributes; | ||
@@ -62,4 +64,4 @@ attributes = encapsulatedAttributes; | ||
// eslint-disable-next-line @typescript-eslint/no-for-in-array | ||
for (let tag in node.children[tagName]) { | ||
if (Object.prototype.hasOwnProperty.call(node.children[tagName], tag)) { | ||
for (const tag in node.children[tagName]) { | ||
if (Object.hasOwn(node.children[tagName], tag)) { | ||
result[newTagName].push(traversableToJSON(node.children[tagName][tag], options, tagName)); | ||
@@ -66,0 +68,0 @@ } |
import { XMLNode } from './XMLNode'; | ||
export declare function getAllMatches(string: string, regex: RegExp): RegExpMatchArray[]; | ||
export declare function getAllMatches(string: string, regex: RegExp): RegExpExecArray[]; | ||
export declare function isName(string: string): boolean; | ||
@@ -10,3 +10,3 @@ export declare function isEmptyObject(obj: Record<string, boolean | XMLNode | XMLNode[]>): boolean; | ||
*/ | ||
export declare function merge(target: Record<string, boolean | XMLNode | (XMLNode | boolean)[]>, source: Record<string, boolean | XMLNode>, arrayMode: ((tagName: string, parentTagName: string) => boolean) | string | boolean | RegExp): void; | ||
export declare function merge(target: Record<string, boolean | XMLNode | Array<XMLNode | boolean>>, source: Record<string, boolean | XMLNode>, arrayMode: ((tagName: string, parentTagName: string) => boolean) | string | boolean | RegExp): void; | ||
/** | ||
@@ -13,0 +13,0 @@ * Check if a tag name should be treated as array |
@@ -0,1 +1,2 @@ | ||
export type XMLNodeValue = string | Uint8Array | number | boolean; | ||
export declare class XMLNode { | ||
@@ -6,7 +7,7 @@ tagName: string; | ||
attributes?: Record<string, XMLNode | boolean>; | ||
value?: string | Uint8Array; | ||
value?: XMLNodeValue; | ||
startIndex: number; | ||
constructor(tagName: string, parent?: XMLNode, value?: Uint8Array | string); | ||
constructor(tagName: string, parent?: XMLNode, value?: Uint8Array | string | undefined | number); | ||
addChild(child: XMLNode): void; | ||
} | ||
//# sourceMappingURL=XMLNode.d.ts.map |
export class XMLNode { | ||
tagName; | ||
parent; | ||
children; | ||
attributes; | ||
value; | ||
startIndex; | ||
constructor(tagName, parent, value) { | ||
this.tagName = tagName; | ||
this.parent = parent; | ||
this.children = Object.create({}); //child tags | ||
this.attributes = Object.create({}); //attributes map | ||
this.children = Object.create(null); //child tags | ||
this.attributes = Object.create(null); //attributes map | ||
this.value = value; //text only | ||
@@ -8,0 +14,0 @@ this.startIndex = -1; |
@@ -14,20 +14,18 @@ "use strict"; | ||
} | ||
else { | ||
if (found > 0) { | ||
let j = 0; | ||
for (; j <= found && array[foundIndex + j] === array[foundIndex + found]; j++) | ||
; | ||
if (j < found + 1) { | ||
foundIndex = -1; | ||
found = 0; | ||
} | ||
else { | ||
foundIndex++; | ||
} | ||
else if (found > 0) { | ||
let j = 0; | ||
for (; j <= found && array[foundIndex + j] === array[foundIndex + found]; j++) | ||
; | ||
if (j < found + 1) { | ||
foundIndex = -1; | ||
found = 0; | ||
} | ||
else { | ||
found = 0; | ||
foundIndex = -1; | ||
foundIndex++; | ||
} | ||
} | ||
else { | ||
found = 0; | ||
foundIndex = -1; | ||
} | ||
} | ||
@@ -34,0 +32,0 @@ if (found !== referenceArray.length) { |
@@ -5,3 +5,3 @@ import { ParseOptions } from './traversable/defaultOptions'; | ||
*/ | ||
export declare function parse(xmlData: string | Uint8Array | ArrayBufferLike, options?: ParseOptions): string | Uint8Array | Record<string, string | Uint8Array>; | ||
export declare function parse(xmlData: string | Uint8Array | ArrayBufferLike, options?: ParseOptions): import("./XMLNode").XMLNodeValue | Record<string, import("./XMLNode").XMLNodeValue>; | ||
//# sourceMappingURL=parse.d.ts.map |
@@ -5,3 +5,3 @@ import { StreamParseOptions } from './traversable/defaultOptions'; | ||
*/ | ||
export declare function parseStream(readableStream: ReadableStream, lookupTagName: string, options?: StreamParseOptions): AsyncGenerator<string | Uint8Array | Record<string, string | Uint8Array>, void, unknown>; | ||
export declare function parseStream(readableStream: ReadableStream, lookupTagName: string, options?: StreamParseOptions): AsyncGenerator<import("./XMLNode").XMLNodeValue | Record<string, import("./XMLNode").XMLNodeValue>, void, unknown>; | ||
//# sourceMappingURL=parseStream.d.ts.map |
@@ -120,3 +120,3 @@ "use strict"; | ||
const parsedOpeningTag = (0, closingIndexForOpeningTag_1.closingIndexForOpeningTag)(xmlData, i + 1); | ||
let tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const closeIndex = parsedOpeningTag.index; | ||
@@ -123,0 +123,0 @@ const separatorIndex = tagData.indexOf(' '); |
@@ -34,2 +34,3 @@ "use strict"; | ||
while (currentLength < maxBufferSize && !endStream) { | ||
// eslint-disable-next-line no-await-in-loop | ||
chunk = await reader.read(); | ||
@@ -47,3 +48,3 @@ endStream = chunk.done; | ||
currentShift += xmlData.length; | ||
for (let chunk of newChunks) { | ||
for (const chunk of newChunks) { | ||
newXmlData.set(chunk, currentShift); | ||
@@ -151,6 +152,4 @@ currentShift += chunk.length; | ||
} | ||
else { | ||
if (currentNode) { | ||
currentNode.value = (0, concat_1.concat)(currentNode.value, tagExp); | ||
} | ||
else if (currentNode) { | ||
currentNode.value = (0, concat_1.concat)(currentNode.value, tagExp); | ||
} | ||
@@ -164,3 +163,3 @@ i = closeIndex + 2; | ||
const parsedOpeningTag = (0, closingIndexForOpeningTag_1.closingIndexForOpeningTag)(xmlData, i + 1); | ||
let tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const closeIndex = parsedOpeningTag.index; | ||
@@ -210,2 +209,3 @@ const separatorIndex = tagData.indexOf(' '); | ||
//opening tag | ||
// eslint-disable-next-line no-lonely-if | ||
if (currentNode || tagName === lookupTagName) { | ||
@@ -212,0 +212,0 @@ const childNode = new XMLNode_1.XMLNode(tagName, currentNode); |
@@ -17,3 +17,3 @@ "use strict"; | ||
const attributes = {}; | ||
for (let match of matches) { | ||
for (const match of matches) { | ||
const attrName = resolveNameSpace(match[1], options); | ||
@@ -20,0 +20,0 @@ if (attrName.length) { |
@@ -1,2 +0,3 @@ | ||
export declare function concat(a?: string | ArrayLike<number> | undefined, b?: string | ArrayLike<number>): string | Uint8Array; | ||
import { XMLNodeValue } from '../../XMLNode'; | ||
export declare function concat(a?: XMLNodeValue, b?: XMLNodeValue): string | Uint8Array; | ||
//# sourceMappingURL=concat.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { XMLNode } from './XMLNode'; | ||
import { XMLNode, XMLNodeValue } from './XMLNode'; | ||
import { ParseOptions } from './traversable/defaultOptions'; | ||
@@ -10,3 +10,3 @@ /** | ||
*/ | ||
export declare function traversableToJSON(node: XMLNode, options: ParseOptions, parentTagName?: string): string | Uint8Array | Record<string, string | Uint8Array>; | ||
export declare function traversableToJSON(node: XMLNode, options: ParseOptions, parentTagName?: string): XMLNodeValue | Record<string, XMLNodeValue>; | ||
//# sourceMappingURL=traversableToJSON.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.traversableToJSON = void 0; | ||
const dynamic_typing_1 = require("dynamic-typing"); | ||
const util_1 = require("./util"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { parseString } = require('dynamic-typing'); | ||
/** | ||
@@ -22,3 +21,3 @@ * | ||
if (typeof node.value === 'string' && dynamicTypingNodeValue) { | ||
node.value = parseString(node.value); | ||
node.value = (0, dynamic_typing_1.parseString)(node.value); | ||
} | ||
@@ -31,3 +30,6 @@ // when no child node or attr is present | ||
// otherwise create a textnode if node has some text | ||
if (node.value !== undefined && node.value.length !== 0) { | ||
if (node.value !== undefined && | ||
(typeof node.value === 'number' || | ||
typeof node.value === 'boolean' || | ||
node.value.length !== 0)) { | ||
const asArray = (0, util_1.isTagNameInArrayMode)(node.tagName, arrayMode, parentTagName); | ||
@@ -43,3 +45,3 @@ result[options.textNodeName] = asArray | ||
const renamedAttributes = {}; | ||
for (let attributeName in node.attributes) { | ||
for (const attributeName in node.attributes) { | ||
const newAttributeName = attributeNameProcessor | ||
@@ -54,3 +56,3 @@ ? attributeNameProcessor(attributeName) | ||
if (options.attributesNodeName) { | ||
let encapsulatedAttributes = {}; | ||
const encapsulatedAttributes = {}; | ||
encapsulatedAttributes[options.attributesNodeName] = attributes; | ||
@@ -66,4 +68,4 @@ attributes = encapsulatedAttributes; | ||
// eslint-disable-next-line @typescript-eslint/no-for-in-array | ||
for (let tag in node.children[tagName]) { | ||
if (Object.prototype.hasOwnProperty.call(node.children[tagName], tag)) { | ||
for (const tag in node.children[tagName]) { | ||
if (Object.hasOwn(node.children[tagName], tag)) { | ||
result[newTagName].push(traversableToJSON(node.children[tagName][tag], options, tagName)); | ||
@@ -70,0 +72,0 @@ } |
import { XMLNode } from './XMLNode'; | ||
export declare function getAllMatches(string: string, regex: RegExp): RegExpMatchArray[]; | ||
export declare function getAllMatches(string: string, regex: RegExp): RegExpExecArray[]; | ||
export declare function isName(string: string): boolean; | ||
@@ -10,3 +10,3 @@ export declare function isEmptyObject(obj: Record<string, boolean | XMLNode | XMLNode[]>): boolean; | ||
*/ | ||
export declare function merge(target: Record<string, boolean | XMLNode | (XMLNode | boolean)[]>, source: Record<string, boolean | XMLNode>, arrayMode: ((tagName: string, parentTagName: string) => boolean) | string | boolean | RegExp): void; | ||
export declare function merge(target: Record<string, boolean | XMLNode | Array<XMLNode | boolean>>, source: Record<string, boolean | XMLNode>, arrayMode: ((tagName: string, parentTagName: string) => boolean) | string | boolean | RegExp): void; | ||
/** | ||
@@ -13,0 +13,0 @@ * Check if a tag name should be treated as array |
@@ -0,1 +1,2 @@ | ||
export type XMLNodeValue = string | Uint8Array | number | boolean; | ||
export declare class XMLNode { | ||
@@ -6,7 +7,7 @@ tagName: string; | ||
attributes?: Record<string, XMLNode | boolean>; | ||
value?: string | Uint8Array; | ||
value?: XMLNodeValue; | ||
startIndex: number; | ||
constructor(tagName: string, parent?: XMLNode, value?: Uint8Array | string); | ||
constructor(tagName: string, parent?: XMLNode, value?: Uint8Array | string | undefined | number); | ||
addChild(child: XMLNode): void; | ||
} | ||
//# sourceMappingURL=XMLNode.d.ts.map |
@@ -5,7 +5,13 @@ "use strict"; | ||
class XMLNode { | ||
tagName; | ||
parent; | ||
children; | ||
attributes; | ||
value; | ||
startIndex; | ||
constructor(tagName, parent, value) { | ||
this.tagName = tagName; | ||
this.parent = parent; | ||
this.children = Object.create({}); //child tags | ||
this.attributes = Object.create({}); //attributes map | ||
this.children = Object.create(null); //child tags | ||
this.attributes = Object.create(null); //attributes map | ||
this.value = value; //text only | ||
@@ -12,0 +18,0 @@ this.startIndex = -1; |
{ | ||
"name": "arraybuffer-xml-parser", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Parse XML files contained in an array buffer", | ||
@@ -22,5 +22,4 @@ "main": "./lib/index.js", | ||
"prettier-write": "prettier --write src", | ||
"test": "npm run test-coverage && npm run eslint && npm run prettier && npm run check-types", | ||
"test-coverage": "jest --coverage", | ||
"test-only": "jest", | ||
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types", | ||
"test-only": "jest --coverage", | ||
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm", | ||
@@ -42,20 +41,20 @@ "tsc-cjs": "tsc --project tsconfig.cjs.json", | ||
"devDependencies": { | ||
"@types/he": "^1.1.2", | ||
"@types/jest": "^27.5.1", | ||
"cheminfo-build": "^1.1.11", | ||
"eslint": "^8.16.0", | ||
"eslint-config-cheminfo-typescript": "^10.4.0", | ||
"@types/he": "^1.2.3", | ||
"@types/jest": "^29.5.12", | ||
"cheminfo-build": "^1.2.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-cheminfo-typescript": "^12.4.0", | ||
"he": "^1.2.0", | ||
"iobuffer": "^5.1.0", | ||
"jest": "^28.1.0", | ||
"pako": "^2.0.4", | ||
"prettier": "^2.6.2", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^28.0.3", | ||
"typescript": "^4.7.2", | ||
"iobuffer": "^5.3.2", | ||
"jest": "^29.7.0", | ||
"pako": "^2.1.0", | ||
"prettier": "^3.2.5", | ||
"rimraf": "^5.0.7", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "^5.4.5", | ||
"uint8-base64": "^0.1.1" | ||
}, | ||
"dependencies": { | ||
"dynamic-typing": "^0.1.3" | ||
"dynamic-typing": "^1.0.1" | ||
} | ||
} |
@@ -14,20 +14,18 @@ export function arrayIndexOf( | ||
found++; | ||
} else { | ||
if (found > 0) { | ||
let j = 0; | ||
for ( | ||
; | ||
j <= found && array[foundIndex + j] === array[foundIndex + found]; | ||
j++ | ||
); | ||
if (j < found + 1) { | ||
foundIndex = -1; | ||
found = 0; | ||
} else { | ||
foundIndex++; | ||
} | ||
} else if (found > 0) { | ||
let j = 0; | ||
for ( | ||
; | ||
j <= found && array[foundIndex + j] === array[foundIndex + found]; | ||
j++ | ||
); | ||
if (j < found + 1) { | ||
foundIndex = -1; | ||
found = 0; | ||
} else { | ||
found = 0; | ||
foundIndex = -1; | ||
foundIndex++; | ||
} | ||
} else { | ||
found = 0; | ||
foundIndex = -1; | ||
} | ||
@@ -34,0 +32,0 @@ } |
@@ -146,3 +146,3 @@ import { XMLNode } from '../XMLNode'; | ||
const parsedOpeningTag = closingIndexForOpeningTag(xmlData, i + 1); | ||
let tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const closeIndex = parsedOpeningTag.index; | ||
@@ -149,0 +149,0 @@ const separatorIndex = tagData.indexOf(' '); |
@@ -40,2 +40,3 @@ import { XMLNode } from '../XMLNode'; | ||
while (currentLength < maxBufferSize && !endStream) { | ||
// eslint-disable-next-line no-await-in-loop | ||
chunk = await reader.read(); | ||
@@ -54,3 +55,3 @@ endStream = chunk.done; | ||
currentShift += xmlData.length; | ||
for (let chunk of newChunks) { | ||
for (const chunk of newChunks) { | ||
newXmlData.set(chunk, currentShift); | ||
@@ -183,6 +184,4 @@ currentShift += chunk.length; | ||
} | ||
} else { | ||
if (currentNode) { | ||
currentNode.value = concat(currentNode.value, tagExp); | ||
} | ||
} else if (currentNode) { | ||
currentNode.value = concat(currentNode.value, tagExp); | ||
} | ||
@@ -196,3 +195,3 @@ | ||
const parsedOpeningTag = closingIndexForOpeningTag(xmlData, i + 1); | ||
let tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const tagData = parsedOpeningTag.data.replace(/\r?\n|\t/g, ' '); | ||
const closeIndex = parsedOpeningTag.index; | ||
@@ -252,2 +251,3 @@ const separatorIndex = tagData.indexOf(' '); | ||
// eslint-disable-next-line no-lonely-if | ||
if (currentNode || tagName === lookupTagName) { | ||
@@ -254,0 +254,0 @@ const childNode = new XMLNode(tagName, currentNode); |
@@ -21,3 +21,3 @@ import { XMLNode } from '../XMLNode'; | ||
const attributes: Record<string, XMLNode | boolean> = {}; | ||
for (let match of matches) { | ||
for (const match of matches) { | ||
const attrName = resolveNameSpace(match[1], options); | ||
@@ -24,0 +24,0 @@ if (attrName.length) { |
@@ -1,5 +0,4 @@ | ||
export function concat( | ||
a?: string | ArrayLike<number> | undefined, | ||
b?: string | ArrayLike<number>, | ||
) { | ||
import { XMLNodeValue } from '../../XMLNode'; | ||
export function concat(a?: XMLNodeValue, b?: XMLNodeValue) { | ||
if (a === undefined) { | ||
@@ -6,0 +5,0 @@ a = typeof b === 'string' ? '' : new Uint8Array(0); |
@@ -1,9 +0,7 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { XMLNode } from './XMLNode'; | ||
import { parseString } from 'dynamic-typing'; | ||
import { XMLNode, XMLNodeValue } from './XMLNode'; | ||
import { ParseOptions } from './traversable/defaultOptions'; | ||
import { isTagNameInArrayMode, merge, isEmptyObject } from './util'; | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { parseString } = require('dynamic-typing'); | ||
/** | ||
@@ -20,3 +18,3 @@ * | ||
parentTagName?: string, | ||
): string | Uint8Array | Record<string, string | Uint8Array> { | ||
): XMLNodeValue | Record<string, XMLNodeValue> { | ||
const { | ||
@@ -47,3 +45,8 @@ dynamicTypingNodeValue, | ||
// otherwise create a textnode if node has some text | ||
if (node.value !== undefined && node.value.length !== 0) { | ||
if ( | ||
node.value !== undefined && | ||
(typeof node.value === 'number' || | ||
typeof node.value === 'boolean' || | ||
node.value.length !== 0) | ||
) { | ||
const asArray = isTagNameInArrayMode( | ||
@@ -65,3 +68,3 @@ node.tagName, | ||
const renamedAttributes: Record<string, boolean | XMLNode> = {}; | ||
for (let attributeName in node.attributes) { | ||
for (const attributeName in node.attributes) { | ||
const newAttributeName = attributeNameProcessor | ||
@@ -76,3 +79,3 @@ ? attributeNameProcessor(attributeName) | ||
if (options.attributesNodeName) { | ||
let encapsulatedAttributes: Record<string, any> = {}; | ||
const encapsulatedAttributes: Record<string, any> = {}; | ||
encapsulatedAttributes[options.attributesNodeName] = attributes; | ||
@@ -89,4 +92,4 @@ attributes = encapsulatedAttributes; | ||
// eslint-disable-next-line @typescript-eslint/no-for-in-array | ||
for (let tag in node.children[tagName]) { | ||
if (Object.prototype.hasOwnProperty.call(node.children[tagName], tag)) { | ||
for (const tag in node.children[tagName]) { | ||
if (Object.hasOwn(node.children[tagName], tag)) { | ||
result[newTagName].push( | ||
@@ -93,0 +96,0 @@ traversableToJSON(node.children[tagName][tag], options, tagName), |
@@ -35,3 +35,3 @@ import { XMLNode } from './XMLNode'; | ||
export function merge( | ||
target: Record<string, boolean | XMLNode | (XMLNode | boolean)[]>, | ||
target: Record<string, boolean | XMLNode | Array<XMLNode | boolean>>, | ||
source: Record<string, boolean | XMLNode>, | ||
@@ -38,0 +38,0 @@ arrayMode: |
@@ -0,1 +1,3 @@ | ||
export type XMLNodeValue = string | Uint8Array | number | boolean; | ||
export class XMLNode { | ||
@@ -6,3 +8,3 @@ public tagName: string; | ||
public attributes?: Record<string, XMLNode | boolean>; | ||
public value?: string | Uint8Array; | ||
public value?: XMLNodeValue; | ||
public startIndex: number; | ||
@@ -12,8 +14,8 @@ public constructor( | ||
parent?: XMLNode, | ||
value?: Uint8Array | string, | ||
value?: Uint8Array | string | undefined | number, | ||
) { | ||
this.tagName = tagName; | ||
this.parent = parent; | ||
this.children = Object.create({}); //child tags | ||
this.attributes = Object.create({}); //attributes map | ||
this.children = Object.create(null); //child tags | ||
this.attributes = Object.create(null); //attributes map | ||
this.value = value; //text only | ||
@@ -20,0 +22,0 @@ this.startIndex = -1; |
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
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
210047
3157
+ Addeddynamic-typing@1.0.1(transitive)
- Removeddynamic-typing@0.1.3(transitive)
Updateddynamic-typing@^1.0.1