1.0.10 • Published 2 years ago

config-randomizer v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

config-randomizer

Config randomizer used to generate configuration from a set of input parameters.

Recurses through your input configuration object, and checks for two scenarios:

  1. If the sub-object matches RandomizableCount interface, it calculates a concrete length based off of the count, and fills the array with mimics of the itemDetails interface.
  2. If the sub-object matches RandomizableRange interface, it calculates a concrete value within the minValIncl and maxValIncl range according to the weight function.

    • The potential values to chose from are found by starting at the minValIncl, and stepping by the stepper amount until the maxValIncl is reached

    Note: if the maxValIncl is not an even amount of steps from the minValIncl (NOT recommended), the last value before going over the max value, as well as the max value, will both be included. For example:

    1->5 by 1.5 = 1, 2.5, 4, 5

Note: As you will see in the example, these two interfaces can be used together. You can leverage a RandomizableCount whose itemDetails contains a RandomizableRange.

Example Usage

The following input configuration

{
    a: {
        b: {
            minValIncl: 1,
            maxValIncl: 4,
            weightFnKey: "EVEN",
            stepper: 1
        },
        c: {
            d: {
                minValIncl: 0.1,
                maxValIncl: 0.5,
                stepper: 0.1,
                weightFnKey: "EVEN"
            }
        },
        e: {
            count: {
                minValIncl: 1,
                maxValIncl: 4,
                stepper: 1,
                weightFnKey: "EVEN"
            },
            itemDetails: {
                e_1: "hello",
                e_2: {
                    minValIncl: 0.6,
                    maxValIncl: 0.9,
                    stepper: 0.1,
                    weightFnKey: "EVEN"
                }
            }
        }
    }
}

Could produce the following when run through deRandomize.

{
    a: {
        b: 2
        c: {
            d: 0.1
        },
        e: [{
            e_1: "hello",
            e_2: 0.7
        }, {
            e_1: "hello",
            e_2: 0.6
        }]
    }
}

Supported Weight Functions

  1. EVEN
    • Gives every step value an even weight, so each value is equally likely.
1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago