From 07e6be076839652f5ac8e5394df780d0ab9bc000 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Fri, 10 May 2024 09:34:07 +0200 Subject: [PATCH 1/4] wip: update dependencies and fix TS --- package.json | 6 +++--- src/XMLNode.ts | 8 ++++---- src/traversable/utils/concat.ts | 5 +---- src/traversableToJSON.ts | 6 ++---- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 620658a..5069525 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@types/jest": "^29.5.12", "cheminfo-build": "^1.2.0", "eslint": "^8.57.0", - "eslint-config-cheminfo-typescript": "^12.2.0", + "eslint-config-cheminfo-typescript": "^12.4.0", "he": "^1.2.0", "iobuffer": "^5.3.2", "jest": "^29.7.0", @@ -49,10 +49,10 @@ "prettier": "^3.2.5", "rimraf": "^5.0.5", "ts-jest": "^29.1.2", - "typescript": "^5.3.3", + "typescript": "^5.4.5", "uint8-base64": "^0.1.1" }, "dependencies": { - "dynamic-typing": "^1.0.0" + "dynamic-typing": "^1.0.1" } } diff --git a/src/XMLNode.ts b/src/XMLNode.ts index 1f5308c..adee17d 100644 --- a/src/XMLNode.ts +++ b/src/XMLNode.ts @@ -3,17 +3,17 @@ export class XMLNode { public parent?: XMLNode; public children: Record; public attributes?: Record; - public value?: string | Uint8Array; + public value?: string | Uint8Array | undefined | number; public startIndex: number; public constructor( tagName: string, 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 this.startIndex = -1; } diff --git a/src/traversable/utils/concat.ts b/src/traversable/utils/concat.ts index 4b85f27..af37b4b 100644 --- a/src/traversable/utils/concat.ts +++ b/src/traversable/utils/concat.ts @@ -1,7 +1,4 @@ -export function concat( - a?: string | ArrayLike | undefined, - b?: string | ArrayLike, -) { +export function concat(a?: string | Uint8Array, b?: string | Uint8Array) { if (a === undefined) { a = typeof b === 'string' ? '' : new Uint8Array(0); } diff --git a/src/traversableToJSON.ts b/src/traversableToJSON.ts index 20e8ac9..2ff5bd7 100644 --- a/src/traversableToJSON.ts +++ b/src/traversableToJSON.ts @@ -1,11 +1,9 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ +import { parseString } from 'dynamic-typing'; + import { XMLNode } 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'); - /** * * @param {*} node From 65adbcd768b112bd5249ec4bc7cb94f59ae318cf Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Fri, 10 May 2024 23:00:56 +0200 Subject: [PATCH 2/4] chore: add .npmignore --- src/.npmignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/.npmignore b/src/.npmignore index d1c932d..e75adf4 100644 --- a/src/.npmignore +++ b/src/.npmignore @@ -1,3 +1,2 @@ __tests__ -.npmignore -.DS_Store \ No newline at end of file +.npmignore \ No newline at end of file From ea6753ac8f8c8e42f7d2debff4a6538037e52534 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Tue, 14 May 2024 08:46:07 +0200 Subject: [PATCH 3/4] chore: fix TS --- package.json | 4 ++-- src/XMLNode.ts | 4 +++- src/traversable/utils/concat.ts | 4 +++- src/traversableToJSON.ts | 11 ++++++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 5069525..33d0bc0 100644 --- a/package.json +++ b/package.json @@ -40,14 +40,14 @@ "@types/he": "^1.2.3", "@types/jest": "^29.5.12", "cheminfo-build": "^1.2.0", - "eslint": "^8.57.0", + "eslint": "^9.2.0", "eslint-config-cheminfo-typescript": "^12.4.0", "he": "^1.2.0", "iobuffer": "^5.3.2", "jest": "^29.7.0", "pako": "^2.1.0", "prettier": "^3.2.5", - "rimraf": "^5.0.5", + "rimraf": "^5.0.7", "ts-jest": "^29.1.2", "typescript": "^5.4.5", "uint8-base64": "^0.1.1" diff --git a/src/XMLNode.ts b/src/XMLNode.ts index adee17d..1ddd5b9 100644 --- a/src/XMLNode.ts +++ b/src/XMLNode.ts @@ -1,9 +1,11 @@ +export type XMLNodeValue = string | Uint8Array | number | boolean; + export class XMLNode { public tagName: string; public parent?: XMLNode; public children: Record; public attributes?: Record; - public value?: string | Uint8Array | undefined | number; + public value?: XMLNodeValue; public startIndex: number; public constructor( tagName: string, diff --git a/src/traversable/utils/concat.ts b/src/traversable/utils/concat.ts index af37b4b..60d1d29 100644 --- a/src/traversable/utils/concat.ts +++ b/src/traversable/utils/concat.ts @@ -1,4 +1,6 @@ -export function concat(a?: string | Uint8Array, b?: string | Uint8Array) { +import { XMLNodeValue } from '../../XMLNode'; + +export function concat(a?: XMLNodeValue, b?: XMLNodeValue) { if (a === undefined) { a = typeof b === 'string' ? '' : new Uint8Array(0); } diff --git a/src/traversableToJSON.ts b/src/traversableToJSON.ts index 2ff5bd7..df61629 100644 --- a/src/traversableToJSON.ts +++ b/src/traversableToJSON.ts @@ -1,6 +1,6 @@ import { parseString } from 'dynamic-typing'; -import { XMLNode } from './XMLNode'; +import { XMLNode, XMLNodeValue } from './XMLNode'; import { ParseOptions } from './traversable/defaultOptions'; import { isTagNameInArrayMode, merge, isEmptyObject } from './util'; @@ -15,7 +15,7 @@ export function traversableToJSON( node: XMLNode, options: ParseOptions, parentTagName?: string, -): string | Uint8Array | Record { +): XMLNodeValue | Record { const { dynamicTypingNodeValue, tagValueProcessor, @@ -41,7 +41,12 @@ export function traversableToJSON( } // 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, From c3f7555d20c1733210bb47587f77b15f241bb13c Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Tue, 14 May 2024 09:28:17 +0200 Subject: [PATCH 4/4] chore: fix eslint --- package.json | 2 +- tsconfig.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 33d0bc0..0c4b32f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@types/he": "^1.2.3", "@types/jest": "^29.5.12", "cheminfo-build": "^1.2.0", - "eslint": "^9.2.0", + "eslint": "^8.57.0", "eslint-config-cheminfo-typescript": "^12.4.0", "he": "^1.2.0", "iobuffer": "^5.3.2", diff --git a/tsconfig.json b/tsconfig.json index a3c234e..18aa530 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "esModuleInterop": true, "moduleResolution": "node", "outDir": "lib", + "skipLibCheck": true, "sourceMap": true, "strict": true, "target": "es2022"