interface-forge - v2.5.0
    Preparing search index...

    Class LocationModule

    Module to generate addresses and locations. Prior to Faker 8.0.0, this module was known as faker.address.

    For a typical street address for a locale, use streetAddress(), city(), state()), and zipCode(). Most locales provide localized versions for a specific country.

    If you need latitude and longitude coordinates, use latitude() and longitude(), or nearbyGPSCoordinate() for a latitude/longitude near a given location.

    For a random country, you can use country() or countryCode().

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    faker: Faker

    Methods

    • Generates a random building number.

      Returns string

      faker.location.buildingNumber() // '379'
      

      8.0.0

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

      Parameters

      • Optionaloptions: { abbreviated?: boolean }

        The options to use.

        • Optionalabbreviated?: boolean

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

          false
          

      Returns string

      faker.location.cardinalDirection() // 'North'
      faker.location.cardinalDirection({ abbreviated: true }) // 'W'

      8.0.0

    • Generates a random localized city name.

      Returns string

      faker.location.city() // 'East Jarretmouth'
      fakerDE.location.city() // 'Bad Lilianadorf'

      8.0.0

    • Returns a random continent name.

      Returns string

      faker.location.continent() // 'Asia'
      

      9.1.0

    • Returns a random country name.

      Returns string

      faker.location.country() // 'Greece'
      

      8.0.0

    • Returns a random ISO_3166-1 country code.

      Parameters

      • Optionaloptions:
            | "alpha-2"
            | "alpha-3"
            | "numeric"
            | { variant?: "alpha-2"
            | "alpha-3"
            | "numeric" }

        The code to return or an options object.

        • "alpha-2"
        • "alpha-3"
        • "numeric"
        • { variant?: "alpha-2" | "alpha-3" | "numeric" }
          • Optionalvariant?: "alpha-2" | "alpha-3" | "numeric"

            The code to return. Can be either 'alpha-2' (two-letter code), 'alpha-3' (three-letter code) or 'numeric' (numeric code).

            'alpha-2'
            

      Returns string

      faker.location.countryCode() // 'SJ'
      faker.location.countryCode('alpha-2') // 'GA'
      faker.location.countryCode('alpha-3') // 'TJK'
      faker.location.countryCode('numeric') // '528'

      8.0.0

    • Returns a random localized county, or other equivalent second-level administrative entity for the locale's country such as a district or department.

      Returns string

      fakerEN_GB.location.county() // 'Cambridgeshire'
      fakerEN_US.location.county() // 'Monroe County'

      8.0.0

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

      Parameters

      • Optionaloptions: { abbreviated?: boolean }

        The options to use.

        • Optionalabbreviated?: boolean

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

          false
          

      Returns string

      faker.location.direction() // 'Northeast'
      faker.location.direction({ abbreviated: true }) // 'SW'

      8.0.0

    • Returns a random spoken language.

      Returns Language

      faker.location.language() // { alpha2: 'de', alpha3: 'deu', name: 'German' }
      faker.location.language().name // German
      faker.location.language().alpha2 // de
      faker.location.language().alpha3 // deu

      9.4.0

    • Generates a random latitude.

      Parameters

      • Optionaloptions: { max?: number; min?: number; precision?: number }

        An options object.

        • Optionalmax?: number

          The upper bound for the latitude to generate.

          90
          
        • Optionalmin?: number

          The lower bound for the latitude to generate.

          -90
          
        • Optionalprecision?: number

          The number of decimal points of precision for the latitude.

          4
          

      Returns number

      faker.location.latitude() // -30.9501
      faker.location.latitude({ max: 10 }) // 5.7225
      faker.location.latitude({ max: 10, min: -10 }) // -9.6273
      faker.location.latitude({ max: 10, min: -10, precision: 5 }) // 2.68452

      8.0.0

    • Generates a random longitude.

      Parameters

      • Optionaloptions: { max?: number; min?: number; precision?: number }

        An options object.

        • Optionalmax?: number

          The upper bound for the longitude to generate.

          180
          
        • Optionalmin?: number

          The lower bound for the longitude to generate.

          -180
          
        • Optionalprecision?: number

          The number of decimal points of precision for the longitude.

          4
          

      Returns number

      faker.location.longitude() // -30.9501
      faker.location.longitude({ max: 10 }) // 5.7225
      faker.location.longitude({ max: 10, min: -10 }) // -9.6273
      faker.location.longitude({ max: 10, min: -10, precision: 5 }) // 2.68452

      8.0.0

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

      Parameters

      • Optionaloptions: {
            isMetric?: boolean;
            origin?: [latitude: number, longitude: number];
            radius?: number;
        }

        The options for generating a GPS coordinate.

        • OptionalisMetric?: boolean

          If true assume the radius to be in kilometers. If false for miles.

          false
          
        • Optionalorigin?: [latitude: number, longitude: number]

          The original coordinate to get a new coordinate close to.

        • Optionalradius?: number

          The maximum distance from the given coordinate to the new coordinate.

          10
          

      Returns [latitude: number, longitude: number]

      faker.location.nearbyGPSCoordinate() // [ 33.8475, -170.5953 ]
      faker.location.nearbyGPSCoordinate({ origin: [33, -170] }) // [ 33.0165, -170.0636 ]
      faker.location.nearbyGPSCoordinate({ origin: [33, -170], radius: 1000, isMetric: true }) // [ 37.9163, -179.2408 ]

      8.0.0

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

      Parameters

      • Optionaloptions: { abbreviated?: boolean }

        Whether to use abbreviated or an options object.

        • Optionalabbreviated?: boolean

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

          false
          

      Returns string

      faker.location.ordinalDirection() // 'Northeast'
      faker.location.ordinalDirection({ abbreviated: true }) // 'SW'

      8.0.0

    • 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

      faker.location.secondaryAddress() // 'Apt. 861'
      

      8.0.0

    • Returns a random localized state, or other equivalent first-level administrative entity for the locale's country such as a province or region. Generally, these are the ISO 3166-2 subdivisions for a country. If a locale doesn't correspond to one specific country, the method may return ISO 3166-2 subdivisions from one or more countries that uses that language. For example, the ar locale includes subdivisions from Arabic-speaking countries, such as Tunisia, Algeria, Syria, Lebanon, etc. For historical compatibility reasons, the default en locale only includes states in the United States (identical to en_US). However, you can use other English locales, such as en_IN, en_GB, and en_AU, if needed.

      Parameters

      • Optionaloptions: { abbreviated?: boolean }

        An options object.

        • Optionalabbreviated?: boolean

          If true this will return abbreviated first-level administrative entity names. Otherwise this will return the long name.

          false
          

      Returns string

      faker.location.state() // 'Mississippi'
      fakerEN_CA.location.state() // 'Saskatchewan'
      fakerDE.location.state() // 'Nordrhein-Westfalen'
      faker.location.state({ abbreviated: true }) // 'LA'

      8.0.0

    • Generates a random localized street name.

      Returns string

      faker.location.street() // 'Schroeder Isle'
      

      8.0.0

    • Generates a random localized street address.

      Parameters

      • Optionaloptions: boolean | { useFullAddress?: boolean }

        Whether to use a full address or an options object.

        • boolean
        • { useFullAddress?: boolean }
          • OptionaluseFullAddress?: boolean

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

      Returns string

      faker.location.streetAddress() // '0917 O'Conner Estates'
      faker.location.streetAddress(false) // '34830 Erdman Hollow'
      faker.location.streetAddress(true) // '3393 Ronny Way Apt. 742'
      faker.location.streetAddress({ useFullAddress: true }) // '7917 Miller Park Apt. 410'

      8.0.0

    • Returns a random IANA time zone relevant to this locale.

      The returned time zone is tied to the current locale.

      Returns string

      faker.location.timeZone() // 'Pacific/Guam'
      

      8.0.0

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

      Parameters

      • Optionaloptions: string | { format?: string; state?: string }

        The format used to generate the zip code or an options object.

        • string
        • { format?: string; state?: string }
          • Optionalformat?: string

            The optional format used to generate the zip code.

            This won't be used if the state option is specified.

            faker.definitions.location.postcode
            
          • Optionalstate?: string

            The state to generate the zip code for.

            If the current locale does not have a corresponding postcode_by_state definition, an error is thrown.

      Returns string

      faker.helpers.replaceSymbols(): For more information about how the pattern is used.

      faker.location.zipCode() // '17839'
      faker.location.zipCode('####') // '6925'

      8.0.0