UNPKG

any-serialize

Version:

Serialize / Deserialize any JavaScript objects, as long as you provides how-to. I have already provided `Date`, `RegExp`, `Set` and `Function`.

22 lines (19 loc) 494 B
import { IRegistration } from './utils' export const MongoDateAdapter: IRegistration = { prefix: '', key: '$date', item: Date, fromJSON: (current) => new Date(current) } export const MongoRegExpAdapter: IRegistration = { prefix: '', key: '$regex', item: RegExp, fromJSON (current: string, parent: { $options?: string }) { return new RegExp(current, parent.$options) }, toJSON (_this: any, parent: any) { parent.$options = _this.flags return _this.source } }