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 53 forks source link

support Date objects #56

Open skeggse opened 4 years ago

skeggse commented 4 years ago

Currently, jsesc produces unsupported code when passed a Date object:

jsesc({ value: new Date() })
// => '{\'value\':Tue Mar 31 2020 18:06:06 GMT-0700 (Pacific Daylight Time)}'

Ideally, this would produce a constructor for that date/time. I'm happy to implement - I'm thinking it'd just use the valueOf unless there's a good argument for using the ISO 8601 format.

mathiasbynens commented 4 years ago

Sounds good. The only reason I haven't added support for this is because I haven't had the need. Happy to review a patch!