sadgod
Version:
SadGod helps you extract data from ROTMG's internal SWF files. Currently it allows you to read the names and values of all binary packet ids used in the network communication. This is helpful because the game often changes the packet ids.
15 lines (13 loc) • 739 B
JavaScript
function renameProperties(object, propertyMap) {
if (typeof object != 'object' || object === null) throw new Error("Must supply an object to rename it's properties")
if (typeof propertyMap != 'object' || propertyMap === null) throw new Error("Property map must be an object")
if (Object.values(propertyMap).some(value => typeof value != 'string')) throw new Error("All property map values must be strings")
const output = {...object}
Object.entries(propertyMap).forEach(([oldPropertyName, newPropertyName]) => {
if (!output.hasOwnProperty(oldPropertyName)) return
delete output[oldPropertyName]
output[newPropertyName] = object[oldPropertyName]
})
return output
}
module.exports = renameProperties