npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@auturge/testing

v1.0.0

Published

auturge/testing - the testing library

Downloads

19

Readme

auturge/testing

License NPM Version Build Status Coverage Status

Installation

$ npm install @auturge/testing

AnyRandom

AnyRandom: Generate pseudo-random entities for testing purposes.

NOTE that some methods include one or more alias methods. These methods provide identical behavior, simply under a different method name.

Boolean

AnyRandom.boolean(): boolean;
AnyRandom.bool(): boolean;

Returns a random boolean (true or false).


Date

AnyRandom.date(): Date;

Returns a random date between 01-JAN-1970 and now.

AnyRandom.date(earliest: Date, latest: Date): Date;

Returns a random date within the range defined by the earliest and latest dates.


Sign

AnyRandom.sign(includeZero?: boolean = false): number;

Returns a random sign. When the optional parameter includeZero is false, or not provided, returns either -1 or 1. When includeZero is true, returns -1, 0, or 1.


8-bit Integer (byte)

AnyRandom.uint8(): number;
AnyRandom.byte(): number;

Returns a random unsigned 'byte' (8-bit integer) on the interval [0, 255].

AnyRandom.uint8(minValue: number, maxValue: number): number;
AnyRandom.byte(minValue: number, maxValue: number): number;

Returns a random unsigned byte within the range defined by minValue and maxValue. NOTE that minValue and maxValue must both be on the interval [0, 255].

AnyRandom.int8(): number;
AnyRandom.sbyte(): number;

Returns a random signed byte on the interval [-128, 127].

AnyRandom.int8(minValue: number, maxValue: number): number;
AnyRandom.sbyte(minValue: number, maxValue: number): number;

Returns a random signed byte within the range defined by minValue and maxValue. NOTE that minValue and maxValue must both be on the interval [-128, 127].


16-bit Integer

AnyRandom.uint16(): number;
AnyRandom.ushort(): number;

Returns a random unsigned 16-bit integer on the interval [0, 65535].

AnyRandom.uint16(minValue: number, maxValue: number): number;
AnyRandom.ushort(minValue: number, maxValue: number): number;

Returns a random unsigned 16-bit integer within the range defined by minValue and maxValue. NOTE that minValue and maxValue must both be on the interval [0, 65535].

AnyRandom.int16(): number;
AnyRandom.short(): number;

Returns a random signed 16-bit integer on the interval [–32768, 32767].

AnyRandom.uint16(minValue: number, maxValue: number): number;
AnyRandom.ushort(minValue: number, maxValue: number): number;

Returns a random signed 16-bit integer within the range defined by minValue and maxValue. NOTE that minValue and maxValue must both be on the interval [-32768, 32767].


32-bit Integer

AnyRandom.uint32(): number;
AnyRandom.uint(): number;

Returns a random unsigned 32-bit integer on the interval [0, 4294967295].

AnyRandom.uint32(minValue: number, maxValue: number): number;
AnyRandom.uint(minValue: number, maxValue: number): number;

Returns a random unsigned 32-bit integer within the range defined by minValue and maxValue. NOTE that minValue and maxValue must both be on the interval [0, 4294967295].

AnyRandom.int32(): number;
AnyRandom.int(): number;

Returns a random signed 32-bit integer on the interval [-2147483648, 2147483647].

AnyRandom.int32(minValue: number, maxValue: number): number;
AnyRandom.int(minValue: number, maxValue: number): number;

Returns a random signed 32-bit integer within the range defined by minValue and maxValue. NOTE that minValue and maxValue must both be on the interval [-2147483648, 2147483647].


64-bit Double-Precision Floating Point Number

AnyRandom.double(): number;
AnyRandom.number(): number;

Returns a random 64-bit double-precision floating-point number on the interval [0, 1). NOTE that this is the same behavior as Math.random().

AnyRandom.double(minValue: number, maxValue: number): number;
AnyRandom.number(minValue: number, maxValue: number): number;

Returns a random 64-bit double-precision floating-point number within the range defined by minValue and maxValue.


32-bit Single-Precision Floating Point Number

AnyRandom.float(): number;
AnyRandom.single(): number;

Returns a random 32-bit single-precision floating-point number on the interval (-infinity, infinity).

AnyRandom.float(minValue: number, maxValue: number): number;
AnyRandom.single(minValue: number, maxValue: number): number;

Returns a random 32-bit single-precision floating-point number within the range defined by minValue and maxValue.


Character Sets


Character

AnyRandom.char(): string;

Returns a single random character, taken from the ATOM character set.

AnyRandom.char(characterSet: string | CharacterSet): string;

Returns a single random character, taken from the given characterSet.


Character Array

AnyRandom.charArray(): string[];

Returns an array of characters, between 0 and 32 characters long, taken from the ATOM character set.

AnyRandom.charArray(minLength: number, maxLength: number): string[];

Returns an array of characters, between minLength and maxLength characters long, where the elements are taken from the ATOM character set.

AnyRandom.charArray(minLength: number, maxLength: number, characterSet: string | CharacterSet): string[];

Returns an array of characters, between minLength and maxLength characters long, where the elements are taken from the given characterSet.


String

AnyRandom.string(): string;

Returns a random string, between 0 and 32 characters long, where the characters are taken from the ATOM character set.

AnyRandom.string(minLength: number, maxLength: number): string;

Returns a random string, between minLength and maxLength characters long, where the characters are taken from the ATOM character set.

AnyRandom.string(minLength: number, maxLength: number, characterSet: string | CharacterSet): string;

Returns a random string, between minLength and maxLength characters long, where the characters are taken from the given characterSet.


UUID

AnyRandom.uuid(): string;

or

AnyRandom.guid(): string;

Returns a quasi-random (v4) UUID as a string.

WARNING: Randomness and/or uniqueness are not guaranteed!

DO NOT use this method to produce UUIDs in production code!


enum

AnyRandom.enum<T>(enumeration: T): T[keyof T];

Returns a randomly-chosen entry from the given enum.

WARNING: This only works for enums with keys of type string.


oneOf

AnyRandom.oneOf<T>(array: T[]): T;

Returns a randomly-chosen entry from the given array.


arrayOf

AnyRandom.arrayOf<T>(generator: () => T): T[];

Returns an array of between 5 any 10 elements, using the specified generator function.

AnyRandom.arrayOf<T>(generator: () => T, count: number): T[];

Returns an array of count elements, using the specified generator function.

AnyRandom.arrayOf<T>(generator: () => T, minCount: number, maxCount: number): T[];

Returns an array with a number of elements between minCount and maxCount, using the specified generator function.


URL

AnyRandom.url(): string;

Returns a quasi-random URL, with an empty path, no query, and no fragment(s).

AnyRandom.url(includePath: boolean, includeQuery: boolean, includeFragment: boolean): string;

Returns a quasi-random URL, including the specified parts.


License

Distributed under the MIT license. See LICENSE for more information.