Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sax-wasm

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sax-wasm - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

15

lib/saxWasm.d.ts

@@ -15,3 +15,4 @@ export declare class SaxEventType {

}
declare abstract class Reader<T> {
export declare type Detail = Position | Attribute | Text | Tag | StringReader;
export declare abstract class Reader<T = Detail> {
protected data: Uint8Array;

@@ -26,2 +27,3 @@ protected cache: {

};
abstract readonly value: any;
}

@@ -52,2 +54,9 @@ export declare class 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> {

@@ -65,2 +74,3 @@ readonly openStart: Position;

};
readonly value: string;
}

@@ -73,3 +83,3 @@ export interface SaxParserOptions {

events: number;
eventHandler: (type: SaxEventType, detail: Reader<any> | Position | string) => void;
eventHandler: (type: SaxEventType, detail: Detail) => void;
private readonly options;

@@ -84,2 +94,1 @@ private wasmSaxParser;

}
export {};

35

lib/saxWasm.js

@@ -5,2 +5,3 @@ "use strict";

}
exports.SaxEventType = SaxEventType;
// 1

@@ -30,3 +31,2 @@ SaxEventType.Text = 0b1;

SaxEventType.CloseCDATA = 0b100000000000;
exports.SaxEventType = SaxEventType;
class Reader {

@@ -39,2 +39,3 @@ constructor(data, ptr = 0) {

}
exports.Reader = Reader;
class Position {

@@ -101,2 +102,17 @@ constructor(line, character) {

exports.Text = Text;
class StringReader extends Reader {
get value() {
if (this.cache.value) {
return this.cache.value;
}
return (this.cache.value = readString(this.data.buffer, this.ptr, this.data.length));
}
toJSON() {
return { value: this.value };
}
toString() {
return this.value;
}
}
exports.StringReader = StringReader;
class Tag extends Reader {

@@ -163,2 +179,5 @@ get openStart() {

}
get value() {
return this.name;
}
}

@@ -170,6 +189,6 @@ exports.Tag = Tag;

const uint8array = new Uint8Array(this.wasmSaxParser.memory.buffer.slice(ptr, ptr + len));
let payload;
let detail;
switch (event) {
case SaxEventType.Attribute:
payload = new Attribute(uint8array);
detail = new Attribute(uint8array);
break;

@@ -179,15 +198,15 @@ case SaxEventType.OpenTag:

case SaxEventType.OpenTagStart:
payload = new Tag(uint8array);
detail = new Tag(uint8array);
break;
case SaxEventType.Text:
payload = new Text(uint8array);
detail = new Text(uint8array);
break;
case SaxEventType.OpenCDATA:
payload = readPosition(uint8array);
detail = readPosition(uint8array);
break;
default:
payload = readString(this.wasmSaxParser.memory.buffer, ptr, len);
detail = new StringReader(uint8array);
break;
}
this.eventHandler(event, payload);
this.eventHandler(event, detail);
};

@@ -194,0 +213,0 @@ this.options = options;

{
"name": "sax-wasm",
"version": "1.3.1",
"version": "1.4.0",
"repository": "https://github.com/justinwilaby/sax-wasm",

@@ -15,3 +15,3 @@ "description": "An extremely fast JSX, HTML and XML parser written in Rust compiled to WebAssembly for Node and the Web",

"scripts": {
"test": "nyc mocha src/js/__test__/",
"test": "nyc --reporter=text mocha",
"test:coveralls": "npm run test && nyc report --reporter=text-lcov | coveralls",

@@ -32,11 +32,14 @@ "build:wasm": "rustc ./src/lib.rs -Clto -O --crate-type cdylib --target wasm32-unknown-unknown -o ./lib/sax-wasm.wasm",

"devDependencies": {
"@types/mocha": "^2.2.47",
"@types/node": "^10.12.19",
"@types/webassembly-js-api": "^0.0.2",
"coveralls": "^3.0.2",
"@istanbuljs/nyc-config-typescript": "^0.1.3",
"@types/expect.js": "^0.3.29",
"@types/mocha": "^5.2.7",
"@types/node": "^12.0.8",
"coveralls": "^3.0.6",
"expect.js": "^0.3.1",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"typescript": "^3.2.4"
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"source-map-support": "^0.5.13",
"ts-node": "^8.3.0",
"typescript": "^3.6.2"
}
}

@@ -125,16 +125,16 @@ # SAX (Simple API for XML) for WebAssembly

|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#L48) |
|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) |

@@ -141,0 +141,0 @@ ## Speeding things up on large documents

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc