Skip to content

Commit

Permalink
refactor(location)!: add aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Oct 18, 2022
1 parent 9151c0c commit c8ebc70
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/api-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Run 'pnpm run generate:api-docs' to update
export const apiPages = [
{ text: 'Overview', link: '/api/' },
{ text: 'Address', link: '/api/address.html' },
{ text: 'Animal', link: '/api/animal.html' },
{ text: 'Color', link: '/api/color.html' },
{ text: 'Commerce', link: '/api/commerce.html' },
Expand All @@ -16,6 +15,7 @@ export const apiPages = [
{ text: 'Helpers', link: '/api/helpers.html' },
{ text: 'Image', link: '/api/image.html' },
{ text: 'Internet', link: '/api/internet.html' },
{ text: 'Location', link: '/api/location.html' },
{ text: 'Lorem', link: '/api/lorem.html' },
{ text: 'Music', link: '/api/music.html' },
{ text: 'Person', link: '/api/person.html' },
Expand Down
4 changes: 3 additions & 1 deletion scripts/apidoc/moduleMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function extractModuleName(module: DeclarationReflection): string {
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') {
if (name === 'AddressModule') {
return 'Location';
} else if (name === 'NameModule') {
return 'Person';
}
return name.replace(/Module$/, '');
Expand Down
30 changes: 25 additions & 5 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { HackerModule } from './modules/hacker';
import { HelpersModule } from './modules/helpers';
import { ImageModule } from './modules/image';
import { InternetModule } from './modules/internet';
import type { LocationModule as AddressModule } from './modules/location';
import { LocationModule } from './modules/location';
import { LoremModule } from './modules/lorem';
import { MusicModule } from './modules/music';
Expand Down Expand Up @@ -109,13 +110,24 @@ export class Faker {
readonly word: WordModule = new WordModule(this);

// Aliases
/** @deprecated Use {@link location} instead */
get address(): AddressModule {
deprecated({
deprecated: 'faker.address',
proposed: 'faker.location',
since: '8.0',
until: '10.0',
});
return this.location;
}

/** @deprecated Use {@link person} instead */
get name(): NameModule {
deprecated({
deprecated: 'faker.name',
proposed: 'faker.person',
since: '8.0.0',
until: '10.0.0',
since: '8.0',
until: '10.0',
});
return this.person;
}
Expand Down Expand Up @@ -175,13 +187,21 @@ export class Faker {
return new Proxy({} as LocaleDefinition, {
get(target: LocaleDefinition, module: string): unknown {
// Support aliases
if (module === 'name') {
if (module === 'address') {
module = 'location';
deprecated({
deprecated: `faker.helpers.fake('{{address.*}}') or faker.definitions.address`,
proposed: `faker.helpers.fake('{{location.*}}') or faker.definitions.location`,
since: '8.0',
until: '10.0',
});
} else 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',
since: '8.0',
until: '10.0',
});
}

Expand Down

0 comments on commit c8ebc70

Please sign in to comment.