UNPKG

@builder.io/mitosis

Version:

Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io

25 lines (24 loc) 682 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.set = void 0; /** * Minimal implementation of lodash's _.set * https://lodash.com/docs/4.17.15#set * * See ./set.test.ts for usage examples */ const set = (obj, _path, value) => { if (Object(obj) !== obj) { return obj; } const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g); path .slice(0, -1) .reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : (a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}), obj)[path[path.length - 1]] = value; return obj; }; exports.set = set;