Coder Social home page Coder Social logo

xogroup / hashprimer Goto Github PK

View Code? Open in Web Editor NEW
4.0 6.0 0.0 6 KB

Simple and effective way to assign values to a javascript object from an array of ordered keys with builtin callbacks available for upserting arrays and incrementing counters

JavaScript 100.00%

hashprimer's Introduction

hashprimer

A javascript library for creating or updating javscript objects {} from an Array of key values.

A few builtin callbacks are available with this release:

hashprimer.increment : increment numerical value
hashprimer.array : create/append value to array

Usage Example

var hashprimer = require('hashprimer');
var hash = new hashprimer();

var OS = {};
hash.set(OS, 0.155, [ "AWS", "us-east-1a", "c4.xlarge", "cost" ]);
hash.set(OS, null, [ "AWS", "us-east-1a", "c4.xlarge", "count" ], hash.increment);
hash.set(OS, 10, [ "AWS", "us-east-1a", "c4.xlarge", "count" ], hash.increment);
hash.set(OS, 'i-a1b2b3c4', [ "AWS", "us-east-1a", "c4.xlarge", "instances" ], hash.array);
hash.set(OS, 'i-a4b3b2c1', [ "AWS", "us-east-1a", "c4.xlarge", "instances" ], hash.array);
hash.set(OS, null, [ "AWS", "us-east-1a", "c4.xlarge", "monthly_charge" ], function(hash, value) {
  return (OS.AWS['us-east-1a']['c4.xlarge'].cost * OS.AWS['us-east-1a']['c4.xlarge'].count * 24 * 30);
});

console.log(JSON.stringify(OS));

Example Output

{
    "AWS": {
        "us-east-1a": {
            "c4.xlarge": {
                "cost": 0.155,
                "count": 11,
                "instances": [
                    "i-a1b2b3c4",
                    "i-a4b3b2c1"
                ],
                "monthly_charge": 1227.6000000000001
            }
        }
    }
}

Version

1.0.5

Installation

$ npm install hashprimer --save

Contributions Welcome

Please see general info on contributions and conduct etc.

hashprimer's People

Contributors

georgetaveras1231 avatar rprashad avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hashprimer's Issues

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.