* Convert a value to a plain object as DTO. * * - The prototype of the value in primitive types are preserved, * like `Date`, `ObjectId`. * - If the value is an instance of custom model, call `toObject` to convert. * - If the value is an array, convert each element recursively. * * @param v
(value: any, options?: Options)
| 315 | * @param options the options |
| 316 | */ |
| 317 | function asObject(value: any, options?: Options): any { |
| 318 | if (value == null) return value; |
| 319 | if (typeof value.toObject === 'function') { |
| 320 | return value.toObject(options); |
| 321 | } |
| 322 | if (Array.isArray(value)) { |
| 323 | return value.map(item => asObject(item, options)); |
| 324 | } |
| 325 | return value; |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Base class for models |