Skip to content

Commit

Permalink
fix: 🐛 Includes array access notation in attributes rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed Mar 23, 2023
1 parent 8c0cb84 commit d7dbb59
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const renameWithAttributes = (str: string, append = '_attributes') => {
for(let i = parts.length - 2; i > 0; i--) {
if(parts[i].charAt(parts[i].length - 1) !== ']') {
parts[i] = `${parts[i]}${append}`
} else {
parts[i].replace('[', '_attributes[')
}
}

Expand Down Expand Up @@ -89,7 +91,7 @@ export const renameObjectWithAttributes = <T>(data: T, str = '_attributes') => {

const recursiveRename = (data: NestedObject, str) => {
Object.entries(data).forEach(([key, value]) => {
if(isPlainObject(value)) {
if(isPlainObject(value) || Array.isArray(value)) {
renameKey(data, key, `${key}${str}`)
// @ts-ignore - Can't figure out how to type arbitrarily deep nested objects
recursiveRename(value, str)
Expand Down

0 comments on commit d7dbb59

Please sign in to comment.