Skip to content

Commit

Permalink
fix: setFmtError
Browse files Browse the repository at this point in the history
  • Loading branch information
CN-Tower committed Jan 30, 2023
1 parent b769d02 commit 458afaa
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
47 changes: 39 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

## Usages

#### In html
### In html

```html
<script src="https://unpkg.com/[email protected]/fmt2json.min.js"></script>
Expand All @@ -31,10 +31,41 @@
const jsonString = fmt2json(source);
console.log(jsonString);
// =>
`{
"zjson": "ZJSON",
"description:"Online json formatter",
"version": "v4.1.8",
"updateTime": "2018-11-23",
"url": "https://zjson.net",
"project": "https://github.com/CN-Tower/zjson",
"language": [
"中文(简体)",
"English"
],
"keywords": [
"zjson",
"json formatter"
],
"content": {
"array": [
"element 001",
"element 002"
],
"boolean": true,
"null": null,
"number": 123,
"string": "Hello World",
"object": {
"property": "value",
"key": "val"
}
}
}`
</script>
```

#### In javascript
### In javascript

Run: `npm install format-to-json --save`;

Expand All @@ -47,7 +78,7 @@ const fmtInfo = fmt2json(source, { withDetails: true });
console.log(fmtInfo.result);
```

In js Result:
Output:

```js
{
Expand Down Expand Up @@ -80,11 +111,11 @@ In js Result:
' "key": "val"\r\n' +
' }\r\n' +
' }',
fmtType: 'success',
fmtSign: 'scc',
fmtType: 'danger',
fmtSign: 'end',
fmtLines: 29,
fmtTime: 1.1812089681625366,
message: 'Success formated 29 lines!',
fmtTime: 1.0678750276565552,
message: 'Expect a comma or a "}" in line: 29',
errFormat: true,
errIndex: 29,
errNear: '...": "val"\\n }\\n }>>>>>>',
Expand Down Expand Up @@ -127,8 +158,8 @@ interface FormatResult {
message: string;
errFormat: boolean;
errIndex: number;
errExpect: string;
errNear: string;
errExpect: string;
}
```

Expand Down
5 changes: 3 additions & 2 deletions fmt2json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* format-to-json v3.0.1
* format-to-json v3.0.2
* GitHub Repository <https://github.com/CN-Tower/format-to-json>
* Released under MIT license <https://github.com/CN-Tower/format-to-json/blob/master/LICENSE>
*/
Expand Down Expand Up @@ -572,8 +572,9 @@
if (signsQueue) {
var expBracket = getBracketPair(signsQueue.substr(-1));
setFmtError('end', expBracket);
} else {
setFmtError('scc');
}
setFmtError('scc');
}
fmtLines = curIndex;
}
Expand Down
4 changes: 2 additions & 2 deletions fmt2json.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ interface FormatResult {
message: string;
errFormat: boolean;
errIndex: number;
errExpect: string;
errNear: string;
errExpect: string;
}

declare function fmt2json(source: string, options?: FormatOptions): string;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "format-to-json",
"version": "3.0.1",
"version": "3.0.2",
"description": "Format string to a json like template.",
"main": "index.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/license.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* format-to-json v3.0.1
* format-to-json v3.0.2
* GitHub Repository <https://github.com/CN-Tower/format-to-json>
* Released under MIT license <https://github.com/CN-Tower/format-to-json/blob/master/LICENSE>
*/
3 changes: 2 additions & 1 deletion src/fmt2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,9 @@
if (signsQueue) {
const expBracket = getBracketPair(signsQueue.substr(-1));
setFmtError('end', expBracket);
} else {
setFmtError('scc');
}
setFmtError('scc');
}
fmtLines = curIndex;
}
Expand Down

0 comments on commit 458afaa

Please sign in to comment.