object-property-assigner
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -22,4 +22,5 @@ "use strict"; | ||
var current = inputObj; | ||
var parent = []; | ||
var parent; | ||
var parentPart = ''; | ||
var topLevelArrayDeletion = false; | ||
// Drill down into object/array via the path sequence | ||
@@ -81,5 +82,9 @@ propertyPathArray.forEach(function (part, index) { | ||
if (remove) { | ||
var currentArray = parent[parentPart]; | ||
var newArray = __spreadArray(__spreadArray([], currentArray.slice(0, part), true), currentArray.slice(part + 1), true); | ||
parent[parentPart] = newArray; | ||
if (parent) { | ||
var currentArray = parent[parentPart]; | ||
var newArray = sliceArray(currentArray, part); | ||
parent[parentPart] = newArray; | ||
} | ||
else | ||
topLevelArrayDeletion = true; | ||
} | ||
@@ -99,3 +104,7 @@ else | ||
}); | ||
return inputObj; | ||
if (!topLevelArrayDeletion) | ||
return inputObj; | ||
// Deleting from a root-level array must be handled as a special case. | ||
var index = propertyPathArray[0]; | ||
return sliceArray(inputObj, index); | ||
}; | ||
@@ -133,2 +142,4 @@ // Splits a string representing a (nested) property/index on an Object or Array | ||
}; | ||
// Returns a copy of an array with a specific index removed. | ||
var sliceArray = function (input, index) { return __spreadArray(__spreadArray([], input.slice(0, index), true), input.slice(index + 1), true); }; | ||
exports.default = assignProperty; |
{ | ||
"name": "object-property-assigner", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A lightweight (no dependencies) tool to assign deeply nested properties in JS Objects (incl. Arrays)", | ||
@@ -5,0 +5,0 @@ "main": "build/assign.js", |
45733
159