Skip to content

Commit

Permalink
refactor(person)!: rename name module (#1445)
Browse files Browse the repository at this point in the history
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
  • Loading branch information
Shinigami92 and ST-DDT authored Oct 16, 2022
1 parent 90b9c5c commit 20f2236
Show file tree
Hide file tree
Showing 593 changed files with 1,173 additions and 1,112 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The API covers the following modules:
| Internet | `faker.internet.domainName()` | muddy-neuropathologist.net |
| Lorem | `faker.lorem.paragraph()` | Porro nulla id vero perspiciatis nulla nihil. ... |
| Music | `faker.music.genre()` | R&B |
| Name | `faker.name.firstName()` | Cameron |
| Person | `faker.person.firstName()` | Cameron |
| Phone | `faker.phone.phoneNumber()` | +1 291-299-0192 |
| Random | `faker.random.locale()` | fr_CA |
| Science | `faker.science.unit()` | `{ name: 'meter', symbol: 'm' }` |
Expand All @@ -103,7 +103,7 @@ Faker contains a generator method `faker.helpers.fake` for combining faker API m
```ts
console.log(
faker.helpers.fake(
'Hello {{name.prefix}} {{name.lastName}}, how are you today?'
'Hello {{person.prefix}} {{person.lastName}}, how are you today?'
)
);
```
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/api-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const apiPages = [
{ text: 'Internet', link: '/api/internet.html' },
{ text: 'Lorem', link: '/api/lorem.html' },
{ text: 'Music', link: '/api/music.html' },
{ text: 'Name', link: '/api/name.html' },
{ text: 'Person', link: '/api/person.html' },
{ text: 'Phone', link: '/api/phone.html' },
{ text: 'Random', link: '/api/random.html' },
{ text: 'Science', link: '/api/science.html' },
Expand Down
26 changes: 13 additions & 13 deletions docs/guide/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Using Faker is as easy as importing it from `@faker-js/faker`.
```js
import { faker } from '@faker-js/faker';

const randomName = faker.name.fullName(); // Rowan Nikolaus
const randomName = faker.person.fullName(); // Rowan Nikolaus
const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
```

Expand All @@ -16,7 +16,7 @@ Or if you using CommonJS
```js
const { faker } = require('@faker-js/faker');

const randomName = faker.name.fullName(); // Rowan Nikolaus
const randomName = faker.person.fullName(); // Rowan Nikolaus
const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
```

Expand All @@ -27,7 +27,7 @@ const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
// Caitlyn Kerluke
const randomName = faker.name.fullName();
const randomName = faker.person.fullName();
// Rusty@arne.info
const randomEmail = faker.internet.email();
Expand All @@ -43,7 +43,7 @@ Using the browser is great for experimenting 👍. However, due to all of the st
```js
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';

const randomName = faker.name.findName(); // Willie Bahringer
const randomName = faker.person.findName(); // Willie Bahringer
const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com
```

Expand Down Expand Up @@ -120,9 +120,9 @@ function createRandomUser(): User {
avatar: faker.image.avatar(),
birthday: faker.date.birthdate(),
email: faker.internet.email(),
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
sex: faker.name.sexType(),
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
sex: faker.person.sexType(),
subscriptionTier: faker.helpers.arrayElement(['free', 'basic', 'business']),
};
}
Expand All @@ -142,9 +142,9 @@ Let's refactor our current code:
import { faker } from '@faker-js/faker';

function createRandomUser(): User {
const sex = this.faker.name.sexType();
const firstName = faker.name.firstName(sex);
const lastName = faker.name.lastName();
const sex = this.faker.person.sexType();
const firstName = faker.person.firstName(sex);
const lastName = faker.person.lastName();
const email = faker.internet.email(firstName, lastName);

return {
Expand Down Expand Up @@ -179,9 +179,9 @@ Faker has your back, with another helper method:
import { faker } from '@faker-js/faker';

function createRandomUser(): User {
const sex = this.faker.name.sexType();
const firstName = faker.name.firstName(sex);
const lastName = faker.name.lastName();
const sex = this.faker.person.sexType();
const firstName = faker.person.firstName(sex);
const lastName = faker.person.lastName();
const email = faker.helpers.unique(faker.internet.email, [
firstName,
lastName,
Expand Down
8 changes: 7 additions & 1 deletion scripts/apidoc/moduleMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ export function processModuleMethods(project: ProjectReflection): PageIndex {
}

export function extractModuleName(module: DeclarationReflection): string {
return module.name.replace(/Module$/, '');
const { name } = module;
// TODO @ST-DDT 2022-10-16: Remove in v10.
// Typedoc prefers the name of the module that is exported first.
if (name === 'NameModule') {
return 'Person';
}
return name.replace(/Module$/, '');
}

function extractModuleFieldName(module: DeclarationReflection): string {
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const definitionsTypes: DefinitionsType = {
internet: 'InternetDefinitions',
lorem: 'LoremDefinitions',
music: 'MusicDefinitions',
name: 'NameDefinitions',
person: 'PersonDefinitions',
phone_number: 'PhoneNumberDefinitions',
science: 'ScienceDefinitions',
system: 'SystemDefinitions',
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { HackerDefinitions } from './hacker';
import type { InternetDefinitions } from './internet';
import type { LoremDefinitions } from './lorem';
import type { MusicDefinitions } from './music';
import type { NameDefinitions } from './name';
import type { PersonDefinitions } from './person';
import type { PhoneNumberDefinitions } from './phone_number';
import type { ScienceDefinitions } from './science';
import type { SystemDefinitions } from './system';
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface Definitions {
internet: InternetDefinitions;
lorem: LoremDefinitions;
music: MusicDefinitions;
name: NameDefinitions;
person: PersonDefinitions;
phone_number: PhoneNumberDefinitions;
science: ScienceDefinitions;
system: SystemDefinitions;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type { HackerDefinitions } from './hacker';
export type { InternetDefinitions } from './internet';
export type { LoremDefinitions } from './lorem';
export type { MusicDefinitions } from './music';
export type { NameDefinitions, NameTitleDefinitions } from './name';
export type { PersonDefinitions, PersonTitleDefinitions } from './person';
export type { PhoneNumberDefinitions } from './phone_number';
export type { ScienceDefinitions } from './science';
export type {
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/name.ts → src/definitions/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to people's names.
*/
export type NameDefinitions = LocaleEntry<{
export type PersonDefinitions = LocaleEntry<{
gender: string[];
sex: string[];

Expand All @@ -30,13 +30,13 @@ export type NameDefinitions = LocaleEntry<{
*/
name: string[];

title: NameTitleDefinitions;
title: PersonTitleDefinitions;
}>;

/**
* The possible definitions related to people's titles.
*/
export interface NameTitleDefinitions {
export interface PersonTitleDefinitions {
descriptor?: string[];
job: string[];
level?: string[];
Expand Down
29 changes: 27 additions & 2 deletions src/faker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LocaleDefinition } from './definitions';
import { FakerError } from './errors/faker-error';
import { deprecated } from './internal/deprecated';
import { MersenneModule } from './internal/mersenne/mersenne';
import type { KnownLocale } from './locales';
import { AddressModule } from './modules/address';
Expand All @@ -18,7 +19,8 @@ import { ImageModule } from './modules/image';
import { InternetModule } from './modules/internet';
import { LoremModule } from './modules/lorem';
import { MusicModule } from './modules/music';
import { NameModule } from './modules/name';
import type { PersonModule as NameModule } from './modules/person';
import { PersonModule } from './modules/person';
import { PhoneModule } from './modules/phone';
import { RandomModule } from './modules/random';
import { ScienceModule } from './modules/science';
Expand Down Expand Up @@ -97,13 +99,25 @@ export class Faker {
readonly internet: InternetModule = new InternetModule(this);
readonly lorem: LoremModule = new LoremModule(this);
readonly music: MusicModule = new MusicModule(this);
readonly name: NameModule = new NameModule(this);
readonly person: PersonModule = new PersonModule(this);
readonly phone: PhoneModule = new PhoneModule(this);
readonly science: ScienceModule = new ScienceModule(this);
readonly system: SystemModule = new SystemModule(this);
readonly vehicle: VehicleModule = new VehicleModule(this);
readonly word: WordModule = new WordModule(this);

// Aliases
/** @deprecated Use {@link person} instead */
get name(): NameModule {
deprecated({
deprecated: 'faker.name',
proposed: 'faker.person',
since: '8.0.0',
until: '10.0.0',
});
return this.person;
}

constructor(opts: FakerOptions) {
if (!opts) {
throw new FakerError(
Expand Down Expand Up @@ -158,6 +172,17 @@ export class Faker {

return new Proxy({} as LocaleDefinition, {
get(target: LocaleDefinition, module: string): unknown {
// Support aliases
if (module === 'name') {
module = 'person';
deprecated({
deprecated: `faker.helpers.fake('{{name.*}}') or faker.definitions.name`,
proposed: `faker.helpers.fake('{{person.*}}') or faker.definitions.person`,
since: '8.0.0',
until: '10.0.0',
});
}

let result = target[module];
if (result) {
return result;
Expand Down
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export type {
LocaleDefinition,
LoremDefinitions,
MusicDefinitions,
NameDefinitions,
NameTitleDefinitions,
/** @deprecated Use PersonDefinitions instead */
PersonDefinitions as NameDefinitions,
PersonDefinitions,
/** @deprecated Use PersonTitleDefinitions instead */
PersonTitleDefinitions as NameTitleDefinitions,
PersonTitleDefinitions,
PhoneNumberDefinitions,
ScienceDefinitions,
SystemDefinitions,
Expand Down Expand Up @@ -53,8 +57,13 @@ export type { ImageModule } from './modules/image';
export type { InternetModule } from './modules/internet';
export type { LoremModule } from './modules/lorem';
export type { MusicModule } from './modules/music';
export { Sex } from './modules/name';
export type { NameModule, SexType } from './modules/name';
export { Sex } from './modules/person';
export type {
/** @deprecated Use PersonModule instead */
PersonModule as NameModule,
PersonModule,
SexType,
} from './modules/person';
export type { PhoneModule } from './modules/phone';
export type { RandomModule } from './modules/random';
export type { ChemicalElement, ScienceModule, Unit } from './modules/science';
Expand Down
8 changes: 4 additions & 4 deletions src/locales/af_ZA/address/city.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default [
'{{address.city_prefix}} {{name.firstName}}{{address.city_suffix}}',
'{{address.city_prefix}} {{name.firstName}}',
'{{name.firstName}}{{address.city_suffix}}',
'{{name.lastName}}{{address.city_suffix}}',
'{{address.city_prefix}} {{person.firstName}}{{address.city_suffix}}',
'{{address.city_prefix}} {{person.firstName}}',
'{{person.firstName}}{{address.city_suffix}}',
'{{person.lastName}}{{address.city_suffix}}',
];
4 changes: 2 additions & 2 deletions src/locales/af_ZA/address/street.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
'{{name.firstName}} {{address.street_suffix}}',
'{{name.lastName}} {{address.street_suffix}}',
'{{person.firstName}} {{address.street_suffix}}',
'{{person.lastName}} {{address.street_suffix}}',
];
4 changes: 2 additions & 2 deletions src/locales/af_ZA/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import address from './address';
import cell_phone from './cell_phone';
import company from './company';
import internet from './internet';
import name_ from './name';
import person from './person';
import phone_number from './phone_number';

const af_ZA: LocaleDefinition = {
Expand All @@ -16,7 +16,7 @@ const af_ZA: LocaleDefinition = {
cell_phone,
company,
internet,
name: name_,
person,
phone_number,
};

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { NameDefinitions } from '../../..';
import type { PersonDefinitions } from '../../..';
import female_first_name from './female_first_name';
import first_name from './first_name';
import last_name from './last_name';
import male_first_name from './male_first_name';

const name: NameDefinitions = {
const person: PersonDefinitions = {
female_first_name,
first_name,
last_name,
male_first_name,
};

export default name;
export default person;
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/locales/ar/address/street.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
'{{address.street_prefix}} {{name.first_name}}',
'{{address.street_prefix}} {{name.last_name}}',
'{{address.street_prefix}} {{person.first_name}}',
'{{address.street_prefix}} {{person.last_name}}',
];
4 changes: 2 additions & 2 deletions src/locales/ar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import cell_phone from './cell_phone';
import color from './color';
import commerce from './commerce';
import date from './date';
import name_ from './name';
import person from './person';
import phone_number from './phone_number';
import team from './team';
import vehicle from './vehicle';
Expand All @@ -21,7 +21,7 @@ const ar: LocaleDefinition = {
color,
commerce,
date,
name: name_,
person,
phone_number,
team,
vehicle,
Expand Down
5 changes: 0 additions & 5 deletions src/locales/ar/name/name.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { NameDefinitions } from '../../..';
import type { PersonDefinitions } from '../../..';
import female_first_name from './female_first_name';
import first_name from './first_name';
import last_name from './last_name';
Expand All @@ -12,7 +12,7 @@ import prefix from './prefix';
import suffix from './suffix';
import title from './title';

const name: NameDefinitions = {
const person: PersonDefinitions = {
female_first_name,
first_name,
last_name,
Expand All @@ -23,4 +23,4 @@ const name: NameDefinitions = {
title,
};

export default name;
export default person;
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/locales/ar/person/name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default [
'{{person.prefix}} {{person.first_name}} {{person.last_name}}',
'{{person.first_name}} {{person.last_name}}',
'{{person.last_name}} {{person.first_name}}',
];
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/locales/az/company/name_patterns.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default [
'{{company.prefix}} {{name.female_first_name}}',
'{{company.prefix}} {{name.male_first_name}}',
'{{company.prefix}} {{name.male_last_name}}',
'{{company.prefix}} {{person.female_first_name}}',
'{{company.prefix}} {{person.male_first_name}}',
'{{company.prefix}} {{person.male_last_name}}',
'{{company.prefix}} {{company.suffix}}{{company.suffix}}',
'{{company.prefix}} {{company.suffix}}{{company.suffix}}{{company.suffix}}',
'{{company.prefix}} {{address.city_name}}{{company.suffix}}',
Expand Down
Loading

0 comments on commit 20f2236

Please sign in to comment.