The collection of javascript methods to ease developers job
The collection of javascript methods to ease developers job.
npm install helper-methods -S/-D
## Usage
var helperMethods = require('helper-methods');
var indexifiesObject = helperMethods.indexifyArray([{ id: 91, value: 'India' }, { id: 1, value: 'USA' }],'id');
{ 1: { id: 1, value: 'USA' }, 91: { id: 91, value: 'India'}};
var helperMethods = require('helper-methods');
This method indexify the array of JSON object by the attribute of JSON object and return unique result.
var data = [{
'id': 1,
'user': 'barney',
'active': false
}, {
'id': 2,
'user': 'fred',
'active': false
}];
helperMehtods.indexifyArray(data,'id');
//result
==> {1:{'id':1,'user':'barney','active':false},2:{'id':2,'user':'fred','active':false}}
This method indexify the array of json object based upon the request attributes of json object.
var data = var data = [{
'id': 1,
'user': 'barney',
'active': false
}, {
'id': 2,
'user': 'fred',
'active': false
}];
helperMehtods.indexify(data,'id','user');
//result
==> {1:'barney',2:'fred'};
This method convert json object to array
var data = {
'id': 1,
'user': 'barney',
'active': false
};
helperMethods.jsonToArray(data);
//result
// [{ 'id': 1},{ 'user': 'barney' },{ 'active': false }]
var object1 = { 'user': 'barney', 'age': 36, 'active': true },
object2 = { 'user': 'Prateek', 'age': 50, 'active': false };
helperMethods.objectDifference(object1,object2);
//result
//=> object of barney
var object1 = { 'user': 'barney', 'age': 36, 'active': true },
object2 = { 'user': 'Prateek', 'age': 50, 'active': false }
helperMethods.objectDifference(object1,object2,['age']);
//result
//=> object of Prateek with only age {age:50};
var object1 = { 'user': 'barney', 'age': 36, 'active': true },
object2 = { 'user': 'Prateek', 'age': 50, 'active': false }
helperMethods.objectDifference(object1,object2,['user','age']);
//result
//=> object of barney {user:'barney',age:36};