(path, _object)
| 30 | * @param {{}} _object - object with key and value |
| 31 | */ |
| 32 | export function removeKeyFromObject(path, _object) { |
| 33 | const keys = path.split('.') |
| 34 | const lastKey = keys.pop() |
| 35 | |
| 36 | // Traverse the state and find the nested object up to the second last key |
| 37 | let newAttrs = { ..._object } |
| 38 | let nestedObject = newAttrs |
| 39 | |
| 40 | for (const key of keys) { |
| 41 | if (nestedObject[key] !== undefined) { |
| 42 | nestedObject[key] = { ...nestedObject[key] } // Ensure immutability |
| 43 | nestedObject = nestedObject[key] |
| 44 | } else { |
| 45 | return // Key doesn't exist, so nothing to remove |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Remove the attribute |
| 50 | delete nestedObject[lastKey] |
| 51 | |
| 52 | return newAttrs |
| 53 | } |
| 54 | |
| 55 | |
| 56 | export function isNumeric(str) { |
no outgoing calls
no test coverage detected