Skip to content

Commit

Permalink
Merge 83f26e3 into c4ba6be
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Wilaby committed Sep 1, 2019
2 parents c4ba6be + 83f26e3 commit 93878fc
Show file tree
Hide file tree
Showing 23 changed files with 2,054 additions and 1,743 deletions.
7 changes: 7 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
require: 'source-map-support/register',
'full-trace': true,
bail: true,
extension: ['ts'],
spec: 'src/**/*.spec.ts'
};
13 changes: 7 additions & 6 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"extension": [
".js"
".ts"
],
"include": [
"lib/**/*.js"
"src/**/*.ts"
],
"require": [
"ts-node/register"
],
"exclude": [
"**/node_modules/**",
"**/__test__/**",
"**/src/**",
"**/coverage/**",
"**/*.d.ts"
"**/coverage/**"
],
"reporter": [
"html"
],
"all": true,
"all": false,
"cache": true
}
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,20 @@ parser.events = SaxEventType.Text | SaxEventType.OpenTag | SaxEventType.Attribut
```
Complete list of event/argument pairs:

|Event |Mask |Argument passed to handler |
|----------------------------------|--------------|---------------------------------------------|
|SaxEventType.Text |0b000000000001|text: [Text](src/js/saxWasm.ts#L91) |
|SaxEventType.ProcessingInstruction|0b000000000010|procInst: string |
|SaxEventType.SGMLDeclaration |0b000000000100|sgmlDecl: string |
|SaxEventType.Doctype |0b000000001000|doctype: string |
|SaxEventType.Comment |0b000000010000|comment: string |
|SaxEventType.OpenTagStart |0b000000100000|tag: [Tag](src/js/saxWasm.ts#L114) |
|SaxEventType.Attribute |0b000001000000|attribute: [Attribute](src/js/saxWasm.ts#L51)|
|SaxEventType.OpenTag |0b000010000000|tag: [Tag](src/js/saxWasm.ts#L48) |
|SaxEventType.CloseTag |0b000100000000|tag: [Tag](src/js/saxWasm.ts#L48) |
|SaxEventType.OpenCDATA |0b001000000000|start: [Position](src/js/saxWasm.ts#L41) |
|SaxEventType.CDATA |0b010000000000|cdata: string |
|SaxEventType.CloseCDATA |0b100000000000|end: [Position](src/js/saxWasm.ts#L41) |
|Event |Mask |Argument passed to handler |
|----------------------------------|--------------|------------------------------------------------|
|SaxEventType.Text |0b000000000001|text: [Text](src/js/saxWasm.ts#L95) |
|SaxEventType.ProcessingInstruction|0b000000000010|procInst: [StringReader](src/js/saxWasm.ts#L118)|
|SaxEventType.SGMLDeclaration |0b000000000100|sgmlDecl: [StringReader](src/js/saxWasm.ts#L118)|
|SaxEventType.Doctype |0b000000001000|doctype: [StringReader](src/js/saxWasm.ts#L118) |
|SaxEventType.Comment |0b000000010000|comment: [StringReader](src/js/saxWasm.ts#L118) |
|SaxEventType.OpenTagStart |0b000000100000|tag: [Tag](src/js/saxWasm.ts#L135) |
|SaxEventType.Attribute |0b000001000000|attribute: [Attribute](src/js/saxWasm.ts#L55) |
|SaxEventType.OpenTag |0b000010000000|tag: [Tag](src/js/saxWasm.ts#L135) |
|SaxEventType.CloseTag |0b000100000000|tag: [Tag](src/js/saxWasm.ts#L135) |
|SaxEventType.OpenCDATA |0b001000000000|start: [Position](src/js/saxWasm.ts#L45) |
|SaxEventType.CDATA |0b010000000000|cdata: [StringReader](src/js/saxWasm.ts#L118) |
|SaxEventType.CloseCDATA |0b100000000000|end: [Position](src/js/saxWasm.ts#L45) |

## Speeding things up on large documents
The speed of the sax-wasm parser is incredibly fast and can parse very large documents in a blink of an eye. Although
Expand Down
2 changes: 1 addition & 1 deletion lib/sax-wasm.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* tslint:disable */
import * as wasm from './sax-wasm.wasm_bg.wasm';

Binary file modified lib/sax-wasm.wasm
Binary file not shown.
15 changes: 12 additions & 3 deletions lib/saxWasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export declare class SaxEventType {
static Cdata: number;
static CloseCDATA: number;
}
declare abstract class Reader<T> {
export declare type Detail = Position | Attribute | Text | Tag | StringReader;
export declare abstract class Reader<T = Detail> {
protected data: Uint8Array;
protected cache: {
[prop: string]: T;
Expand All @@ -22,6 +23,7 @@ declare abstract class Reader<T> {
abstract toJSON(): {
[prop: string]: T;
};
abstract readonly value: any;
}
export declare class Position {
line: number;
Expand All @@ -47,6 +49,13 @@ export declare class Text extends Reader<string | Position> {
[prop: string]: string | Position;
};
}
export declare class StringReader extends Reader<string> {
readonly value: string;
toJSON(): {
[p: string]: string;
};
toString(): string;
}
export declare class Tag extends Reader<Attribute[] | Text[] | Position | string | number | boolean> {
readonly openStart: Position;
readonly openEnd: Position;
Expand All @@ -59,14 +68,15 @@ export declare class Tag extends Reader<Attribute[] | Text[] | Position | string
toJSON(): {
[p: string]: Attribute[] | Text[] | Position | string | number | boolean;
};
readonly value: string;
}
export interface SaxParserOptions {
highWaterMark: number;
}
export declare class SAXParser {
static textDecoder: TextDecoder;
events: number;
eventHandler: (type: SaxEventType, detail: Reader<any> | Position | string) => void;
eventHandler: (type: SaxEventType, detail: Detail) => void;
private readonly options;
private wasmSaxParser;
private writeBuffer;
Expand All @@ -76,4 +86,3 @@ export declare class SAXParser {
prepareWasm(saxWasm: Uint8Array): Promise<boolean>;
protected eventTrap: (event: number, ptr: number, len: number) => void;
}
export {};
35 changes: 27 additions & 8 deletions lib/saxWasm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/saxWasm.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 93878fc

Please sign in to comment.