Option to decode JSON date string
hongnk opened this issue · 1 comments
hongnk commented
When sending Date objects, they are serialized into ISO string format, and JSON parse doesn't convert them back.
Propose to add option to JSON decode function, for example
const dateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
function dateReviver(key, value) {
if (typeof value === "string" && dateFormat.test(value)) {
return new Date(value);
}
return value;
}
module.exports.decode = function(str) {
return JSON.parse(str, dateReviver)
}
Pagebakers commented
How about adding EJSON support?