@eramux/rekey
Advanced tools
Comparing version 0.0.16 to 0.0.17
{ | ||
"name": "@eramux/rekey", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "A simple and performant library to rename object keys", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,8 +0,10 @@ | ||
# rekey | ||
This library enables you to quickly and efficiently modify object keys. | ||
<p align="center"><img width="100" src="https://raw.githubusercontent.com/eramux/rekey/master/resources/logo.png" alt="Vue logo"></p> | ||
<h1 align="center">Rekey</h1> | ||
A simple and performant zero dependency library that allows you to modify your object structure using references. | ||
## Installation | ||
``` | ||
``` shell | ||
npm i @eramux/rekey | ||
@@ -13,7 +15,6 @@ ``` | ||
``` | ||
First we will need to create an object which will be passed to the rekey funcitons | ||
import { renameKey, deleteKey } from "@eramux/rekey" | ||
# Define a sample object | ||
``` ts | ||
// Define a sample object | ||
let data = { | ||
@@ -25,2 +26,11 @@ key1: "some string", | ||
}, | ||
users: [ | ||
{ | ||
name: "Marie" | ||
}, | ||
{ | ||
name: "Steven", | ||
type: "Human" | ||
} | ||
], | ||
items: [ | ||
@@ -36,25 +46,69 @@ { | ||
} | ||
``` | ||
#### Rename key: | ||
``` ts | ||
import { renameKey } from "@eramux/rekey" | ||
/** | ||
* Using renameKey | ||
*/ | ||
# This will result in the settings -> name key being renamed into 'username' | ||
// Rename the settings -> name key to 'username' | ||
renameKey(data, "settings.name", "username") | ||
// -> { | ||
// ... | ||
// settings: { | ||
// username: "John" | ||
// active: true | ||
// } | ||
// ... | ||
// } | ||
# rekey will automatically rename keys in object arrays | ||
// It will automatically rename keys in object arrays | ||
renameKey(data, "items.name", "material") | ||
// -> { | ||
// ... | ||
// items: [ | ||
// { | ||
// material: "abs" | ||
// } | ||
// ... | ||
// ] | ||
// ... | ||
// } | ||
# It takes care to only change keys that exist | ||
renameKey(data, "items.supported", "usable") | ||
// It only changes keys that exist | ||
renameKey(data, "users.type", "species") | ||
// -> { | ||
// ... | ||
// users: [ | ||
// { | ||
// name: "Marie" | ||
// }, | ||
// { | ||
// name: "Steven", | ||
// species: "Human" | ||
// } | ||
// ] | ||
// ... | ||
// } | ||
``` | ||
#### Rename key: | ||
``` ts | ||
// Delete a key nested deeply inside of the object or arrays | ||
deleteKey(data, "users.name") | ||
// -> { | ||
// ... | ||
// users: [ | ||
// {}, | ||
// { | ||
// species: "Human" | ||
// } | ||
// ] | ||
// ... | ||
// } | ||
``` | ||
/** | ||
* 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.__ | ||
``` | ||
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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10668
11
112