-
Notifications
You must be signed in to change notification settings - Fork 11
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
8f59a39
commit 823b9d6
Showing
23 changed files
with
947 additions
and
741 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
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
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
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
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
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,22 +1,22 @@ | ||
import typescript from 'rollup-plugin-typescript2'; | ||
import pkg from './package.json'; | ||
import typescript from "rollup-plugin-typescript2"; | ||
import pkg from "./package.json"; | ||
|
||
export default [ | ||
{ | ||
input: 'src/index.ts', | ||
input: "src/index.ts", | ||
output: { | ||
file: pkg.browser, | ||
format: 'umd', | ||
name: 'jsonparse' | ||
format: "umd", | ||
name: "jsonparse", | ||
}, | ||
plugins: [ | ||
typescript({ | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
target: "es5", | ||
} | ||
} | ||
}) | ||
] | ||
}, | ||
}, | ||
}), | ||
], | ||
}, | ||
]; |
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,5 +1,5 @@ | ||
export { default as Tokenizer } from './tokenizer'; | ||
export { default as Parser } from './parser'; | ||
export { default as JsonParser } from './jsonparse'; | ||
export * as utf8 from './utils/utf-8'; | ||
export { TokenType } from './utils/constants'; | ||
export { default as Tokenizer } from "./tokenizer"; | ||
export { default as Parser } from "./parser"; | ||
export { default as JsonParser } from "./jsonparse"; | ||
export * as utf8 from "./utils/utf-8"; | ||
export { TokenType } from "./utils/constants"; |
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,25 +1,32 @@ | ||
import Tokenizer, { TokenizerOptions } from './tokenizer'; | ||
import Parser, { StackElement } from './parser'; | ||
import Tokenizer, { TokenizerOptions } from "./tokenizer"; | ||
import Parser, { StackElement } from "./parser"; | ||
|
||
export default class JSONParser { | ||
private tokenizer: Tokenizer; | ||
private parser: Parser; | ||
|
||
constructor (opts: TokenizerOptions = {}) { | ||
constructor(opts: TokenizerOptions = {}) { | ||
this.tokenizer = new Tokenizer(opts); | ||
this.parser = new Parser(); | ||
this.tokenizer.onToken = this.parser.write.bind(this.parser); | ||
} | ||
|
||
public write(buffer: any) { // TODO tighten types | ||
this.tokenizer.write(buffer); | ||
public write(input: Iterable<number> | string) { | ||
this.tokenizer.write(input); | ||
} | ||
|
||
public set onToken(cb: (token: number, value: any, offset: number) => void) { | ||
this.tokenizer.onToken = cb; | ||
} | ||
|
||
public set onValue(cb: (value: any, key: string | number | undefined, parent: any, stack: StackElement[]) => void) { | ||
public set onValue( | ||
cb: ( | ||
value: any, | ||
key: string | number | undefined, | ||
parent: any, | ||
stack: StackElement[], | ||
) => void, | ||
) { | ||
this.parser.onValue = cb; | ||
} | ||
} |
Oops, something went wrong.