Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fake.location and bump minor version #235

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fake-eggs",
"version": "6.3.1",
"version": "6.4.0",
"description": "Generate Good Eggs-flavored data for development / test fixtures",
"main": "dist/index.js",
"scripts": {
Expand Down
34 changes: 27 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ fake.employee.email(); // => '[email protected]
automatically. Please update this manually when making changes, until we can add some entation
auto-generation back in. -->

#### `fake.address`

`() => string`

Generates a random street address string (e.g., `5447 Bazpe Lane`).
Recommended to use its `fake.location.address` counterpart.

#### `fake.array`

`<T>(lengthLowerInclusive: number, lengthUpperExclusive: number, generator: () => T) => T[]`
Expand Down Expand Up @@ -158,6 +165,24 @@ Generates a random integer (could be negative!). Optionally between `lowerExclus

Generates a random last name, e.g., `Armstrong`.

#### `fake.location.address`

`() => string`

Generates a random street address string (e.g., `5447 Bazpe Lane`).

#### `fake.location.state`

`() => string`

Generates a random two letter state code, e.g., `CA`.

#### `fake.location.zip`

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`

#### `fake.maybe`

`<T>(returnValue: () => T) => ?T`
Expand Down Expand Up @@ -247,12 +272,6 @@ Chooses one of the elements of the provided `array`. The given array cannot be e

Generates a random sentence beginning with a capitalized letter and ending with a period.

#### `fake.state`

`() => string`

Generates a random two letter state code, e.g., `CA`.

#### `fake.string`

`(length?: number, charset?: string) => string`
Expand Down Expand Up @@ -316,7 +335,8 @@ Generate a random URI, e.g., `https://adl2j.goodeggs.com/ax/faj23`

#### `fake.zip`

Generate a random zip code (e.g. 55416) with the option of specifying a ZIP+4 format (e.g. 12201-7050)
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`

Expand Down
13 changes: 13 additions & 0 deletions src/generators/location/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Chance} from 'chance';

import createAddressGenerator from '../address';
import createStateGenerator from '../state';
import createZipGenerator from '../zip';

const createLocationGenerators = (chance: Chance.Chance) => ({
address: createAddressGenerator(chance),
state: createStateGenerator(chance),
zip: createZipGenerator(chance),
});

export default createLocationGenerators;
1 change: 0 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('the default export', function () {
const values = ['a', 'b', 'c'];
expect(values).toContain(fake.sample(values));
expect(fake.digit()).toEqual(expect.any(Number));
expect(fake.state()).toEqual(expect.any(String));
expect(fake.string()).toEqual(expect.any(String));
expect(fake.uri()).toEqual(expect.any(String));
expect(fake.zip()).toEqual(expect.any(String));
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import createFullNameGenerator from './generators/full_name';
import createUniqueGenerator from './generators/unique';
import createIntegerGenerator from './generators/integer';
import createLastNameGenerator from './generators/last_name';
import createLocationGenerators from './generators/location';
import createMaybeCombinator from './combinators/maybe';
import createNullableCombinator from './combinators/nullable';
import createNumberGenerator from './generators/number';
Expand All @@ -26,7 +27,6 @@ import createProducerGenerators from './generators/producer';
import createProductGenerators from './generators/product';
import createSampleGenerator from './generators/sample';
import createSentenceGenerator from './generators/sentence';
import createStateGenerator from './generators/state';
import createStringGenerator from './generators/string';
import createTzidGenerator from './generators/tzid';
import createUriGenerator from './generators/uri';
Expand Down Expand Up @@ -95,14 +95,14 @@ export const createFakeEggs = ({
fullName: createFullNameGenerator(chance),
integer: createIntegerGenerator(chance),
lastName: createLastNameGenerator(chance),
location: createLocationGenerators(chance),
number: createNumberGenerator(chance),
objectId: createObjectIdGenerator(chance),
phoneNumber: createPhoneNumberGenerators(chance),
producer: createProducerGenerators(chance),
product: createProductGenerators(chance),
sample: createSampleGenerator(chance),
sentence: createSentenceGenerator(chance),
state: createStateGenerator(chance),
string: createStringGenerator(chance),
tzid: createTzidGenerator(chance),
unique: createUniqueGenerator(chance),
Expand Down