Skip to content

Commit

Permalink
Bump to v1.0.3, tweak stripJsonComments()
Browse files Browse the repository at this point in the history
Previously the code always performed the comma check after checking for
string openeings or the end of an array or object. This change prevents
those other comparisons if we already know the current character is a
comma.
  • Loading branch information
mbland committed Jan 1, 2024
1 parent a3a41ff commit 1f73de0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -55,7 +55,7 @@ Running the wrapper will generate the local `file://` URL to the generated
`index.html` file, e.g.:

```text
file:///path/to/jsdoc/output/jsdoc-cli-wrapper/1.0.0/index.html
file:///path/to/jsdoc/output/jsdoc-cli-wrapper/1.0.3/index.html
```

You can click on or copy this link to open it in your browser. You can also open
Expand Down Expand Up @@ -99,10 +99,10 @@ This wrapper resolves both of these minor annoyances.
```sh
$ pnpm jsdoc

> jsdoc-cli-wrapper@1.0.1 jsdoc /path/to/jsdoc-cli-wrapper
> jsdoc-cli-wrapper@1.0.3 jsdoc /path/to/jsdoc-cli-wrapper
> node index.js -c jsdoc.json .

file:///path/to/jsdoc-cli-wrapper/jsdoc/jsdoc-cli-wrapper/1.0.0/index.html
file:///path/to/jsdoc-cli-wrapper/jsdoc/jsdoc-cli-wrapper/1.0.3/index.html
```

Of course, your own project would use `jsdoc-cli-wrapper` instead of `node
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Expand Up @@ -197,10 +197,12 @@ export function stripJsonComments(str) {
comment = (c === '/') ? 'line' : 'block'
c = result[i-1] = ' '
}
} else if (c === ',') {
comma = i
} else { // outside any valid string or comment, replace trailing commas
if (c === '"') inString = true
else if (comma && (c === ']' || c === '}')) result[comma] = ' '
comma = (c === ',') ? i : null
comma = null
}
result.push(c)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jsdoc-cli-wrapper",
"version": "1.0.2",
"version": "1.0.3",
"description": "JSDoc command line interface wrapper",
"main": "index.js",
"bin": "./index.js",
Expand Down

0 comments on commit 1f73de0

Please sign in to comment.