Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Latest commit

 

History

History
54 lines (45 loc) · 1.17 KB

README.md

File metadata and controls

54 lines (45 loc) · 1.17 KB

objectio (object + io)

A JavaScript object getter and setter with string literals ⚡

NPM version NPM downloads Package License (MIT)

Usage

import { get, set } from 'objectio';

const obj = {
  a: 1,
  b: {
    c: [
      'd',
      {
        e: 'e',
      },
    ],
  },
};

// getter examples
console.log(get(obj, 'a')); // 1
console.log(get(obj, 'b.c[0]')); // 'd'
console.log(get(obj, 'b.c[1].e')); // 'e'

// setter examples
set(obj, 'a', 100);
console.log(get(obj, 'a')); // 100

set(obj, 'b.c[1]', 'E')
console.log(get(obj, 'b.c[1]')); // 'E'

console.log(obj);
// {
//   "a": 100,
//   "b": {
//     "c": [
//       "d",
//       "E"
//     ]
//   }
// }