Skip to content

Commit a6c39ae

Browse files
authored
fix: update dependencies and fix TS (#20)
* wip: update dependencies and fix TS * chore: add .npmignore * chore: fix TS * chore: fix eslint
1 parent 5542e8a commit a6c39ae

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@
4141
"@types/jest": "^29.5.12",
4242
"cheminfo-build": "^1.2.0",
4343
"eslint": "^8.57.0",
44-
"eslint-config-cheminfo-typescript": "^12.2.0",
44+
"eslint-config-cheminfo-typescript": "^12.4.0",
4545
"he": "^1.2.0",
4646
"iobuffer": "^5.3.2",
4747
"jest": "^29.7.0",
4848
"pako": "^2.1.0",
4949
"prettier": "^3.2.5",
50-
"rimraf": "^5.0.5",
50+
"rimraf": "^5.0.7",
5151
"ts-jest": "^29.1.2",
52-
"typescript": "^5.3.3",
52+
"typescript": "^5.4.5",
5353
"uint8-base64": "^0.1.1"
5454
},
5555
"dependencies": {
56-
"dynamic-typing": "^1.0.0"
56+
"dynamic-typing": "^1.0.1"
5757
}
5858
}

src/.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
__tests__
2-
.npmignore
3-
.DS_Store
2+
.npmignore

src/XMLNode.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
export type XMLNodeValue = string | Uint8Array | number | boolean;
2+
13
export class XMLNode {
24
public tagName: string;
35
public parent?: XMLNode;
46
public children: Record<string, XMLNode[]>;
57
public attributes?: Record<string, XMLNode | boolean>;
6-
public value?: string | Uint8Array;
8+
public value?: XMLNodeValue;
79
public startIndex: number;
810
public constructor(
911
tagName: string,
1012
parent?: XMLNode,
11-
value?: Uint8Array | string,
13+
value?: Uint8Array | string | undefined | number,
1214
) {
1315
this.tagName = tagName;
1416
this.parent = parent;
15-
this.children = Object.create({}); //child tags
16-
this.attributes = Object.create({}); //attributes map
17+
this.children = Object.create(null); //child tags
18+
this.attributes = Object.create(null); //attributes map
1719
this.value = value; //text only
1820
this.startIndex = -1;
1921
}

src/traversable/utils/concat.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
export function concat(
2-
a?: string | ArrayLike<number> | undefined,
3-
b?: string | ArrayLike<number>,
4-
) {
1+
import { XMLNodeValue } from '../../XMLNode';
2+
3+
export function concat(a?: XMLNodeValue, b?: XMLNodeValue) {
54
if (a === undefined) {
65
a = typeof b === 'string' ? '' : new Uint8Array(0);
76
}

src/traversableToJSON.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { XMLNode } from './XMLNode';
1+
import { parseString } from 'dynamic-typing';
2+
3+
import { XMLNode, XMLNodeValue } from './XMLNode';
34
import { ParseOptions } from './traversable/defaultOptions';
45
import { isTagNameInArrayMode, merge, isEmptyObject } from './util';
56

6-
// eslint-disable-next-line @typescript-eslint/no-var-requires
7-
const { parseString } = require('dynamic-typing');
8-
97
/**
108
*
119
* @param {*} node
@@ -17,7 +15,7 @@ export function traversableToJSON(
1715
node: XMLNode,
1816
options: ParseOptions,
1917
parentTagName?: string,
20-
): string | Uint8Array | Record<string, string | Uint8Array> {
18+
): XMLNodeValue | Record<string, XMLNodeValue> {
2119
const {
2220
dynamicTypingNodeValue,
2321
tagValueProcessor,
@@ -43,7 +41,12 @@ export function traversableToJSON(
4341
}
4442

4543
// otherwise create a textnode if node has some text
46-
if (node.value !== undefined && node.value.length !== 0) {
44+
if (
45+
node.value !== undefined &&
46+
(typeof node.value === 'number' ||
47+
typeof node.value === 'boolean' ||
48+
node.value.length !== 0)
49+
) {
4750
const asArray = isTagNameInArrayMode(
4851
node.tagName,
4952
arrayMode,

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"esModuleInterop": true,
55
"moduleResolution": "node",
66
"outDir": "lib",
7+
"skipLibCheck": true,
78
"sourceMap": true,
89
"strict": true,
910
"target": "es2022"

0 commit comments

Comments
 (0)