as-services/libs/utils/object/deep-map-keys.js
devthejo 16b7e7d6aa
All checks were successful
/ build (map[dockerfile:./services/hasura/Dockerfile name:hasura]) (push) Successful in 47s
/ build (map[dockerfile:./services/web/Dockerfile name:web]) (push) Successful in 1m47s
/ build (map[dockerfile:./services/watchers/Dockerfile name:watchers]) (push) Successful in 2m37s
/ build (map[dockerfile:./services/files/Dockerfile name:files]) (push) Successful in 2m52s
/ build (map[dockerfile:./services/api/Dockerfile name:api]) (push) Successful in 3m2s
/ build (map[dockerfile:./services/app/Dockerfile name:app]) (push) Successful in 31s
/ build (map[dockerfile:./services/tasks/Dockerfile name:tasks]) (push) Successful in 2m44s
/ deploy (push) Successful in 48s
chore(init): available sources
2025-04-13 10:46:53 +02:00

20 lines
615 B
JavaScript

module.exports = function deepMapKeys(originalObject, callback) {
if (typeof originalObject !== "object" || originalObject === null) {
return originalObject
}
return Object.keys(originalObject || {}).reduce((newObject, key) => {
const newKey = callback(key)
const originalValue = originalObject[key]
let newValue = originalValue
if (Array.isArray(originalValue)) {
newValue = originalValue.map((item) => deepMapKeys(item, callback))
} else {
newValue = deepMapKeys(originalValue, callback)
}
return {
...newObject,
[newKey]: newValue,
}
}, {})
}