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.
As I understand it,
json
tries to ensure that the output is JSON-compatible, at least in the types supported. It seems thatMap
andSet
don't comply with this:JSON.parse
encounters aSyntaxError
when attempting to interpret this output, which seems undesirable.