Skip to content

roganmelo/set-by-dot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

set-by-dot

🌳 Set a value to an object using dot path.

NPM version Build StatusCode Coverage 100%ISC LicenseNodeJS

API

import setByDot from 'set-by-dot';

setByDot({}, 'path', 'value');

Usage

  import setByDot from 'set-by-dot';

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

  setByDot(obj, 'a.b', 'a') // { a: { b: 'a' }, b: [{ c: 'a' }] }
  setByDot(obj, 'a', 'c');  // { a: 'c', b: [{ c: 'a' }] }
  setByDot(obj, 'a.b.c', 'b');  // { a: { b: 'a', c: 'b' }, b: [{ c: 'a' }] }
  setByDot(obj);  // { a: { b: 'a' }, b: [{ c: 'a' }] }

About

🌳 Set a value to an object using dot path.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published