-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
458f612
commit 8e0180f
Showing
14 changed files
with
388 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
/coverage | ||
/.nyc_output | ||
/target | ||
/node_modules | ||
.idea | ||
/lib | ||
/pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './saxWasm'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
export declare class SaxEventType { | ||
static Text: number; | ||
static ProcessingInstruction: number; | ||
static SGMLDeclaration: number; | ||
static Doctype: number; | ||
static Comment: number; | ||
static OpenTagStart: number; | ||
static Attribute: number; | ||
static OpenTag: number; | ||
static CloseTag: number; | ||
static OpenCDATA: number; | ||
static Cdata: number; | ||
static CloseCDATA: number; | ||
} | ||
declare abstract class Reader<T> { | ||
constructor(buf: Uint8Array, ptr: number); | ||
protected abstract read(buf: Uint8Array, ptr: number): void; | ||
} | ||
export declare class Position { | ||
line: number; | ||
character: number; | ||
constructor(line: number, character: number); | ||
} | ||
export declare class Attribute extends Reader<string | number | Position> { | ||
static BYTES_IN_DESCRIPTOR: number; | ||
nameEnd: Position; | ||
nameStart: Position; | ||
valueEnd: Position; | ||
valueStart: Position; | ||
name: string; | ||
value: string; | ||
protected read(buf: Uint8Array, ptr: number): void; | ||
} | ||
export declare class Text extends Reader<string | Position> { | ||
static BYTES_IN_DESCRIPTOR: number; | ||
end: Position; | ||
start: Position; | ||
value: string; | ||
protected read(buf: Uint8Array, ptr: number): void; | ||
} | ||
export declare class Tag extends Reader<Attribute[] | Text[] | Position | string | number | boolean> { | ||
name: string; | ||
attributes: Attribute[]; | ||
textNodes: Text[]; | ||
selfClosing: boolean; | ||
openStart: Position; | ||
openEnd: Position; | ||
closeStart: Position; | ||
closeEnd: Position; | ||
protected read(buf: Uint8Array, ptr: number): void; | ||
} | ||
export declare class SAXParser { | ||
static textDecoder: TextDecoder; | ||
static textEncoder: TextEncoder; | ||
events: number; | ||
eventHandler: (type: SaxEventType, detail: Reader<any> | Position | string) => void; | ||
private wasmSaxParser; | ||
constructor(events?: number); | ||
write(value: string): void; | ||
end(): void; | ||
prepareWasm(saxWasm: Uint8Array): Promise<boolean>; | ||
protected eventTrap: (event: number, ptr: number, len: number) => void; | ||
} | ||
export {}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
"expect.js": "^0.3.1", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"sax": "^1.2.4", | ||
"typescript": "^3.2.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const sax = require("sax"); | ||
const {SaxEventType, SAXParser} = require('../../../lib/'); | ||
const parser = sax.parser(true); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const doc = fs.readFileSync(path.resolve(__dirname + '/xml.xml'), {encoding:'utf8'}); | ||
const saxWasm = fs.readFileSync(path.resolve(__dirname, '../../../lib/sax-wasm.wasm')); | ||
|
||
parser.onopentag = function() { | ||
|
||
} | ||
|
||
let t = Date.now(); | ||
parser.write(doc); | ||
console.log(Date.now() - t); | ||
|
||
|
||
const wasmParser = new SAXParser(SaxEventType.OpenTagStart); | ||
|
||
wasmParser.eventHandler = function (event, data) { | ||
|
||
}; | ||
|
||
wasmParser.prepareWasm(saxWasm).then(() => { | ||
let t = Date.now(); | ||
wasmParser.write(doc); | ||
console.log(Date.now() - t); | ||
}); |
Oops, something went wrong.