Providing you with all sorts of Good Eggs-style fake data!
All exported functions are stateless (meaning you don't have to worry about binding to this
).
Use fake-eggs
to generate random and realistic "Good Eggs"-style data. This module can be used for test data, local development, and beyond!
Note: when generating json schemas or mongoose schemas Unionized should be used as fake-eggs
does not support factory-style composition for test data objects.
If fake-eggs
doesn't support the random data you're trying to generate consider opening an issue to track it - or open a PR to contribute!
import fake from 'fake-eggs';
fake.boolean(); // => true
fake.sample(['a', 'b', 'c']); // => 'b
fake.uri(); // => 'https://7wr6_.goodeggs.com/k/ok
fake.employee.email(); // => '[email protected]
() => string
Generates a random street address string (e.g., 5447 Bazpe Lane
).
Recommended to use its fake.location.address
counterpart.
<T>(lengthLowerInclusive: number, lengthUpperExclusive: number, generator: () => T) => T[]
Calls supplied generator
function to return an array of length lengthLowerInclusive
and lengthUpperInclusive
.
() => boolean
Returns true
or false
, chosen at random.
Exposes the underlying Chance.js client.
() => string
Returns a randomly-selected first name, e.g. Carter
.
() => string
Generates a random last name, e.g., Armstrong
.
() => string
Generates a random phone number, e.g. +15556797779
.
(firstName?: string, lastName?: string) => string
Randomly generates a full name, e.g., Randall Munroe
. firstName
and lastName
can optionally be overridden.
(options?: {domain?: string, username?: string}) => string
Returns a randomly-selected email address string (e.g., [email protected]
).
You can override either portion of the email with username
and domain
options.
(from?: (Date | string), to?: (Date | string)) => Date
Returns a randomly-selected Date
, optionally between from
and to
.
(from?: (Date | string), to?: (Date | string)) => string
Returns a randomly-selected day string (YYYY-MM-DD
), optionally between from
and to
.
() => number
Returns a randomly-selected digit (integer between 0 and 9).
(options?: {domain?: string, username?: string}) => string
Returns a randomly-selected email address string (e.g., [email protected]
).
You can override either portion of the email with username
and domain
options.
() => string
Returns a randomly-selected first name, e.g. Carter
.
() => string
Generates a random last name, e.g., Armstrong
.
() => string
Generates a random phone number, e.g. +15556797779
.
(firstName?: string, lastName?: string) => string
Randomly generates a full name, e.g., Randall Munroe
. firstName
and lastName
can optionally be overridden.
(options?: {firstName?: string, lastName?: string}) => string
Returns a randomly-selected email address at goodeggs.com of the form [email protected]
.
You can override firstName
and lastName
by providing appropriate options.
() => string
Returns a randomly-selected first name, e.g. Carter
.
() => string
Returns a randomly-selected foodhub slug, e.g. sfbay
.
(firstName?: string, lastName?: string) => string
Randomly generates a full name, e.g., Randall Munroe
. firstName
and lastName
can optionally be overridden.
(lowerInclusive?: number, upperExclusive?: number) => number
Generates a random integer (could be negative!). Optionally between lowerExclusive
and upperExclusive
.
() => string
Generates a random last name, e.g., Armstrong
.
() => string
Generates a random street address string (e.g., 5447 Bazpe Lane
).
() => string
Generates a random two letter state code, e.g., CA
.
Generate a random zip code (e.g. 55416) with the option of specifying a ZIP+4 format (e.g. 12201-7050)
(options?: {plusfour?: boolean}) => string
<T>(returnValue: () => T) => ?T
Potentially returns null
, undefined
, or the result of the supplied returnValue
function.
Useful for maybe types in Flow, e.g.:
{
maybeValue: ?boolean,
}
<T>(returnValue: () => T) => (T | null)
(lowerInclusive?: number, upperExclusive?: number, fixed?: number) => number
Generates a random number
, optionally between lowerInclusive
and upperExclusive
with a fixed
number of digits after the decimal.
({+counter?: number, +from?: (string | Date), +machineId?: number, +processId?: number, +timestamp?: (string | Date | number), +to?: (string | Date)}) => string
Generates a random mongodb-friendly objectId string.
<T>(returnValue: () => T) => (T | void)
() => string
Generates a random phone number, e.g. +15556797779
.
() => string
Generates a random producer name, e.g., Bahringer
.
(nameArg?: string) => string
Generates a random producer slug, e.g., anderson
.
Optionally can override with an explicit name to generate from.
() => string
Generates a random product name, e.g. Hargrand Apricots
.
() => string
Generates a random product unit, e.g. count
.
() => number
Generates a random product count, e.g., 31
.
() => string
Generates a random storage type, e.g., chill
.
<T>(array: T[]) => T
Chooses one of the elements of the provided array
. The given array cannot be empty.
() => string
Generates a random sentence beginning with a capitalized letter and ending with a period.
(length?: number, charset?: string) => string
Generates a random string, optionally of length
and using chars from provided charset
.
(tzids?: string[]) => string
Generate a random tzid, e.g., America/Denver
.
Accepts an optional array of tzids to sample.
(
generator: (...args: A) => T,
{
isEqual = Object.is,
}: {
isEqual?: (a: T, b: T) => boolean;
} = {},
): ((...args: A) => T)
Accepts a generator function and a number of items to generate and returns an array of unique
values. It throws a RangeError
when it is unable to generate an array of unique values.
By default it compares each new generated value against all other generated values using a
sameValueZero
(Object.is
) comparsion. You can customize this behavior by passing your own
comparator via options.isEqual
.
For example:
import fake from 'fake-eggs';
const uniqueFoo = fake.unique(fake.string);
uniqueFoo(); // => e.g. "foo_0"
uniqueFoo(); // => e.g. "foo_1"
uniqueFoo(); // => e.g. "foo_2"
// This could theoretically fail, but we'd have to get extraordinarily unlucky for it to do so.
const generateInteger0to100 = (): number => Math.floor(Math.random() * 100);
const generateUniqueInteger0to100 = fake.unique(generateInteger0to100);
const values = [1, 2, 3, 4, 5].map(() => generateUniqueInteger0to100());
(domain?: string) => string
Generate a random URI, e.g., https://adl2j.goodeggs.com/ax/faj23
@param {*} domain
(length?: number, charset?: string) => string
Generate a random zip code (e.g. 55416) with the option of specifying a ZIP+4 format (e.g. 12201-7050).
Recommended to use its fake.location.zip
counterpart.
(options?: {plusfour?: boolean}) => string
fake-eggs
uses chance.js behind the scenes. The chance.js object is exposed using fake.chance
, if you wish to use any of its functions.
i.e.
fake.chance.address()
fake.chance.state()
To compile the project:
yarn run build
To run tests:
yarn run test
To release a new version of this module, use yarn to bump the version
in package.json
and create a git tag, then push. This will automatically
get published to the NPM registry via CI.
yarn version --new-version=<major|minor|patch|premajor|preminor|prepatch>
git push --follow-tags