Actually, I have now succeeded in deserializing objects (instead of Arrays). The solution is here.
Also, to create a MongoDB-compatible serialize, you can try.
const cond = { a: new Date(), b: /regexp/gi } const r = JSON.stringify(cond, function (k, v) { const v0 = this[k] if (v0) { if (v0 instanceof Date) { return { $date: v0.toISOString() } } else if (v0 instanceof RegExp) { return { $regex: v0.source, $options: v0.flags } } } return v }) console.log(r) console.log(JSON.parse(r, (_, v) => { if (v && typeof v === 'object') { if (v.$date) { return new Date(v.$date) } else if (v.$regex) { return new RegExp(v.$regex, v.$options) } } return v }))
I also created a Gist for the time being -- gist.github.com/patarapolw/c9fc59e...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Actually, I have now succeeded in deserializing objects (instead of Arrays). The solution is here.
patarapolw / any-serialize
Serialize any JavaScript objects, as long as you provides how-to. I have already provided Date, RegExp and Function.
Also, to create a MongoDB-compatible serialize, you can try.
I also created a Gist for the time being -- gist.github.com/patarapolw/c9fc59e...