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 library to rename object keys

  • 0.0.13
  • Source
  • npm
  • Socket score

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

rekey

This library enables you to quickly and efficiently modify object keys.

Installation

npm i @eramux/rekey

Usage


import { renameKey, deleteKey } from "@eramux/rekey"

# Define a sample object
let data = {
  key1: "some string",
  settings: {
    name: "John",
    active: true
  },
  items: [
    {
      name: "abs"
    },
    {
      name: "pvc",
      supported: false
    }
  ]
}

/**
 * Using renameKey
 */

# This will result in the settings -> name key being renamed into 'username'
renameKey(data, "settings.name", "username")

# rekey will automatically rename keys in object arrays
renameKey(data, "items.name", "material")

# It takes care to only change keys that exist
renameKey(data, "items.supported", "usable")

/**
 * Using deleteKey
 */

# This will delete the key defined by the selector
deleteKey(data, "settings.name")

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

Keywords

FAQs

Package last updated on 25 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