@hpcc-js/wasm-expat 1.9.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +4 -4
- package/package.json +5 -4
- package/src/expat.ts +26 -30
- package/types/expat.d.ts +3 -2
- package/types/expatlib.d.ts +65 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/wasm-expat",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "hpcc-js - WASM expat",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"build-dev": "run-p gen-types bundle-dev",
|
|
27
27
|
"build": "run-p gen-types bundle",
|
|
28
28
|
"lint-skypack": "npx -y @skypack/package-check",
|
|
29
|
-
"lint-eslint": "eslint src/**/*.ts tests/**/*.ts",
|
|
29
|
+
"lint-eslint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
30
30
|
"lint": "run-p lint-eslint",
|
|
31
31
|
"test-browser": "vitest run --project browser",
|
|
32
32
|
"test-node": "vitest run --project node",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"update-major": "npx -y npm-check-updates -u"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@hpcc-js/esbuild-plugins": "1.7.0"
|
|
39
|
+
"@hpcc-js/esbuild-plugins": "1.7.0",
|
|
40
|
+
"@hpcc-js/wasm-util": "1.0.0"
|
|
40
41
|
},
|
|
41
42
|
"keywords": [
|
|
42
43
|
"graphviz",
|
|
@@ -54,5 +55,5 @@
|
|
|
54
55
|
},
|
|
55
56
|
"homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
|
|
56
57
|
"license": "Apache-2.0",
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "11395f5acfc865accde71905509bb45d5c79b11b"
|
|
58
59
|
}
|
package/src/expat.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @ts-expect-error importing from a wasm file is resolved via a custom esbuild plugin
|
|
2
|
-
import load, { reset } from "../../../build/packages/expat/
|
|
2
|
+
import load, { reset } from "../../../build/packages/expat/expatlib.wasm";
|
|
3
|
+
import type { MainModule, map_string_string } from "../types/expatlib.js";
|
|
4
|
+
import { MainModuleEx } from "@hpcc-js/wasm-util";
|
|
3
5
|
|
|
4
6
|
export type Attributes = { [key: string]: string };
|
|
5
7
|
export interface IParser {
|
|
@@ -8,18 +10,20 @@ export interface IParser {
|
|
|
8
10
|
characterData(content: string): void;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
function parseAttrs(attrs:
|
|
13
|
+
function parseAttrs(attrs: map_string_string): Attributes {
|
|
12
14
|
const retVal: Attributes = {};
|
|
13
|
-
const keys = attrs;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
retVal[
|
|
19
|
-
}
|
|
15
|
+
const keys = attrs.keys();
|
|
16
|
+
const size = keys.size();
|
|
17
|
+
for (let i = 0; i < size; ++i) {
|
|
18
|
+
const key = keys.get(i);
|
|
19
|
+
const value = attrs.get(key!);
|
|
20
|
+
retVal[key!] = value!;
|
|
21
|
+
}
|
|
20
22
|
return retVal;
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
let g_expat: Promise<Expat>;
|
|
26
|
+
|
|
23
27
|
/**
|
|
24
28
|
* Expat XML parser WASM library, provides a simplified wrapper around the Expat XML Parser library.
|
|
25
29
|
*
|
|
@@ -46,9 +50,10 @@ function parseAttrs(attrs: string): Attributes {
|
|
|
46
50
|
* ```
|
|
47
51
|
|
|
48
52
|
*/
|
|
49
|
-
export class Expat {
|
|
53
|
+
export class Expat extends MainModuleEx<MainModule> {
|
|
50
54
|
|
|
51
|
-
private constructor(
|
|
55
|
+
private constructor(_module: MainModule) {
|
|
56
|
+
super(_module);
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
/**
|
|
@@ -61,9 +66,10 @@ export class Expat {
|
|
|
61
66
|
* @returns A promise to an instance of the Expat class.
|
|
62
67
|
*/
|
|
63
68
|
static load(): Promise<Expat> {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
69
|
+
if (!g_expat) {
|
|
70
|
+
g_expat = (load() as Promise<MainModule>).then((module) => new Expat(module));
|
|
71
|
+
}
|
|
72
|
+
return g_expat;
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
/**
|
|
@@ -78,7 +84,7 @@ export class Expat {
|
|
|
78
84
|
* @returns The Expat c++ version
|
|
79
85
|
*/
|
|
80
86
|
version(): string {
|
|
81
|
-
return this._module.
|
|
87
|
+
return this._module.version();
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
/**
|
|
@@ -93,21 +99,11 @@ export class Expat {
|
|
|
93
99
|
* @returns `true`|`false` if the XML parse succeeds.
|
|
94
100
|
*/
|
|
95
101
|
parse(xml: string, callback: IParser): boolean {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
callback.endElement(this.tag());
|
|
102
|
-
};
|
|
103
|
-
parser.characterData = function () {
|
|
104
|
-
callback.characterData(this.content());
|
|
105
|
-
};
|
|
106
|
-
parser.create();
|
|
107
|
-
const retVal = parser.parse(xml);
|
|
108
|
-
parser.destroy();
|
|
109
|
-
this._module.destroy(parser);
|
|
110
|
-
return retVal;
|
|
102
|
+
return this._module.parse(xml, {
|
|
103
|
+
startElement: (tag: string, attrs: map_string_string) => callback.startElement(tag, parseAttrs(attrs)),
|
|
104
|
+
endElement: (tag: string) => callback.endElement(tag),
|
|
105
|
+
characterData: (content: string) => callback.characterData(content)
|
|
106
|
+
});
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
109
|
|
package/types/expat.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { MainModule } from "../types/expatlib.js";
|
|
2
|
+
import { MainModuleEx } from "@hpcc-js/wasm-util";
|
|
1
3
|
export type Attributes = {
|
|
2
4
|
[key: string]: string;
|
|
3
5
|
};
|
|
@@ -32,8 +34,7 @@ export interface IParser {
|
|
|
32
34
|
* ```
|
|
33
35
|
|
|
34
36
|
*/
|
|
35
|
-
export declare class Expat {
|
|
36
|
-
protected _module: any;
|
|
37
|
+
export declare class Expat extends MainModuleEx<MainModule> {
|
|
37
38
|
private constructor();
|
|
38
39
|
/**
|
|
39
40
|
* Compiles and instantiates the raw wasm.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
|
|
2
|
+
declare namespace RuntimeExports {
|
|
3
|
+
/**
|
|
4
|
+
* Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
|
|
5
|
+
* emscripten HEAP, returns a copy of that string as a Javascript String object.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} ptr
|
|
8
|
+
* @param {number=} maxBytesToRead - An optional length that specifies the
|
|
9
|
+
* maximum number of bytes to read. You can omit this parameter to scan the
|
|
10
|
+
* string until the first 0 byte. If maxBytesToRead is passed, and the string
|
|
11
|
+
* at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
|
|
12
|
+
* string will cut short at that byte index.
|
|
13
|
+
* @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
|
|
14
|
+
* @return {string}
|
|
15
|
+
*/
|
|
16
|
+
function UTF8ToString(ptr: number, maxBytesToRead?: number | undefined, ignoreNul?: boolean | undefined): string;
|
|
17
|
+
function lengthBytesUTF8(str: any): number;
|
|
18
|
+
function stringToUTF8(str: any, outPtr: any, maxBytesToWrite: any): any;
|
|
19
|
+
let HEAPU8: any;
|
|
20
|
+
}
|
|
21
|
+
interface WasmModule {
|
|
22
|
+
_malloc(_0: number): number;
|
|
23
|
+
_free(_0: number): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string;
|
|
27
|
+
export interface ClassHandle {
|
|
28
|
+
isAliasOf(other: ClassHandle): boolean;
|
|
29
|
+
delete(): void;
|
|
30
|
+
deleteLater(): this;
|
|
31
|
+
isDeleted(): boolean;
|
|
32
|
+
// @ts-ignore - If targeting lower than ESNext, this symbol might not exist.
|
|
33
|
+
[Symbol.dispose](): void;
|
|
34
|
+
clone(): this;
|
|
35
|
+
}
|
|
36
|
+
export interface vector_string extends ClassHandle {
|
|
37
|
+
size(): number;
|
|
38
|
+
get(_0: number): string | undefined;
|
|
39
|
+
push_back(_0: EmbindString): void;
|
|
40
|
+
resize(_0: number, _1: EmbindString): void;
|
|
41
|
+
set(_0: number, _1: EmbindString): boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface map_string_string extends ClassHandle {
|
|
45
|
+
keys(): vector_string;
|
|
46
|
+
size(): number;
|
|
47
|
+
get(_0: EmbindString): string | undefined;
|
|
48
|
+
set(_0: EmbindString, _1: EmbindString): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type IParser = {startElement: (tag: string, attrs: map_string_string) => void, endElement: (tag: string) => void, characterData: (content: string) => void};
|
|
52
|
+
|
|
53
|
+
interface EmbindModule {
|
|
54
|
+
vector_string: {
|
|
55
|
+
new(): vector_string;
|
|
56
|
+
};
|
|
57
|
+
map_string_string: {
|
|
58
|
+
new(): map_string_string;
|
|
59
|
+
};
|
|
60
|
+
version(): string;
|
|
61
|
+
parse(_0: EmbindString, _1: IParser): boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;
|
|
65
|
+
export default function MainModuleFactory (options?: unknown): Promise<MainModule>;
|