0.1.25 • Published 2 years ago

json-object-keys v0.1.25

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

json-object-keys

json-object-keys | ⚠️ WIP ⚠️

Manage complex object keys in depth.

Table of contents

Install

npm install json-object-keys

Remove

Remove an unique key

import { remove } from 'json-object-keys'

remove(
  {
    id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
    name: 'John Doe',
    category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
    email: 'john@doe.com',
    age: 29,
    ...
  },
  'category'
)

Output

+{
+  id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+  name: 'John Doe',
-  category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+  email: 'john@doe.com',
+  age: 29
+}

Remove multiple keys

import { remove } from 'json-object-keys'

remove(
  {
    id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
    name: 'John Doe',
    category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
    email: 'john@doe.com',
    age: 29
  },
  ['category', 'email']
)

Output

+{
+  id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+  name: 'John Doe',
-  category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-  email: 'john@doe.com',
+  age: 29
+}

Replace

Replace an unique key

import { replace } from 'json-object-keys'

replace({ id: 1, foo: 2, baz: 3 }, { foo: 'bar' })

Output

{
  id: 1,
+ bar: 2,
  baz: 3
}

Replace multiple keys

import { replace } from 'json-object-keys'

replace(
  {
    uuid: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
    name: 'Grandchild 1',
    children: [
      {
        uuid: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
        name: 'Great Grandchild 1'
      },
      {
        uuid: 'c579a0b8-c2c7-44e2-a7d9-2edba8f7b472',
        name: 'Great Grandchild 2'
      }
    ]
  }, { uuid: 'id', children: 'node' })

Output

 {
+   id: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
    name: 'Grandchild 1',
+   node: [
      {
+       id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
        name: 'Great Grandchild 1'
      },
      {
+       id: 'c579a0b8-c2c7-44e2-a7d9-2edba8f7b472',
        name: 'Great Grandchild 2'
      }
    ]
  }

License

This project is licensed under the MIT License.

0.1.20

2 years ago

0.1.21

2 years ago

0.1.23

2 years ago

0.1.25

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.13

2 years ago

0.1.19

2 years ago

0.1.5

2 years ago

0.1.2-dev

2 years ago

0.1.1-dev

2 years ago

0.1.0-dev

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago