Here is the demo of the npm. https://addressgenerator.io/
The Random Address Generator package generates realistic random addresses based on country data, with customizable formats and additional fields. The package supports generating random addresses for various countries, and allows you to control various aspects of the address, such as the country, address type, and format.
To install the package, use npm:
npm install random-addresses-generator
CDN:
<script type="module">
import { getAddress } from 'https://cdn.jsdelivr.net/npm/random-addresses-generator@1.1.11/src/index.js';
console.log(await getAddress(1));
</script>
The address generator can generate the following fields:
- buildingNo: The building number or house number (e.g., 123, 456).
- buildingName: The name of the building (e.g., "Sunset Tower").
- streetNumber: The street number (e.g., 12).
- streetName: The name of the street (e.g., "Main St", "Elm Street").
- neighborhood: The neighborhood or area (e.g., "Downtown", "Suburbs").
- landmark: A nearby landmark or notable feature (e.g., "Near Central Park").
- city: The city name (e.g., "New York", "Los Angeles").
- state: The state or region name (e.g., "California", "Texas").
- zipCode: The postal or zip code (e.g., "10001", "90210").
- firstName: The first name of a random person (e.g., "John", "Maria").
- lastName: The last name of a random person (e.g., "Doe", "Smith").
- phone: A randomly generated phone number (e.g., "+1 (555) 123-4567").
- email: A randomly generated email address (e.g., "john.doe@example.com").
- Resedential: Residential addresses (default).
- Corporate: Corporate addresses such as company headquarters.
- Industrial: Industrial addresses like factories, warehouses.
Example:
{
addressType : "Resedential"
}
You can add custom fields to your address data by using the addon
property. This property allows you to inject additional data into the generated address.
Example:
{
addon: [{
note: "This is a special note"
}]
}
This will append a note
field to each generated address.
You can control which states to generate addresses from by passing an array of state codes. If you don't specify any states, the generator will select from all available states by default.
Example:
{
states: ["CA", "MN"] // Generates addresses from California and Minnesota only
}
You can specify the country to generate addresses from. The default country is the United States (USA
).
Example:
{
country: "Canada" // Generates addresses from Canada
}
You can specify the city to generate addresses from. .
Example:
{
city: "New York",
country : "USA" // Generates addresses from New York
}
You can specify the format of the generated address using the addressFormat
property, which defines the order of the fields. By default, the address format is:
['buildingNo', 'buildingName', 'streetNumber', 'streetName', 'neighborhood', 'landmark', 'city', 'state', 'zipCode', 'firstName', 'lastName', 'phone', 'email']
You can customize the format by passing an array of field names.
Example:
{
addressFormat: ['firstName', 'lastName', 'city', 'state', 'zipCode']
}
Generates a specified number of random addresses with the given configuration.
- count: The number of addresses to generate.
-
info (optional): A configuration object with the following optional properties:
-
country
: The country to generate addresses for (default is "United States"). -
addressType
: The type of address to generate (options: "Resedential", "Corporate", "Industrial", default is "Resedential"). -
states
: An array of state codes (e.g.,["CA", "MN"]
), default is["all"]
, which generates from all states. -
addressFormat
: A custom format for the address (default is['buildingNo', 'buildingName', 'streetNumber', 'streetName', 'neighborhood', 'landmark', 'city', 'state', 'zipCode', 'firstName', 'lastName', 'phone', 'email']
). -
addon
: Custom fields to be added to each address. -
format
: The format of the output (options: "json", "csv", "text", default is "json").
-
- Generate 5 Commercial Addresses from the United States:
import { getAddress } from('random-addresses-generator');
const addressData = getAddress(5, {
country: 'USA',
addressType: 'Resedential',
format: 'json'
});
console.log(addressData);
- Generate 3 addresses from specific states (California and Minnesota):
import { getAddress } from "random-addresses-generator";
const addressData = getAddress(3, {
country: 'USA',
states: ['CA', 'MN'],
addressFormat: ['firstName', 'lastName', 'streetName', 'city', 'state', 'zipCode'],
format: 'json'
});
console.log(addressData);
- Generate 2 addresses with custom addon field:
import { getAddress } from "random-addresses-generator";
const addressData = getAddress(2, {
country: 'Canada',
addressType: 'Corporate',
addon: [{
note: "This is a custom note"
}],
format: 'json'
});
console.log(addressData);
The package supports generating random addresses for the following countries:
- United States (USA)
- Canada
- Germany
- Argentina
- Australia
- Belgium
- Brazil
- Canada
- China
- Egypt
- England
- France
- Germany
- Greece
- India
- Indonesia
- United Kingdom
- Mexico
- Japan
- Netherlands
- New Zealand
- Nigeria
- Norway
- Poland
- Portugal
- Russia
- Saudi Arabia
- Singapore
- South Africa
- South Korea
- Spain
- Sweden
- Switzerland
- Thailand
- Turkey
- UAE
- Vietnam
The Random Address Generator stands out by ensuring that the generated addresses are not only random but also relevant and realistic. Each address component, such as the city, zip code, and street name, is carefully matched to ensure consistency and accuracy. This means that the zip code corresponds to the correct city, and the street names are appropriate for the selected country and region. Our generator provides high-quality, believable addresses that can be used for testing, development, and other purposes where realistic data is crucial.