UNPKG

@llumiverse/core

Version:

Provide an universal API to LLMs. Support for existing LLMs can be added by writing a driver.

45 lines 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveField = resolveField; /** * Get the property named by "name" of the given object * If an array is indexed using a string key then a map is done and an array with the content of the properties with that name are returned * Ex: docs.text => will return an array of text properties of the docs array * @param object the object * @param name the name of the property. * @returns the property value */ function _prop(object, name) { if (object === undefined) { return undefined; } if (Array.isArray(object)) { const index = +name; if (isNaN(index)) { // map array to property return object.map(item => item[name]); } else { return object[index]; } } else { return object[name]; } } function resolveField(object, path) { let p = object; if (!p) return p; if (!path.length) return p; const last = path.length - 1; for (let i = 0; i < last; i++) { p = _prop(p, path[i]); if (!p) { return undefined; } } return _prop(p, path[last]); } //# sourceMappingURL=resolver.js.map