Skip to content

mohithg/js-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Deep Utility Functions

recursiveOmit (deepObject)

Recursively omits the null, '', undefined values from the object. Checks all levels deep to remove the keys associated.

let deepObject = {
  x: {
    y: {
      z: ''  
    }
    a: {
      b: null,
      c: undefined
    }
    d: null
  }
};
recursiveOmit(deepObject) // returns {}

deepExtend (object1, object2)

Deeply extend object1 with object2 where object1 will be target and object2 will be source.

let object1 = {
  x: {
    y: {
      z: ''  
    }
    a: {
      b: null,
      c: undefined
    }
  }
};

let object 2 = {
  x: {
    y: {
      z: 'z',
    }
    a: {
      b: 'b',
      c: 'c'
    }
    d: 'd'
  }
};

deepExtend(object1, object2)
/* returns {
  x: {
    y: {
      z: 'z',
    }
    a: {
      b: 'b',
      c: 'c'
    }
    d: 'd'
  }
}; */

diffObject(object1, object2)

Compares object1 with object2 and returns the different key value pairs.

eg: let object1 = {
  x: 'a',
  y: 'b'
};

let object 2 = {
  x: 'a',
  z: 'c',
};

diffObject(object1, object2) 
/* returns {
  y: 'b',
  z: 'c'
}; */

Resources

About

JavaScript Utility Functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published