Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eramux/rekey

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eramux/rekey

A simple and performant zero dependency library that allows you to modify your object structure using references.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-76.74%
Maintainers
1
Weekly downloads
 
Created
Source

Vue logo

Rekey

A simple and performant zero dependency library that allows you to modify your object structure using references.

Installation

npm i @eramux/rekey

Usage

First we will need to create an object which will be passed to the rekey funcitons

// Define a sample object
let data = {
  key1: "some string",
  settings: {
    name: "John",
    active: true
  },
  users: [
    {
      name: "Marie"
    },
    {
      name: "Steven",
      type: "Human"
    }
  ],
  items: [
    {
      name: "abs"
    },
    {
      name: "pvc",
      supported: false
    }
  ]
}
Rename key:
import { renameKey } from "@eramux/rekey"

// Rename the settings -> name key to 'username'
renameKey(data, "settings.name", "username")
// -> {
//      ...
//      settings: {
//        username: "John"
//        active: true
//      }
//      ...
//    }

// It will automatically rename keys in object arrays
renameKey(data, "items.name", "material")
// -> {
//      ...
//      items: [
//        {
//          material: "abs"
//        }
//        ...
//     ]
//     ...
//    }

// It only changes keys that exist
renameKey(data, "users.type", "species")
// -> {
//      ...
//      users: [
//        {
//          name: "Marie"
//        },
//        {
//          name: "Steven",
//          species: "Human"
//        }
//     ]
//     ...
//    }
Rename key:
// Delete a key nested deeply inside of the object or arrays
deleteKey(data, "users.name")
// -> {
//      ...
//      users: [
//        {},
//        {
//          species: "Human"
//        }
//     ]
//     ...
//    }

Since rekey does not copy the object, you won't have any unexpected memory spikes. It works by only modifying the reference recursively.

Contributions

Any contributions are welcome! Please make sure to first file an issue so we can discuss the problem at hand and you don't create a PR that doesn't get pulled.

Keywords

FAQs

Package last updated on 26 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc