2.0.0 • Published 5 years ago

random-test-values v2.0.0

Weekly downloads
134
License
ISC
Repository
github
Last release
5 years ago

Random Test Values

Build Status

Installing

npm install random-test-values --save

Using the Library

import { Random } from 'random-test-values';

var someNumber: number = Random.Number();
var someString: string = Random.String();
var someBool: boolean = Random.Boolean();
var someObject: SomeType = Random.Object(SomeType);

Method Breakdown

String

By default the only characters in a generated string are alphanumeric characters of any case.

// Generate a random String
Random.String();

// Specify a min/max length for the string
Random.String({minLength: 5, maxLength: 50});

// Specify characters that are allowed in generated string
Random.String({whiteListString: "1234567890"}); // Would only generate numbers

// Specify characters to exclude in generated string
Random.String({blackListString: "1234567890"}); // Would only generate alpha strings

RegexString

Uses the library https://github.com/fent/randexp.js? to generate strings that match a pattern

Random.RegexString(/hello World/); // Would generate "hello World"
Random.RegexString(/hello World!*/, {minRepetition: 500}); // Would Generate "hello World" with 500+ "!"

Number

Generates an integer

Random.Number(); // Creates a random integer
Random.Number({min: 5, max: 20}); // Generates a number between 5 and 20

DecimalNumber

Like Number but generates a decimal n umber

Random.DecimalNumber(); // Creates a random decimal number
Random.DecimalNumber({min: 5, max: 20, maxDecimalPlaces: 2}); // Creates a random decimal number between 5 and 20, rounding to 2 decimal places.

Boolean

Creates a random boolean, not the best for testing though.

Random.Boolean(); // Creates a boolean, either true or false.

Date

Creates a random valid date.

Random.Date(); // Creates a Date
Random.Date({after: new Date(), before: new Date()}); // Creates a date between the after and before dates

Array

Creates a random array of specified length and type

Random.Array(TestObject, 3); // Creates an array of TestObject of length 3
Random.Array(String, 5); // Creates an array of Strings of length 5

Object

Creates a random object of a given type

NOTE: Object properties must be initilized in the constructor of the class, otherwise they will not be randomly assigned in Random.Object!

Random.Object(TestObject); // Creates a random TestObject
2.0.0

5 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago