CodeParser
A CodeParser takes code data in forms of byte array or plain string as input and returns parsed results. The following code snippet shows its basic usage:
let parser = await Dynamsoft.DCP.CodeParser.createInstance();
parser.setCodeFormat(enumcodeformat);
let result = await parser.parseData(code);
console.log(result);
API Index
Create and Destroy
API Name | Description |
---|---|
createInstance() | Creates a CodeParser instance. |
destroyContext() | Destroys the CodeParser instance in WASM. |
Set Code Format
API Name | Description |
---|---|
setCodeFormat() | Sets input code’s format. |
Parse Code Data
API Name | Description |
---|---|
parseData() | Parses code data for readable results. |
createInstance
Creates a CodeParser
instance.
static createInstance(): Promise<CodeParser>
Return Value
A promise resolving to the created CodeParser
object.
Code Snippet
let reader = await Dynamsoft.DCP.CodeParser.createInstance();
destroyContext
Destroys the CodeParser
instance in WASM. If your page needs to create new instances from time to time, don’t forget to destroy unused old instances.
destroyContext(): void
Code Snippet
let parser = await Dynamsoft.DCP.CodeParser.createInstance();
// ... parse ...
parser.destroyContext();
setCodeFormat
Sets the code format that needs parsing. See EnumCodeFormat to check if it has the code format you are looking for.
setCodeFormat(format: EnumCodeFormat): Promise<void>
Parameters
format
: specifies the code’s format represented by EnumCodeFormat.
Return Value
A promise that resolves when the operation succeeds.
Code Snippet
await parser.setCodeFormat(Dynamsoft.DCP.EnumCodeFormat.CF_AUTO);
// ... parse ...
parseData
Parses the code into readable info.
parseData(source: number[] | Uint8Array | string): Promise<ParseResult>
Parameters
source
: specifies the code data represented by a numder[], Uint8Array or string.
Return Value
A promise resolving to a ParseResult
object which contains the parsing result.
Code Snippet
await parser.parseData(YOUR-CODE-THAT-NEEDS-PARSING);
See Also