@sbspk/object-path

Read and Manipulate Objects with Key Path

Usage no npm install needed!

<script type="module">
  import sbspkObjectPath from 'https://cdn.skypack.dev/@sbspk/object-path';
</script>

README

Installation

npm install --save @sbspk/object-path

Usage

const op = require('@sbspk/object-path');

const data = {
  inner: {
    a: 'b'
  }
}

op.get(data, 'inner.a'); // returns b
op.set(data, 'inner.a', 'c'); // sets the value to c
op.unset(data, 'inner.a') // removes a and inner because inner becomes empty after deleting a
op.set(data, 'hello.world', { greeting: 'Namaste' }); // sets data.hello.world.greeting
op.get(data, 'hello.world.greeting'); // returns 'Namaste'