UNPKG

cooky-cutter

Version:

Object factories for testing in TypeScript

25 lines (24 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MIN_RANDOM_VALUE = exports.MAX_RANDOM_VALUE = exports.sequence = exports.random = void 0; // NOTE: using the 32-bit max integer instead of `Number.MAX_VALUE` to enable // readability and avoid exponentials. eg: `1.4991242955357377e+308` // TODO: consider exposing these as config options. const MAX_RANDOM_VALUE = 2147483647; exports.MAX_RANDOM_VALUE = MAX_RANDOM_VALUE; const MIN_RANDOM_VALUE = 1; exports.MIN_RANDOM_VALUE = MIN_RANDOM_VALUE; /** * Assign a random number to the attribute. This is useful for attributes like * seeds or ids (to avoid tests passing as a result of ordering) */ const random = () => Math.floor(Math.random() * MAX_RANDOM_VALUE) + MIN_RANDOM_VALUE; exports.random = random; /** * Increment the attribute each time the factory is invoked. This is useful * for counts (`random` may be a better option for `ids`). * * @param invocation */ const sequence = (invocation) => invocation; exports.sequence = sequence;