0.5.0 • Published 9 years ago

json-balancer v0.5.0

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
9 years ago

json-balancer

Generates JSON object from balance configuration.

Example:

import {validate, generate, generateDefault} from 'json-balancer';

const config = {
  a: 123,
  b: 456,
  c: {
    balance: [
      {percent: 10, value: 'one value'},
      {percent: 70, value: 'another value', defaultValue: true},
      {percent: 20, value: 'and another'}
    ]
  },
  d: 789
};

validate(config);
// => true

generateDefault(config);
// => {
//      a: 123,
//      b: 456,
//      c: 'another value',
//      d: 789
//    }

generate(config);
// => {
//      a: 123,
//      b: 456,
//      c: random value chosen from the weighted options
//      d: 789
//    }