UNPKG

jest-metadata

Version:

🦸‍♂️ Superhero power for your Jest reporters! 🦸‍♀️

32 lines 918 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.set = void 0; const isPrimitive_1 = require("./isPrimitive"); function set(obj, path, value) { if ((0, isPrimitive_1.isPrimitive)(obj)) { return; } const pathArray = typeof path === 'string' ? path.split('.') : path; let it = obj; for (let i = 0; i < pathArray.length; i++) { const key = pathArray[i]; if (isUnsafeKey(key)) { return; } if (i === pathArray.length - 1) { // If it's the last key in the path it[key] = value; } else { if (it[key] === undefined) { it[key] = {}; } it = it[key]; } } } exports.set = set; function isUnsafeKey(key) { return key === '__proto__' || key === 'constructor' || key === 'prototype'; } //# sourceMappingURL=set.js.map