|
| 1 | +--- |
| 2 | +layout: default-layout |
| 3 | +title: CodeParser Class - Dynamsoft Code Parser SDK JS Edition API Reference |
| 4 | +description: This page shows CodeParser Class of Dynamsoft Code Parser SDK JS Edition. |
| 5 | +keywords: CodeParser, api reference, JS, JavaScript |
| 6 | +needAutoGenerateSidebar: true |
| 7 | +--- |
| 8 | + |
| 9 | +# CodeParser Class |
| 10 | + |
| 11 | +The `CodeParser` class enable users to parse given bytes or a string to be human-readable. |
| 12 | + |
| 13 | +| Method | Description | |
| 14 | +| -------------------------------------------- | ---------------------------------------------------------------------- | |
| 15 | +| `static` [createInstance()](#createinstance) | Initializes a new instance of the `CodeParser` class. | |
| 16 | +| [dispose()](#dispose) | Releases all resources used by the `CodeParser` object. | |
| 17 | +| [disposed](#disposed) | Returns whether the `CodeParser` object has been disposed of. | |
| 18 | +| [initSettings](#initsettings) | Initializes runtime settings with the settings in a given JSON string. | |
| 19 | +| [resetSettings](#resetsettings) | Resets runtime settings to default. | |
| 20 | +| [parse](#parse) | Parses code data for readable results. | |
| 21 | + |
| 22 | +## createInstance |
| 23 | + |
| 24 | +Initializes a new instance of the `CodeParser` class. |
| 25 | + |
| 26 | +**Syntax** |
| 27 | + |
| 28 | +```typescript |
| 29 | +createInstance(): Promise<CodeParser>; |
| 30 | +``` |
| 31 | + |
| 32 | +**Parameter** |
| 33 | + |
| 34 | +None. |
| 35 | + |
| 36 | +**Return value** |
| 37 | + |
| 38 | +A promise that resolves to the initialized `CodeParser` object. |
| 39 | + |
| 40 | +**Code snippet** |
| 41 | + |
| 42 | +```javascript |
| 43 | +let parser = await Dynamsoft.DCP.CodeParser.createInstance(); |
| 44 | +``` |
| 45 | + |
| 46 | +## dispose |
| 47 | + |
| 48 | +Releases all resources used by the `CodeParser` object. |
| 49 | + |
| 50 | +**Syntax** |
| 51 | + |
| 52 | +```typescript |
| 53 | +dispose(): Promise<void>; |
| 54 | +``` |
| 55 | + |
| 56 | +**Parameter** |
| 57 | + |
| 58 | +None. |
| 59 | + |
| 60 | +**Return value** |
| 61 | + |
| 62 | +Returns a promise that resolves when the resources have been successfully released. |
| 63 | + |
| 64 | +**Code snippet** |
| 65 | + |
| 66 | +```javascript |
| 67 | +let parser = await Dynamsoft.DCP.CodeParser.createInstance(); |
| 68 | +// Use the parser to perform a job. |
| 69 | +// ... |
| 70 | +// Release the resources after the job is finished. |
| 71 | +parser.dispose(); |
| 72 | +``` |
| 73 | + |
| 74 | +## disposed |
| 75 | + |
| 76 | +Returns whether the `CodeParser` object has been disposed of. |
| 77 | + |
| 78 | +**Syntax** |
| 79 | + |
| 80 | +```typescript |
| 81 | +disposed: boolean; |
| 82 | +``` |
| 83 | + |
| 84 | +**Parameter** |
| 85 | + |
| 86 | +None. |
| 87 | + |
| 88 | +**Return value** |
| 89 | + |
| 90 | +A boolean value that indicates whether the `CodeParser` object has been disposed of. |
| 91 | + |
| 92 | +**Code snippet** |
| 93 | + |
| 94 | +```javascript |
| 95 | +if(parser.disposed){ |
| 96 | + console.log("The parser has been disposed of."); |
| 97 | +} else { |
| 98 | + // Use the parser to perform a job. |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +## initSettings |
| 103 | + |
| 104 | +Initializes settings from a given string. |
| 105 | + |
| 106 | +```typescript |
| 107 | +initSettings: (settings: string) => Promise<void>; |
| 108 | +``` |
| 109 | + |
| 110 | +**Parameters** |
| 111 | + |
| 112 | +* `settings`: A JSON string that represents the content of the settings. |
| 113 | + |
| 114 | +**Return value** |
| 115 | + |
| 116 | +A promise that resolves when the operation has completed. It does not provide any value upon resolution. |
| 117 | + |
| 118 | +## resetSettings |
| 119 | + |
| 120 | +Resets all parameters to default values. |
| 121 | + |
| 122 | +```typescript |
| 123 | +resetSettings: () => Promise<void>; |
| 124 | +``` |
| 125 | + |
| 126 | +**Parameters** |
| 127 | + |
| 128 | +None. |
| 129 | + |
| 130 | +**Return value** |
| 131 | + |
| 132 | +Returns a promise that resolves when the settings have been successfully reset to their default values. |
| 133 | + |
| 134 | +## parse |
| 135 | + |
| 136 | +Parses a single string to be human-readable. |
| 137 | + |
| 138 | +```typescript |
| 139 | +parse: (source: Uint8Array | string, taskSettingName?: string) => Promise<ParsedResultItem>; |
| 140 | +``` |
| 141 | + |
| 142 | +**Parameters** |
| 143 | + |
| 144 | +* `source`: the array of bytes or the string to parse. |
| 145 | + |
| 146 | +* `taskSettingName`: the name of [CodeParserTaskSetting](https://www.dynamsoft.com/capture-vision/docs/core/parameters/reference/code-parser-task-settings/) that defines the settings used for code parsing. |
| 147 | + |
| 148 | +**Return Value** |
| 149 | + |
| 150 | +Returns an array of [ParsedResultItem](./interfaces/parsed-result-item.md) containing the human-readable results. |
0 commit comments