Wondering what’s next for npm?Check out our public roadmap! »

    rename-prop

    1.0.0 • Public • Published

    rename-prop Build Status

    Rename a property from an object

    Install

    $ npm install --save rename-prop
    

    Usage

    const renameProp = require('rename-prop');
     
    const obj = {foo: {bar: 'baz'}};
    renameProp(obj, 'foo', 'unicorn');
    console.log(obj);
    //=> {unicorn: {bar: 'baz'}}
     
    const obj = {foo: {bar: 'baz'}};
    renameProp(obj, 'foo.bar', 'foo.unicorn');
    console.log(obj);
    //=> {foo: {unicorn: 'baz'}}

    API

    renameProp(input, from, to)

    input

    Type: object

    Object to rename the property.

    from

    Type: string

    Path of the property in the object to rename, using . to separate each nested key.

    to

    Type: string

    Path of the property in the object to rename from to, using . to separate each nested key.

    Related

    • dot-prop - Get, set, or delete a property from a nested object using a dot path

    License

    MIT © Sam Verschueren

    Install

    npm i rename-prop

    DownloadsWeekly Downloads

    90

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • avatar