Skip to content
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
21 changes: 0 additions & 21 deletions .github/workflows/documentationjs.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: TypeDoc

on:
workflow_dispatch:
release:
types: [published]

jobs:
typedoc:
uses: zakodium/workflows/.github/workflows/typedoc.yml@typedoc-v1
with:
entry: 'src/index.ts'
secrets:
github-token: ${{ secrets.BOT_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ dist
.yarn/install-state.gz
.pnp.*

.claude
.DS_Store

lib
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@
"url": "https://github.com/cheminfo/arraybuffer-xml-parser/issues"
},
"homepage": "https://github.com/cheminfo/arraybuffer-xml-parser#readme",
"dependencies": {
"dynamic-typing": "^2.0.0"
},
"devDependencies": {
"@types/he": "^1.2.3",
"@vitest/coverage-v8": "4.0.12",
"@zakodium/tsconfig": "^1.0.2",
"cheminfo-build": "^1.3.1",
"@types/node": "^25.5.0",
"@vitest/coverage-v8": "4.1.2",
"@zakodium/tsconfig": "^1.0.3",
"cheminfo-build": "^1.3.2",
"eslint": "^9.39.1",
"eslint-config-cheminfo-typescript": "^21.0.1",
"globals": "^16.5.0",
"eslint-config-cheminfo-typescript": "^21.1.0",
"globals": "^17.4.0",
"he": "^1.2.0",
"ml-spectra-processing": "^14.18.1",
"ml-spectra-processing": "^14.22.0",
"pako": "^2.1.0",
"prettier": "^3.6.2",
"rimraf": "^6.1.2",
"prettier": "^3.8.1",
"rimraf": "^6.1.3",
"typescript": "^5.9.3",
"uint8-base64": "^1.0.0",
"vitest": "^4.0.12"
},
"dependencies": {
"@types/node": "^24.10.1",
"dynamic-typing": "^1.0.1"
"vitest": "^4.1.2"
}
}
1 change: 1 addition & 0 deletions src/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__tests__
.DS_Store
.npmignore
8 changes: 4 additions & 4 deletions src/XMLNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TagValueProcessor } from './traversable/defaultOptions.js';
import type { TagValueProcessor } from './traversable/defaultOptions.ts';

