UNPKG

@progress/kendo-angular-common

Version:

Kendo UI for Angular - Utility Package

28 lines (27 loc) 1.06 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ const FIELD_REGEX = /\[(?:(\d+)|['"](.*?)['"])\]|((?:(?!\[.*?\]|\.).)+)/g; const getterCache = {}; getterCache['undefined'] = () => undefined; /** * @hidden */ export function getter(field) { if (getterCache[field]) { return getterCache[field]; } const fields = []; field.replace(FIELD_REGEX, function (_match, index, indexAccessor, fieldName) { fields.push(index !== undefined ? index : (indexAccessor || fieldName)); }); getterCache[field] = function (obj) { let result = obj; for (let idx = 0; idx < fields.length && result; idx++) { result = result[fields[idx]]; } return result; }; return getterCache[field]; }