Address

Module to generate addresses and locations.

  • Building Number
  • Cardinal Direction
  • City
  • City Name
  • City Prefix
  • City Suffix
  • Country
  • Country Code
  • County
  • Direction
  • Latitude
  • Longitude
  • Nearby GPSCoordinate
  • Ordinal Direction
  • Secondary Address
  • State
  • State Abbr
  • Street
  • Street Address
  • Street Name
  • Street Prefix
  • Street Suffix
  • Time Zone
  • Zip Code
  • Zip Code By State

Building Number

Generates a random building number.

Returns: string

// buildingNumber function
address.buildingNumber(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.buildingNumber(); // => "5786"
address.buildingNumber(); // '379'

Cardinal Direction

Returns a random cardinal direction (north, east, south, west).

Parameters

NameTypeDefaultDescription
useAbbrbooleanfalseIf true this will return abbreviated directions (N, E, etc). Otherwise this will return the long name.

Returns: string

// cardinalDirection function
address.cardinalDirection(useAbbr: boolean = false): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.cardinalDirection(); // => "South"
address.cardinalDirection(); // 'North'
address.cardinalDirection(false); // 'South'
address.cardinalDirection(true); // 'N'

City

Generates a random localized city name.

Parameters

NameTypeDefaultDescription
format?number | stringThe index of the format to use. Deprecated do not use.

Returns: string

// city function
address.city(format?: number | string): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.city(); // => "Larrymouth"
address.city(); // 'East Jarretmouth'

City Name

Returns a random localized and existing city name.

Returns: string

// cityName function
address.cityName(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.cityName(); // => "Menifee"
address.cityName(); // 'San Rafael'

Country

Returns a random country name.

Returns: string

// country function
address.country(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.country(); // => "Malta"
address.country(); // 'Greece'

Country Code

Returns a random country code.

Parameters

NameTypeDefaultDescription
alphaCode'alpha-2' | 'alpha-3''alpha-2'The code to return. Can be either 'alpha-2' (2 letter code) or 'alpha-3' (three letter code).

Returns: string

// countryCode function
address.countryCode(alphaCode: 'alpha-2' | 'alpha-3' = 'alpha-2'): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.countryCode(); // => "MA"
address.countryCode(); // 'SJ'
address.countryCode('alpha-2'); // 'GA'
address.countryCode('alpha-3'); // 'TJK'

County

Returns a random localized county.

Returns: string

// county function
address.county(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.county(); // => "Borders"
address.county(); // 'Cambridgeshire'

Direction

Returns a random direction (cardinal and ordinal; northwest, east, etc).

Parameters

NameTypeDefaultDescription
useAbbrbooleanfalseIf true this will return abbreviated directions (NW, E, etc). Otherwise this will return the long name.

Returns: string

// direction function
address.direction(useAbbr: boolean = false): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.direction(); // => "Northeast"
address.direction(); // 'Northeast'
address.direction(false); // 'South'
address.direction(true); // 'NE'

Latitude

Generates a random latitude.

Parameters

NameTypeDefaultDescription
maxnumber90The upper bound for the latitude to generate.
minnumber-90The lower bound for the latitude to generate.
precisionnumber4The number of decimal points of precision for the latitude.

Returns: string

// latitude function
address.latitude(max: number = 90, min: number = -90, precision: number = 4): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.latitude(); // => "8.7864"
address.latitude(); // '-30.9501'
address.latitude(10, -10, 5); // '2.68452'

Longitude

Generates a random longitude.

Parameters

NameTypeDefaultDescription
maxnumber180The upper bound for the longitude to generate.
minnumber-180The lower bound for the longitude to generate.
precisionnumber4The number of decimal points of precision for the longitude.

Returns: string

// longitude function
address.longitude(max: number = 180, min: number = -180, precision: number = 4): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.longitude(); // => "17.5729"
address.longitude(); // '-154.0226'
address.longitude(10, -10, 5); // '-4.03620'

Nearby GPSCoordinate

Generates a random GPS coordinate within the specified radius from the given coordinate.

Parameters

NameTypeDefaultDescription
coordinate?[latitude: number, longitude: number]The original coordinate to get a new coordinate close to. If no coordinate is given, a random one will be chosen.
radiusnumber10The maximum distance from the given coordinate to the new coordinate.
isMetricbooleanfalseIf true assume the radius to be in kilometers. If false for miles.

Returns: string

// nearbyGPSCoordinate function
address.nearbyGPSCoordinate(coordinate?: [latitude: number, longitude: number], radius: number = 10, isMetric: boolean = false): [latitude: string, longitude: string]

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.nearbyGPSCoordinate(); // => ["8.7864","33.4241"]
address.nearbyGPSCoordinate(); // [ '33.8475', '-170.5953' ]
address.nearbyGPSCoordinate([33, -170]); // [ '33.0165', '-170.0636' ]
address.nearbyGPSCoordinate([33, -170], 1000, true); // [ '37.9163', '-179.2408' ]

Ordinal Direction

Returns a random ordinal direction (northwest, southeast, etc).

Parameters

NameTypeDefaultDescription
useAbbrbooleanfalseIf true this will return abbreviated directions (NW, SE, etc). Otherwise this will return the long name.

Returns: string

// ordinalDirection function
address.ordinalDirection(useAbbr: boolean = false): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.ordinalDirection(); // => "Southeast"
address.ordinalDirection(); // 'Northeast'
address.ordinalDirection(false); // 'Northwest'
address.ordinalDirection(true); // 'NE'

Secondary Address

Generates a random localized secondary address. This refers to a specific location at a given address such as an apartment or room number.

Returns: string

// secondaryAddress function
address.secondaryAddress(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.secondaryAddress(); // => "Suite 578"
address.secondaryAddress(); // 'Apt. 861'

State

Returns a random localized state from this country.

Returns: string

// state function
address.state(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.state(); // => "Nevada"
address.state(); // 'Georgia'

State Abbr

Returns a random localized state's abbreviated name from this country.

Returns: string

// stateAbbr function
address.stateAbbr(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.stateAbbr(); // => "NV"
address.stateAbbr(); // 'ND'

Street

Generates a random localized street name.

Returns: string

// street function
address.street(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.street(); // => "Medhurst Road"
address.street(); // 'Schroeder Isle'

Street Address

Generates a random localized street address.

Parameters

NameTypeDefaultDescription
useFullAddressbooleanfalseWhen true this will generate a full address. Otherwise it will just generate a street address.

Returns: string

// streetAddress function
address.streetAddress(useFullAddress: boolean = false): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.streetAddress(); // => "5786 Little Summit"
address.streetAddress(); // '0917 O'Conner Estates'
address.streetAddress(false); // '34830 Erdman Hollow'
address.streetAddress(true); // '3393 Ronny Way Apt. 742'

Street Name

Returns a random localized street name.

Returns: string

// streetName function
address.streetName(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.streetName(); // => "Medhurst Road"
address.streetName(); // 'Cavill Avenue'

Street Prefix

Returns a random localized street prefix.

Returns: string

// streetPrefix function
address.streetPrefix(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.streetPrefix(); // => "b"
address.streetPrefix(); // 'Boame'

Street Suffix

Returns a random localized street suffix.

Returns: string

// streetSuffix function
address.streetSuffix(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.streetSuffix(); // => "Orchard"
address.streetSuffix(); // 'Streets'

Time Zone

Returns a random time zone.

Returns: string

// timeZone function
address.timeZone(): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.timeZone(); // => "Asia/Riyadh"
address.timeZone(); // 'Pacific/Guam'

Zip Code

Generates random zip code from specified format. If format is not specified, the locale's zip format is used.

Parameters

NameTypeDefaultDescription
format?stringThe optional format used to generate the the zip code. By default, a random format is used from the locale zip formats.

Returns: string

// zipCode function
address.zipCode(format?: string): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.zipCode(); // => "57868-5846"
address.zipCode(); // '17839'
address.zipCode('####'); // '6925'

Zip Code By State

Generates random zip code from state abbreviation. If state abbreviation is not specified, a random zip code is generated according to the locale's zip format. Only works for locales with postcode_by_state definition. If a locale does not have a postcode_by_state definition, a random zip code is generated according to the locale's zip format.

Parameters

NameTypeDefaultDescription
statestringThe abbreviation of the state to generate the zip code for.

Returns: string

// zipCodeByState function
address.zipCodeByState(state: string): string

// import
import { useFaker } from 'next-faker';

const { address } = useFaker();

// usage
address.zipCodeByState(); // => "57868-5846"
address.zipCodeByState("AK"); // '99595'
address.zipCodeByState("??"); // '47683-9880'