Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update dependencies and fix TS #20

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@
"@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",
"pako": "^2.1.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"rimraf": "^5.0.7",
"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"
}
}
3 changes: 1 addition & 2 deletions src/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
__tests__
.npmignore
.DS_Store
.npmignore
10 changes: 6 additions & 4 deletions src/XMLNode.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
export type XMLNodeValue = string | Uint8Array | number | boolean;

export class XMLNode {
public tagName: string;
public parent?: XMLNode;
public children: Record<string, XMLNode[]>;
public attributes?: Record<string, XMLNode | boolean>;
public value?: string | Uint8Array;
public value?: XMLNodeValue;
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;
}
Expand Down
7 changes: 3 additions & 4 deletions src/traversable/utils/concat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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) {
a = typeof b === 'string' ? '' : new Uint8Array(0);
}
Expand Down
17 changes: 10 additions & 7 deletions src/traversableToJSON.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* 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');

/**
*
* @param {*} node
Expand All @@ -17,7 +15,7 @@ export function traversableToJSON(
node: XMLNode,
options: ParseOptions,
parentTagName?: string,
): string | Uint8Array | Record<string, string | Uint8Array> {
): XMLNodeValue | Record<string, XMLNodeValue> {
const {
dynamicTypingNodeValue,
tagValueProcessor,
Expand All @@ -43,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,
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"esModuleInterop": true,
"moduleResolution": "node",
"outDir": "lib",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es2022"
Expand Down
Loading