export type XMLNodeValue = string | Uint8Array | number | boolean;
export type XMLAttributeValue = string | number | boolean;
Expand Down Expand Up @@ -36,7 +36,7 @@
arrayConcat.set(toAppend, this.bytes.length);
this.bytes = arrayConcat;
}
public get value(): any {

Check warning on line 39 in src/XMLNode.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
if (this.cachedValue === undefined) {
const value = this.tagValueProcessor(this.bytes, this);
this.cachedValue = value;
Expand All @@ -44,9 +44,9 @@
return this.cachedValue;
}
public addChild(child: XMLNode) {
if (Array.isArray(this.children[child.tagName])) {
//already presents
this.children[child.tagName].push(child);
const existing = this.children[child.tagName];
if (Array.isArray(existing)) {
existing.push(child);
} else {
this.children[child.tagName] = [child];
}
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/arrayModeSpec.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const encoder = new TextEncoder();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const encoder = new TextEncoder();

Expand All @@ -15,8 +15,7 @@
a: { b: [0, 1] },
};

// eslint-disable-next-line no-extend-native
Array.prototype.someExtentionOfArrayPrototype =
(Array.prototype as any).someExtentionOfArrayPrototype =

Check warning on line 18 in src/__tests__/arrayWithExtendedPrototypePropsSpec.test.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
'someExtentionOfArrayPrototype';

const result = parse(xmlData, {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/attributesSpec.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
// import he from 'he';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const encoder = new TextEncoder();

Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/base64.test.js → src/__tests__/base64.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { decode as base64decode } from 'uint8-base64';
import { expect, test } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';
// library to convert base64 <--> arrayBuffer: https://github.com/niklasvh/base64-arraybuffer/blob/master/src/index.ts

const encoder = new TextEncoder();
Expand All @@ -15,15 +15,15 @@
<binary>AAAAAAAA8D8AAAAAAAAAQAAAAAAAAAhA</binary>
</binaryDataArray>`);

let result = parse(xmlData, {
const result = parse(xmlData, {
attributeNameProcessor: (name) => name,
tagValueProcessor: (value, node) => {
if (node.tagName !== 'binary') return decoder.decode(value);
const decoded = base64decode(value);
// isLittleEndian and the data were encoded in littleEndian
return new Float64Array(decoded.buffer);
},
});
}) as Record<string, any>;

Check warning on line 26 in src/__tests__/base64.test.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type

expect(result.binaryDataArray.binary).toStrictEqual(
Float64Array.from([1, 2, 3]),
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/cdataSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'node:path';

import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const encoder = new TextEncoder();

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/cheminfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

describe('XMLParser', () => {
it('Try to parse a very simple example', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/cyrillic.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

describe('XMLParser', () => {
it('should parse XML with cyrillic characters to JSON string', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/data.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const encoder = new TextEncoder();

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/parseStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import { describe, expect, it } from 'vitest';

import { parseStream } from '../parseStream.js';
import { parseStream } from '../parseStream.ts';

describe('parseStream', () => {
it('simple case', async () => {
const file = await open(join(__dirname, 'assets/sample.xml'), 'r');
const CHUNK_SIZE = 10;
const transformStream = new TransformStream({
start: function start() {}, // required.

Check warning on line 13 in src/__tests__/parseStream.test.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected empty method 'start'
transform: async function transform(chunk, controller) {
if (chunk === null) controller.terminate();
chunk = new Uint8Array(await chunk);
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/stopNodes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const encoder = new TextEncoder();

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/tagProcessors.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

describe('XMLParser', () => {
it('tag name processor', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/__tests__/valueProcessors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import he from 'he'; // HTML entity encoder/decoder
import { describe, expect, it } from 'vitest';
/* eslint-disable camelcase */

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const encoder = new TextEncoder();
const decoder = new TextDecoder();
Expand Down Expand Up @@ -89,8 +89,9 @@ describe('XMLParser', () => {
const resultMap: Record<string, Uint8Array[]> = {};
parse(xmlData, {
tagValueProcessor: (value, node) => {
if (resultMap[node.tagName]) {
resultMap[node.tagName].push(value);
const existing = resultMap[node.tagName];
if (existing) {
existing.push(value);
} else {
resultMap[node.tagName] = [value];
}
Expand Down
10 changes: 6 additions & 4 deletions src/__tests__/xmlParser.mz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { decode } from 'uint8-base64';
import { expect, test } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const decoder = new TextDecoder();

Expand All @@ -16,17 +16,17 @@
const xmlData = readFileSync(fileNamePath);

// eslint-disable-next-line unicorn/consistent-function-scoping
const tagValueProcessor = async (bytes: Uint8Array, node: any) => {

Check warning on line 19 in src/__tests__/xmlParser.mz.test.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
if (node.tagName !== 'binary') return decoder.decode(bytes);
const ontologies = node.parent.children.cvParam.map(
(entry: any) => entry.attributes.accession,

Check warning on line 22 in src/__tests__/xmlParser.mz.test.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
);
return decodeBase64(bytes, { ontologies });
};

const result = parse(xmlData, {
tagValueProcessor,
}) as any;

Check warning on line 29 in src/__tests__/xmlParser.mz.test.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type

await recursiveResolve(result);

Expand All @@ -48,7 +48,7 @@
});
});

export async function decodeBase64(

Check warning on line 51 in src/__tests__/xmlParser.mz.test.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
base64: Uint8Array,
options: { ontologies?: string[] } = {},
) {
Expand Down Expand Up @@ -76,7 +76,9 @@
switch (compression.toLowerCase()) {
case 'zlib': {
const ds = new DecompressionStream('deflate');
const decompressedStream = new Blob([uint8Array])
const decompressedStream = new Blob([
uint8Array as Uint8Array<ArrayBuffer>,
])
.stream()
.pipeThrough(ds);
const decompressedArrayBuffer = await new Response(
Expand Down Expand Up @@ -116,8 +118,8 @@
i += step
) {
for (let j = 0; j < step / 2; j++) {
const temp = uint8Array[i + j];
uint8Array[i + j] = uint8Array[i + step - 1 - j];
const temp = uint8Array[i + j] as number;
uint8Array[i + j] = uint8Array[i + step - 1 - j] as number;
uint8Array[i + step - 1 - j] = temp;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/xmlParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseString } from 'dynamic-typing';
import { recursiveResolve } from 'ml-spectra-processing';
import { describe, expect, it } from 'vitest';

import { parse } from '../parse.js';
import { parse } from '../parse.ts';

const encoder = new TextEncoder();
const decoder = new TextDecoder();
Expand Down
2 changes: 1 addition & 1 deletion src/bufferUtils/__tests__/arrayIndexOf.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { arrayIndexOf } from '../arrayIndexOf.js';
import { arrayIndexOf } from '../arrayIndexOf.ts';

describe('arrayIndexOf', () => {
it('should find the index pointing to the begining of the found string in array', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/bufferUtils/__tests__/arrayTrim.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';

import { arrayTrim } from '../arrayTrim.js';
import { arrayTrim } from '../arrayTrim.ts';

test('arrayTrim', () => {
const beginning = new Uint8Array([32, 32, 32, 32, 32, 32, 32, 33, 33, 97]);
Expand Down
4 changes: 2 additions & 2 deletions src/bufferUtils/arrayTrim.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
export function arrayTrim(array: Uint8Array, arg?: unknown) {

Check warning on line 2 in src/bufferUtils/arrayTrim.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
let i = 0;
let j = array.length - 1;
for (; i < array.length && array[i] <= 0x20; i++);
for (; j >= i && array[j] <= 0x20; j--);
for (; i < array.length && (array[i] as number) <= 0x20; i++);
for (; j >= i && (array[j] as number) <= 0x20; j--);
if (i === 0 && j === array.length - 1) return array;
return array.subarray(i, j + 1);
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './parse.js';
export * from './parseStream.js';
export * from './parse.ts';
export * from './parseStream.ts';
8 changes: 4 additions & 4 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type {
ParseOptions,
RealParseOptions,
} from './traversable/defaultOptions.js';
import { defaultOptions } from './traversable/defaultOptions.js';
import { getTraversable } from './traversable/getTraversable.js';
import { traversableToJSON } from './traversableToJSON.js';
} from './traversable/defaultOptions.ts';
import { defaultOptions } from './traversable/defaultOptions.ts';
import { getTraversable } from './traversable/getTraversable.ts';
import { traversableToJSON } from './traversableToJSON.ts';

/**
* Parse an ArrayBuffer or Uint8Array representing an XML and return an object
Expand Down
8 changes: 4 additions & 4 deletions src/parseStream.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StreamParseOptions } from './traversable/defaultOptions.js';
import { defaultStreamOptions } from './traversable/defaultOptions.js';
import { getTraversableGenerator } from './traversable/getTraversableGenerator.js';
import { traversableToJSON } from './traversableToJSON.js';
import type { StreamParseOptions } from './traversable/defaultOptions.ts';
import { defaultStreamOptions } from './traversable/defaultOptions.ts';
import { getTraversableGenerator } from './traversable/getTraversableGenerator.ts';
import { traversableToJSON } from './traversableToJSON.ts';

/**
* Parse a web stream representing an XML and emit objects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';

import { closingIndexForOpeningTag } from '../closingIndexForOpeningTag.js';
import { closingIndexForOpeningTag } from '../closingIndexForOpeningTag.ts';

test('sclosingIndexForOpeningTag', () => {
expect(
Expand Down
2 changes: 1 addition & 1 deletion src/traversable/closingIndexForOpeningTag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decoder } from './utils/utf8Decoder.js';
import { decoder } from './utils/utf8Decoder.ts';

/**
* Search for the corresponding closing tag '>'
Expand Down
2 changes: 1 addition & 1 deletion src/traversable/defaultOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseString } from 'dynamic-typing';

import type { XMLAttributeValue, XMLNode } from '../XMLNode.js';
import type { XMLAttributeValue, XMLNode } from '../XMLNode.ts';

const utf8Decoder = new TextDecoder();

Expand Down
2 changes: 1 addition & 1 deletion src/traversable/findClosingIndex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { arrayIndexOf } from '../bufferUtils/arrayIndexOf.js';
import { arrayIndexOf } from '../bufferUtils/arrayIndexOf.ts';

export function findClosingIndex(
xmlData: Uint8Array,
Expand Down
18 changes: 9 additions & 9 deletions src/traversable/getTraversable.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { XMLNode } from '../XMLNode.js';
import { arrayIndexOf } from '../bufferUtils/arrayIndexOf.js';
import { arrayTrim } from '../bufferUtils/arrayTrim.js';
import { XMLNode } from '../XMLNode.ts';
import { arrayIndexOf } from '../bufferUtils/arrayIndexOf.ts';
import { arrayTrim } from '../bufferUtils/arrayTrim.ts';

import { closingIndexForOpeningTag } from './closingIndexForOpeningTag.js';
import type { RealParseOptions } from './defaultOptions.js';
import { findClosingIndex } from './findClosingIndex.js';
import { parseAttributesString } from './parseAttributesString.js';
import { removeNameSpaceIfNeeded } from './utils/removeNameSpaceIfNeeded.js';
import { decoder } from './utils/utf8Decoder.js';
import { closingIndexForOpeningTag } from './closingIndexForOpeningTag.ts';
import type { RealParseOptions } from './defaultOptions.ts';
import { findClosingIndex } from './findClosingIndex.ts';
import { parseAttributesString } from './parseAttributesString.ts';
import { removeNameSpaceIfNeeded } from './utils/removeNameSpaceIfNeeded.ts';
import { decoder } from './utils/utf8Decoder.ts';

export function getTraversable(xmlData: Uint8Array, options: RealParseOptions) {
const { tagValueProcessor } = options;
Expand Down
Loading
Loading