Skip to content

Commit 20f2236

Browse files
Shinigami92ST-DDT
andauthored
refactor(person)!: rename name module (#1445)
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
1 parent 90b9c5c commit 20f2236

593 files changed

Lines changed: 1173 additions & 1112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ The API covers the following modules:
8888
| Internet | `faker.internet.domainName()` | muddy-neuropathologist.net |
8989
| Lorem | `faker.lorem.paragraph()` | Porro nulla id vero perspiciatis nulla nihil. ... |
9090
| Music | `faker.music.genre()` | R&B |
91-
| Name | `faker.name.firstName()` | Cameron |
91+
| Person | `faker.person.firstName()` | Cameron |
9292
| Phone | `faker.phone.phoneNumber()` | +1 291-299-0192 |
9393
| Random | `faker.random.locale()` | fr_CA |
9494
| Science | `faker.science.unit()` | `{ name: 'meter', symbol: 'm' }` |
@@ -103,7 +103,7 @@ Faker contains a generator method `faker.helpers.fake` for combining faker API m
103103
```ts
104104
console.log(
105105
faker.helpers.fake(
106-
'Hello {{name.prefix}} {{name.lastName}}, how are you today?'
106+
'Hello {{person.prefix}} {{person.lastName}}, how are you today?'
107107
)
108108
);
109109
```

docs/.vitepress/api-pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const apiPages = [
1818
{ text: 'Internet', link: '/api/internet.html' },
1919
{ text: 'Lorem', link: '/api/lorem.html' },
2020
{ text: 'Music', link: '/api/music.html' },
21-
{ text: 'Name', link: '/api/name.html' },
21+
{ text: 'Person', link: '/api/person.html' },
2222
{ text: 'Phone', link: '/api/phone.html' },
2323
{ text: 'Random', link: '/api/random.html' },
2424
{ text: 'Science', link: '/api/science.html' },

docs/guide/usage.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Using Faker is as easy as importing it from `@faker-js/faker`.
77
```js
88
import { faker } from '@faker-js/faker';
99

10-
const randomName = faker.name.fullName(); // Rowan Nikolaus
10+
const randomName = faker.person.fullName(); // Rowan Nikolaus
1111
const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
1212
```
1313

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

19-
const randomName = faker.name.fullName(); // Rowan Nikolaus
19+
const randomName = faker.person.fullName(); // Rowan Nikolaus
2020
const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
2121
```
2222

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

46-
const randomName = faker.name.findName(); // Willie Bahringer
46+
const randomName = faker.person.findName(); // Willie Bahringer
4747
const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com
4848
```
4949

@@ -120,9 +120,9 @@ function createRandomUser(): User {
120120
avatar: faker.image.avatar(),
121121
birthday: faker.date.birthdate(),
122122
email: faker.internet.email(),
123-
firstName: faker.name.firstName(),
124-
lastName: faker.name.lastName(),
125-
sex: faker.name.sexType(),
123+
firstName: faker.person.firstName(),
124+
lastName: faker.person.lastName(),
125+
sex: faker.person.sexType(),
126126
subscriptionTier: faker.helpers.arrayElement(['free', 'basic', 'business']),
127127
};
128128
}
@@ -142,9 +142,9 @@ Let's refactor our current code:
142142
import { faker } from '@faker-js/faker';
143143

144144
function createRandomUser(): User {
145-
const sex = this.faker.name.sexType();
146-
const firstName = faker.name.firstName(sex);
147-
const lastName = faker.name.lastName();
145+
const sex = this.faker.person.sexType();
146+
const firstName = faker.person.firstName(sex);
147+
const lastName = faker.person.lastName();
148148
const email = faker.internet.email(firstName, lastName);
149149

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

181181
function createRandomUser(): User {
182-
const sex = this.faker.name.sexType();
183-
const firstName = faker.name.firstName(sex);
184-
const lastName = faker.name.lastName();
182+
const sex = this.faker.person.sexType();
183+
const firstName = faker.person.firstName(sex);
184+
const lastName = faker.person.lastName();
185185
const email = faker.helpers.unique(faker.internet.email, [
186186
firstName,
187187
lastName,

scripts/apidoc/moduleMethods.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ export function processModuleMethods(project: ProjectReflection): PageIndex {
3838
}
3939

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

4450
function extractModuleFieldName(module: DeclarationReflection): string {

scripts/generateLocales.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const definitionsTypes: DefinitionsType = {
5757
internet: 'InternetDefinitions',
5858
lorem: 'LoremDefinitions',
5959
music: 'MusicDefinitions',
60-
name: 'NameDefinitions',
60+
person: 'PersonDefinitions',
6161
phone_number: 'PhoneNumberDefinitions',
6262
science: 'ScienceDefinitions',
6363
system: 'SystemDefinitions',

src/definitions/definitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { HackerDefinitions } from './hacker';
1010
import type { InternetDefinitions } from './internet';
1111
import type { LoremDefinitions } from './lorem';
1212
import type { MusicDefinitions } from './music';
13-
import type { NameDefinitions } from './name';
13+
import type { PersonDefinitions } from './person';
1414
import type { PhoneNumberDefinitions } from './phone_number';
1515
import type { ScienceDefinitions } from './science';
1616
import type { SystemDefinitions } from './system';
@@ -38,7 +38,7 @@ export interface Definitions {
3838
internet: InternetDefinitions;
3939
lorem: LoremDefinitions;
4040
music: MusicDefinitions;
41-
name: NameDefinitions;
41+
person: PersonDefinitions;
4242
phone_number: PhoneNumberDefinitions;
4343
science: ScienceDefinitions;
4444
system: SystemDefinitions;

src/definitions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type { HackerDefinitions } from './hacker';
1717
export type { InternetDefinitions } from './internet';
1818
export type { LoremDefinitions } from './lorem';
1919
export type { MusicDefinitions } from './music';
20-
export type { NameDefinitions, NameTitleDefinitions } from './name';
20+
export type { PersonDefinitions, PersonTitleDefinitions } from './person';
2121
export type { PhoneNumberDefinitions } from './phone_number';
2222
export type { ScienceDefinitions } from './science';
2323
export type {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
33
/**
44
* The possible definitions related to people's names.
55
*/
6-
export type NameDefinitions = LocaleEntry<{
6+
export type PersonDefinitions = LocaleEntry<{
77
gender: string[];
88
sex: string[];
99

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

33-
title: NameTitleDefinitions;
33+
title: PersonTitleDefinitions;
3434
}>;
3535

3636
/**
3737
* The possible definitions related to people's titles.
3838
*/
39-
export interface NameTitleDefinitions {
39+
export interface PersonTitleDefinitions {
4040
descriptor?: string[];
4141
job: string[];
4242
level?: string[];

src/faker.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LocaleDefinition } from './definitions';
22
import { FakerError } from './errors/faker-error';
3+
import { deprecated } from './internal/deprecated';
34
import { MersenneModule } from './internal/mersenne/mersenne';
45
import type { KnownLocale } from './locales';
56
import { AddressModule } from './modules/address';
@@ -18,7 +19,8 @@ import { ImageModule } from './modules/image';
1819
import { InternetModule } from './modules/internet';
1920
import { LoremModule } from './modules/lorem';
2021
import { MusicModule } from './modules/music';
21-
import { NameModule } from './modules/name';
22+
import type { PersonModule as NameModule } from './modules/person';
23+
import { PersonModule } from './modules/person';
2224
import { PhoneModule } from './modules/phone';
2325
import { RandomModule } from './modules/random';
2426
import { ScienceModule } from './modules/science';
@@ -97,13 +99,25 @@ export class Faker {
9799
readonly internet: InternetModule = new InternetModule(this);
98100
readonly lorem: LoremModule = new LoremModule(this);
99101
readonly music: MusicModule = new MusicModule(this);
100-
readonly name: NameModule = new NameModule(this);
102+
readonly person: PersonModule = new PersonModule(this);
101103
readonly phone: PhoneModule = new PhoneModule(this);
102104
readonly science: ScienceModule = new ScienceModule(this);
103105
readonly system: SystemModule = new SystemModule(this);
104106
readonly vehicle: VehicleModule = new VehicleModule(this);
105107
readonly word: WordModule = new WordModule(this);
106108

109+
// Aliases
110+
/** @deprecated Use {@link person} instead */
111+
get name(): NameModule {
112+
deprecated({
113+
deprecated: 'faker.name',
114+
proposed: 'faker.person',
115+
since: '8.0.0',
116+
until: '10.0.0',
117+
});
118+
return this.person;
119+
}
120+
107121
constructor(opts: FakerOptions) {
108122
if (!opts) {
109123
throw new FakerError(
@@ -158,6 +172,17 @@ export class Faker {
158172

159173
return new Proxy({} as LocaleDefinition, {
160174
get(target: LocaleDefinition, module: string): unknown {
175+
// Support aliases
176+
if (module === 'name') {
177+
module = 'person';
178+
deprecated({
179+
deprecated: `faker.helpers.fake('{{name.*}}') or faker.definitions.name`,
180+
proposed: `faker.helpers.fake('{{person.*}}') or faker.definitions.person`,
181+
since: '8.0.0',
182+
until: '10.0.0',
183+
});
184+
}
185+
161186
let result = target[module];
162187
if (result) {
163188
return result;

src/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ export type {
1818
LocaleDefinition,
1919
LoremDefinitions,
2020
MusicDefinitions,
21-
NameDefinitions,
22-
NameTitleDefinitions,
21+
/** @deprecated Use PersonDefinitions instead */
22+
PersonDefinitions as NameDefinitions,
23+
PersonDefinitions,
24+
/** @deprecated Use PersonTitleDefinitions instead */
25+
PersonTitleDefinitions as NameTitleDefinitions,
26+
PersonTitleDefinitions,
2327
PhoneNumberDefinitions,
2428
ScienceDefinitions,
2529
SystemDefinitions,
@@ -53,8 +57,13 @@ export type { ImageModule } from './modules/image';
5357
export type { InternetModule } from './modules/internet';
5458
export type { LoremModule } from './modules/lorem';
5559
export type { MusicModule } from './modules/music';
56-
export { Sex } from './modules/name';
57-
export type { NameModule, SexType } from './modules/name';
60+
export { Sex } from './modules/person';
61+
export type {
62+
/** @deprecated Use PersonModule instead */
63+
PersonModule as NameModule,
64+
PersonModule,
65+
SexType,
66+
} from './modules/person';
5867
export type { PhoneModule } from './modules/phone';
5968
export type { RandomModule } from './modules/random';
6069
export type { ChemicalElement, ScienceModule, Unit } from './modules/science';

0 commit comments

Comments
 (0)