0.0.7 • Published 3 years ago

@snaplib/arbob v0.0.7

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

Arbob

Pseudo randomly generate arbitrary values and objects that can be used for stuff (like mocks for testing).

version license node version github workflow status

ArbInt class

The ArbInt class generates pseudo random integers between negative Number.MAX_VALUE and positive Number.MAX_VALUE. It's possible to make the generated integer value bounded to a specific range by setting either it's min and/or max range and whether these ranges are inclusive or exclusive. These properties can be set via it's constructor arguments:

  1. min

    The min property is an integer used to set the minimum range of the generated integer. This dictates the smallest value the generated integer can either be if it's an inclusive range or must be greater than if it's exclusive.

  2. max

    The max property is an integer used to set the maximum range of the generated integer. This dictates the largest value the generated integer can either be if it's an inclusive range or must be less than if it's exclusive.

  3. inclusive

    The inclusive property is a boolean indicating whether the min and max ranges are inclusive or not.

    If inclusive is set to true, then the ranges are inclusive and it's possible for the generated integer to equal the min and/or max range values.

    If inclusive is set to false, then the ranges are exclusive and the generated integer will be greater than the min range and less than the max range.

import {ArbInt} from "@snaplib/arbob";

// Create ArbInt object with specified inclusive bounds
const inclusiveRangeIntGenerator =
    new ArbInt({min: -Number.MAX_VALUE, max: Number.MAX_VALUE})

/*
 * Will print an integer that is INCLUSIVELY between -1.7976931348623157e+308
 * and 1.7976931348623157e+308. It's possible for the integer to be
 * +/- 1.7976931348623157e+308 or any value in between.
 */
console.log(inclusiveRangeIntGenerator.generate());

// Create ArbInt object with specified exclusive (non-inclusive) bounds
const exclusiveRangeIntGenerator =
    new ArbInt({min: 42, max: 165, inclusive: false})

/*
 * Will print an integer that is EXCLUSIVELY between 42 and 165. It's possible
 * for the integer to be any value in between 42 and 165, but not 42 or 165
 * itself.
 */
console.log(exclusiveRangeIntGenerator.generate());

More in-depth info can be found in the ArbInt Module docs.

ArbChar class

The ArbChar class generates pseudo random characters (strings consisting of a single character). It focus primarily on organizing more common ASCII characters into various groups by properties they share to dictate how to constrain the types of characters to generate. For instance there's a method for generating vowel characters and another one for generating upper case characters. This class consists exclusively of static methods that generates specific types of characters:

import {ArbChar} from "@snaplib/arbob"

// Will print a character with a code point value equal to or greater than 0 and
// less than or equal to 1,114,111:
console.log(ArbChar.generate());

// Will print an alpha character. An alpha character is an upper or lower case
// character that is in the English alphabet ('A' to 'Z' or 'a' to 'z'):
console.log(ArbChar.alpha());

// Will print a digit character. A digit character is an integer in the range of
// 0 to 9:
console.log(ArbChar.digit());

// Will print an alpha numeric character. An alpha-numeric character can be a
// digit character or alpha character:
console.log(ArbChar.alphaNum());

// Will print a vowel character. That is any of the following characters:
// A, E, I, O, U, a, e, i, o, u:
console.log(ArbChar.vowel());

// Will print a consonant character. That is any upper or lower case letter that
// is not a vowel:
console.log(ArbChar.consonant());

// Will print an upper case alpha character:
console.log(ArbChar.upperCase());

// Will print an upper case alpha vowel character:
console.log(ArbChar.upperCaseVowel());

// Will print an upper case alpha consonant character:
console.log(ArbChar.upperCaseConsonant());

// Will print a lower case alpha character:
console.log(ArbChar.lowerCase());

// Will print a lower case alpha vowel character:
console.log(ArbChar.lowerCaseVowel());

// Will print a lower case alpha consonant character:
console.log(ArbChar.lowerCaseConsonant());

// The following isn't possible, as it has no public constructor:
const arbCharGeneratorObject = new ArbChar();

More in-depth info can be found in the ArbChar Module docs.

0.0.5

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago