MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / asObject

Function asObject

packages/repository/src/model.ts:317–326  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

315 * @param options the options
316 */
317function 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

Callers 1

toObjectMethod · 0.85

Calls 1

toObjectMethod · 0.45

Tested by

no test coverage detected