Handle repeating elements w explicitArray=false
This commit is contained in:
@@ -214,15 +214,19 @@ function registerEvents() {
|
||||
const tokens = path.split('.')
|
||||
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
if (tempObj[tokens[i]] && !(explicitArray === false && i === tokens.length - 1)) {
|
||||
tempObj = tempObj[tokens[i]]
|
||||
const token = tokens[i]
|
||||
const isLastToken = i === tokens.length - 1
|
||||
const doesTokenExist = token in tempObj
|
||||
|
||||
if (!doesTokenExist) {
|
||||
tempObj[token] = explicitArray ? [] : obj
|
||||
} else {
|
||||
// if explicitArray is true then create each node as array
|
||||
// irrespective of how many nodes are there with same name.
|
||||
tempObj[tokens[i]] = explicitArray ? [] : obj
|
||||
tempObj = tempObj[tokens[i]]
|
||||
if (!Array.isArray(tempObj[token]) && isLastToken) tempObj[token] = [tempObj[token]]
|
||||
}
|
||||
if (Array.isArray(tempObj) && i !== tokens.length - 1) {
|
||||
|
||||
tempObj = tempObj[token]
|
||||
|
||||
if (Array.isArray(tempObj) && !isLastToken) {
|
||||
tempObj = tempObj[tempObj.length - 1]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user