2.0.5 • Published 8 years ago

swap-keys-in-object v2.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

Swap keys in an object!

Usage

First install it:

npm install --save

Then use it:

const swapKeysInObject = require('swap-keys-in-object')

Say you have an object like this:

const oldFellow = {
    id: 'PloppyNop39',
    name: 'Crumbface',
    age: 137
}

But you want the keys to be preceded by underscores. Create a map from your old keys onto your new keys:

const keyMap = {
    id: '_id',
    name: '_name',
    age: '_age'
}

Then you can swap out the old keys for new:

const newFellow = swapKeysInObject(keyMap, oldFellow)

The resulting newFellow:

{
    _id: 'PloppyNop39',
    _name: 'Crumbface',
    _age: 137
}
2.0.5

8 years ago

2.0.3

8 years ago

2.0.1

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago