moderndash
Advanced tools
Comparing version 0.12.0 to 0.12.1
@@ -656,4 +656,2 @@ /** | ||
* | ||
* TODO: Add support for array paths. | ||
* | ||
* @alpha | ||
@@ -660,0 +658,0 @@ * @example |
@@ -368,12 +368,15 @@ // src/array/chunk.ts | ||
function set(obj, path, value) { | ||
const pathParts = path.split("."); | ||
const lastPathPart = pathParts.pop(); | ||
const pathParts = path.split(/[.[\]]/g).filter((x) => Boolean(x.trim())); | ||
let currentObj = obj; | ||
for (const pathPart of pathParts) { | ||
if (!isPlainObject(currentObj[pathPart])) { | ||
currentObj[pathPart] = {}; | ||
for (let index = 0; index < pathParts.length; index++) { | ||
const key = pathParts[index]; | ||
if (index === pathParts.length - 1) { | ||
currentObj[key] = value; | ||
break; | ||
} | ||
currentObj = currentObj[pathPart]; | ||
const nextIsNumber = !Number.isNaN(Number.parseInt(pathParts[index + 1])); | ||
if (currentObj[key] === void 0) | ||
currentObj[key] = nextIsNumber ? [] : {}; | ||
currentObj = currentObj[key]; | ||
} | ||
currentObj[lastPathPart] = value; | ||
return obj; | ||
@@ -380,0 +383,0 @@ } |
@@ -54,3 +54,3 @@ { | ||
}, | ||
"version": "0.12.0" | ||
"version": "0.12.1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
212141
2400