faker-user
v0.3.1
Published
Random person data generation utility library
Maintainers
Readme
faker-user
A flexible npm library for generating realistic random person profiles with country-aware names, phone numbers, salary estimates, contact details, and custom attributes.
Overview
faker-user is designed for:
- prototyping user profiles
- test data generation
- game NPC generation
- demo apps and mock APIs
It supports deep customization through generatePerson(), generatePersons(), and generateName().
Install
Install from npm:
npm install faker-userOr install locally from the repository:
npm install /path/to/faker-userQuick Start
import {
generateName,
genName,
createName,
generatePerson,
genPerson,
createPerson,
makePerson,
generatePersons,
genPersons,
createPersons,
makePersons
} from "faker-user";
const simpleName = generateName();
const simpleNameAlias = genName();
console.log(simpleName, simpleNameAlias);
const person = generatePerson({
country: ["UnitedStates"],
jobs: ["Software Engineer"],
salaryCurrency: "USD",
phoneCountry: ["UnitedKingdom"],
phone: "+44 7123456789"
});
const personAlias = createPerson({
country: ["UnitedStates"],
jobs: ["Software Engineer"]
});
const people = generatePersons({
country: ["Canada"],
jobs: ["Data Analyst"],
minAge: 22,
maxAge: 35,
salaryCurrency: "CAD"
}, 3);
const peopleAlias = genPersons({
country: ["Canada"],
jobs: ["Data Analyst"]
}, 3);
console.log(person, personAlias, people, peopleAlias);APIs
generateName(options?)
Generates a random full name from the available name pools.
Aliases: genName, createName
generateName({ country: "Japan", gender: "female" });Options
country?: CountryName | CountryName[]gender?: "male" | "female" | readonly ("male" | "female")[]
generatePerson(options?)
Generates a complete person object with name, location, job, salary, email, phone, attributes, and custom fields.
Aliases: genPerson, createPerson, makePerson
import { generatePerson, GeneratePersonOutputOption } from "faker-user";
const person = generatePerson(
{
country: ["India", "UnitedStates"],
gender: "female",
jobs: ["Software Engineer", "Data Analyst"],
minAge: 25,
maxAge: 40
},
{
outputOption: [GeneratePersonOutputOption.Name, GeneratePersonOutputOption.Email]
}
);generatePersons(options?, itemNumber)
Generates an array of Person objects using the same options for each generated entry.
Aliases: genPersons, createPersons, makePersons
import { generatePersons, GeneratePersonOutputOption } from "faker-user";
const people = generatePersons(
{
country: ["Canada"],
jobs: ["Product Manager"]
},
5,
{
outputOption: [GeneratePersonOutputOption.Name, GeneratePersonOutputOption.City]
}
);generatePerson() Options
Basic options
country?: CountryName | readonly CountryName[]gender?: "male" | "female" | readonly ("male" | "female")[]jobs?: readonly JobTitle[]minAge?: numbermaxAge?: number
Salary options
salaryCurrency?: countryCurrencyCode— target currency code for generated salarysalaryExact?: number— force an exact salary valuesalaryMin?: number— minimum salary when generating a random valuesalaryMax?: number— maximum salary when generating a random value
Name options
name?: string— override the entire generated namefirstName?: string— force the first name onlylastName?: string— force the last name onlynameFormat?: "firstLast" | "lastFirst"— control name layout
Location & contact options
city?: string | readonly string[]— fixed or selectable city valueemail?: string— exact email overrideemailDomain?: string— custom domain for generated emailphone?: string— exact phone string overridephoneCountry?: CountryName | readonly CountryName[]— use a different country phone formatphonePrefix?: string— force the phone operator prefix
Result filtering
outputOption?: GeneratePersonOutputOption | readonly GeneratePersonOutputOption[]— return only the desired predefined profile field or fields
Includes GeneratePersonOutputOption.Dob to select date of birth only.
Attribute and profile options
educationLevel?: EducationLevelmaritalStatus?: MaritalStatusemploymentType?: EmploymentType
Custom fields
The custom option allows you to append arbitrary custom fields to the generated person object.
Supported custom field types:
integer— random integer betweenminandmaxfloat— random float betweenminandmaxboolean—trueorfalseenum— one random value fromvaluesfixed— static fixed value
Example
const person = generatePerson({
country: ["UnitedStates"],
jobs: ["Software Engineer"],
custom: [
{ field: "power", type: "integer", min: 1, max: 10 },
{ field: "playerType", type: "enum", values: ["warrior", "mage", "archer", "healer"] },
{ field: "isNPC", type: "boolean" },
{ field: "Special Group", type: "fixed", value: "The Adventurers Guild" },
{ field: "Luck", type: "float", min: 0, max: 1 }
]
});Result Object
generatePerson() returns a Person object containing all built-in fields plus any custom fields.
Built-in result fields include:
nameagedobgendercountrycityjobsalarysalaryCurrencyemailphoneeducationLevelmaritalStatusemploymentType
Custom fields are merged directly into the result object.
How it works
faker-user assembles profiles by combining multiple generators:
generateName()selects gendered first and last names from country-specific pools.generatePerson()resolves country, job, age, and profile metadata.- Salary is calculated using a country multiplier and optional currency conversion.
- Email is built from the generated name and country, optionally using a custom domain.
- Phone numbers are generated using country dialing data and operator prefixes.
buildPersonAttributes()selects education, marital status, and employment type.customattributes are evaluated and appended to the final object.
Development
To build the library locally:
npm install
npm run buildRun the test suite:
npm testContributing
Contributions are welcome! If you want to improve the generator, please:
- fork the repository
- create a feature branch
- add tests for new behavior
- open a pull request
Good contribution targets include:
- more country data and name pools
- tighter salary/currency mapping
- enhanced phone formatting
- additional custom attribute types
- documentation improvements
Thanks for contributing to faker-user! Feel free to open issues or PRs with ideas, bug fixes, or new examples.
