UNPKG

@conpago/mongo-cursor-pagination

Version:

Make it easy to return cursor-paginated results from a Mongo collection

23 lines 950 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = ({ propertyName, object, sortCaseInsensitive, }) => { const nestedFields = propertyName.split("."); const nestedFieldsCount = nestedFields.length; const finalValue = (() => { let tempValue = object; for (let i = 0; i < nestedFieldsCount; i++) { const nestedField = nestedFields[i]; if (i === nestedFieldsCount - 1) return tempValue[nestedField]; tempValue = tempValue[nestedField]; if (typeof tempValue !== "object" || tempValue === null) { // then cannot continue the nested searching for the desired value return undefined; } } })(); return sortCaseInsensitive && finalValue?.toLowerCase ? finalValue.toLowerCase() : finalValue; }; //# sourceMappingURL=getPropertyViaDotNotation.js.map