mathiasbynens / jsesc

Given some data, jsesc returns the shortest possible stringified & ASCII-safe representation of that data.
https://mths.be/jsesc
MIT License
716 stars 48 forks source link

Map and Set included in JSON output #57

Open skeggse opened 4 years ago

skeggse commented 4 years ago

As I understand it, json tries to ensure that the output is JSON-compatible, at least in the types supported. It seems that Map and Set don't comply with this:

jsesc({ set: new Set([12]), map: new Map([['a', 'b']]) }, { json: true })
// => '{"set":new Set([12]),"map":new Map([["a","b"]])}'

JSON.parse encounters a SyntaxError when attempting to interpret this output, which seems undesirable.

braco commented 1 year ago

This just tripped me up too. If theres no array coercion, the "json" config name is not accurate