1.0.5 • Published 3 years ago

replace-keys v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Idea

Helps to replace keys of objects in an array of objects

Installation

npm i replace-keys

Example

Sometimes when we fetch data from an API we get sort of strange keys which doesn't look nice when we access those keys while iterating over an array of objects.

First argument of the function takes an object where the keys are those which should be replaced by new keys and the values are new keys.

Second argument takes an array of objects on which the operation should be done.

import { replaceKeys } from "replace-keys";

const data = [
  { "1. OOP": true, "2. Backend": "cool" },
  { "1. OOP": "interesting", "2. Backend": "one love" },
  { "1. OOP": "best paradigm", "2. Backend": "fascinating" },
];

const replace = replaceKeys({ "1. OOP": "FP", "2. Backend": "frontend" }, data);

const result = [
  { FP: true, frontend: "cool" },
  { FP: "interesting", frontend: "one love" },
  { FP: "best paradigm", frontend: "fascinating" },
];
1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago