mathiasbynens / mathiasbynens/jsesc
Make `jsesc --object` accept non-JSON-formatted data as well
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 800
- Forks
- 54
- PR merge metrics
- No merged PRs in 30d
Description
$ jsesc --object '{"foo":42}'
{'foo':42}
$ jsesc --object "{'foo':42}"
Unexpected token '
Error: failed to escape.
If you think this is a bug in jsesc, please report it:
https://github.com/mathiasbynens/jsesc/issues/new
Stack trace using jsesc@0.4.1:
SyntaxError: Unexpected token '
at Object.parse (native)
at /usr/local/share/npm/lib/node_modules/jsesc/bin/jsesc:85:20
at Array.forEach (native)
at main (/usr/local/share/npm/lib/node_modules/jsesc/bin/jsesc:49:11)
at /usr/local/share/npm/lib/node_modules/jsesc/bin/jsesc:110:3
at Object.<anonymous> (/usr/local/share/npm/lib/node_modules/jsesc/bin/jsesc:133:2)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
This is currently by design, since we use JSON.parse(). But maybe we could use something like @espadrine’s localeval instead?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in bin/jsesc around line 85, where --object input is passed to JSON.parse(), and review the surrounding argument handling. Compare the JSON example with the single-quoted example, then define and test the accepted non-JSON syntax and its failure behavior; the issue does not specify a final parser or complete acceptance criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100