UNPKG

@progress/kendo-angular-common

Version:

Kendo UI for Angular - Utility Package

29 lines (28 loc) 1.13 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 setterCache = {}; setterCache['undefined'] = (obj) => obj; /** * @hidden */ export function setter(field) { if (setterCache[field]) { return setterCache[field]; } const fields = []; field.replace(FIELD_REGEX, function (_match, index, indexAccessor, fieldName) { fields.push(index !== undefined ? index : (indexAccessor || fieldName)); }); setterCache[field] = function (obj, value) { let root = obj; const depth = fields.length - 1; for (let idx = 0; idx < depth && root; idx++) { root = root[fields[idx]] = root[fields[idx]] || {}; } root[fields[depth]] = value; }; return setterCache[field]; }