helper-methods
v0.0.6
Published
The collection of javascript methods to ease developers job.
Downloads
23
Maintainers
Readme
helper-methods
The collection of javascript methods to ease developers job.
:electric_plug: Installation
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');
Output
{ 1: { id: 1, value: 'USA' }, 91: { id: 91, value: 'India'}};
Using This Module
How to Use
var helperMethods = require('helper-methods');
IndexifyArray
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}}
Indexify
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'};
JsonToArray
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 }]
ObjectDifference
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};