GithubHelp home page GithubHelp logo

prateekpronoc / helper-methods Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 29 KB

The collection of javascript methods to ease developers job

Home Page: https://prateekpronoc.github.io/helper-methods/

License: MIT License

JavaScript 100.00%
lodash javascript json-data array-manipulations

helper-methods's Introduction

helper-methods

Coverage Status Build Status

The collection of javascript methods to ease developers job.

🔌 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};

helper-methods's People

Contributors

prateekpronoc avatar

Stargazers

 avatar

Watchers

 avatar  avatar

helper-methods's Issues

Method to Camelize Object

Method to camelize JSON object.

Input

var object = {id:1,client_id:1,client_name:'Barney',created_by:'David'};

Output

//result ==> {id:1,clientId:1, clientName:'Barney',createdBy:'David'}

This method removes the underscores from attributes of the inputted Object.

Note -: This method can be used while converting database object to business object

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.