Skip to content

Commit

Permalink
refactor!: remove v8 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Feb 24, 2024
1 parent 4382fd9 commit b7b10a3
Show file tree
Hide file tree
Showing 44 changed files with 473 additions and 7,503 deletions.
1 change: 0 additions & 1 deletion docs/.vitepress/api-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const apiPages = [
{ text: 'Number', link: '/api/number.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' },
{ text: 'String', link: '/api/string.html' },
{ text: 'System', link: '/api/system.html' },
Expand Down
7 changes: 0 additions & 7 deletions src/definitions/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,4 @@ export type CompanyDefinition = LocaleEntry<{
* Catchphrase nouns that can be displayed to an end user.
*/
noun: string[];

/**
* Company/Business entity types.
*
* @deprecated Use `faker.company.name` instead.
*/
suffix: string[];
}>;
251 changes: 2 additions & 249 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { MusicModule } from './modules/music';
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';
import { SystemModule } from './modules/system';
import { VehicleModule } from './modules/vehicle';
Expand Down Expand Up @@ -62,12 +61,6 @@ export class Faker extends SimpleFaker {
readonly rawDefinitions: LocaleDefinition;
readonly definitions: LocaleProxy;

/**
* @deprecated Use the modules specific to the type of data you want to generate instead.
*/
// eslint-disable-next-line deprecation/deprecation
readonly random: RandomModule = new RandomModule(this);

readonly airline: AirlineModule = new AirlineModule(this);
readonly animal: AnimalModule = new AnimalModule(this);
readonly color: ColorModule = new ColorModule(this);
Expand Down Expand Up @@ -162,170 +155,9 @@ export class Faker extends SimpleFaker {
* @default generateMersenne32Randomizer()
*/
randomizer?: Randomizer;
});
/**
* Creates a new instance of Faker.
*
* In most cases you should use one of the prebuilt Faker instances instead of the constructor, for example `fakerDE`, `fakerFR`, ...
*
* You only need to use the constructor if you need custom fallback logic or a custom locale.
*
* For more information see our [Localization Guide](https://fakerjs.dev/guide/localization.html).
*
* @param options The options to use.
* @param options.locales The locale data to use.
* @param options.locale The name of the main locale to use.
* @param options.localeFallback The name of the fallback locale to use.
*
* @example
* import { Faker, allLocales } from '@faker-js/faker';
* // const { Faker, allLocales } = require('@faker-js/faker');
*
* new Faker({ locales: allLocales });
*
* @since 6.0.0
*
* @deprecated Use `new Faker({ locale: [locale, localeFallback] })` instead.
*/
constructor(options: {
/**
* The locale data to use for this instance.
*
* @deprecated Use `new Faker({ locale: [locale, localeFallback] })` instead.
*/
locales: Record<string, LocaleDefinition>;
/**
* The name of the main locale to use.
*
* @default 'en'
*
* @deprecated Use `new Faker({ locale: [locale, localeFallback] })` instead.
*/
locale?: string;
/**
* The name of the fallback locale to use.
*
* @default 'en'
*
* @deprecated Use `new Faker({ locale: [locale, localeFallback] })` instead.
*/
localeFallback?: string;
});
// This is somehow required for `ConstructorParameters<typeof Faker>[0]` to work
/**
* Creates a new instance of Faker.
*
* In most cases you should use one of the prebuilt Faker instances instead of the constructor, for example `fakerDE`, `fakerFR`, ...
*
* You only need to use the constructor if you need custom fallback logic or a custom locale.
*
* For more information see our [Localization Guide](https://fakerjs.dev/guide/localization.html).
*
* @param options The options to use.
* @param options.locale The locale data to use or the name of the main locale.
* @param options.locales The locale data to use.
* @param options.localeFallback The name of the fallback locale to use.
* @param options.randomizer The Randomizer to use.
* Specify this only if you want to use it to achieve a specific goal,
* such as sharing the same random generator with other instances/tools.
* Defaults to faker's Mersenne Twister based pseudo random number generator.
*
* @example
* import { Faker, es } from '@faker-js/faker';
* // const { Faker, es } = require('@faker-js/faker');
*
* // create a Faker instance with only es data and no en fallback (=> smaller bundle size)
* const customFaker = new Faker({ locale: [es] });
*
* customFaker.person.firstName(); // 'Javier'
* customFaker.person.lastName(); // 'Ocampo Corrales'
*
* customFaker.music.genre(); // throws Error as this data is not available in `es`
*
* @since 8.0.0
*/
constructor(
options:
| {
/**
* The locale data to use for this instance.
* If an array is provided, the first locale that has a definition for a given property will be used.
*
* @see mergeLocales(): For more information about how the locales are merged.
*/
locale: LocaleDefinition | LocaleDefinition[];

/**
* The Randomizer to use.
* Specify this only if you want to use it to achieve a specific goal,
* such as sharing the same random generator with other instances/tools.
*
* @default generateMersenne32Randomizer()
*/
randomizer?: Randomizer;
}
| {
/**
* The locale data to use for this instance.
*
* @deprecated Use `new Faker({ locale: [locale, localeFallback] })` instead.
*/
locales: Record<string, LocaleDefinition>;
/**
* The name of the main locale to use.
*
* @default 'en'
*
* @deprecated Use `new Faker({ locale: [locale, localeFallback] })` instead.
*/
locale?: string;
/**
* The name of the fallback locale to use.
*
* @default 'en'
*
* @deprecated Use `new Faker({ locale: [locale, localeFallback] })` instead.
*/
localeFallback?: string;
}
);
constructor(
options:
| {
locale: LocaleDefinition | LocaleDefinition[];
randomizer?: Randomizer;
}
| {
locales: Record<string, LocaleDefinition>;
locale?: string;
localeFallback?: string;
randomizer?: Randomizer;
}
) {
}) {
super({ randomizer: options.randomizer });

const { locales } = options as {
locales: Record<string, LocaleDefinition>;
};

if (locales != null) {
deprecated({
deprecated:
"new Faker({ locales: {a, b}, locale: 'a', localeFallback: 'b' })",
proposed:
'new Faker({ locale: [a, b, ...] }) or new Faker({ locale: a })',
since: '8.0',
until: '9.0',
});
const { locale = 'en', localeFallback = 'en' } = options as {
locale: string;
localeFallback: string;
};
options = {
locale: [locales[locale], locales[localeFallback]],
};
}

let { locale } = options;

if (Array.isArray(locale)) {
Expand All @@ -338,7 +170,7 @@ export class Faker extends SimpleFaker {
locale = mergeLocales(locale);
}

this.rawDefinitions = locale as LocaleDefinition;
this.rawDefinitions = locale;
this.definitions = createLocaleProxy(this.rawDefinitions);
}

Expand All @@ -356,85 +188,6 @@ export class Faker extends SimpleFaker {
getMetadata(): MetadataDefinition {
return this.rawDefinitions.metadata ?? {};
}

// Pure JS backwards compatibility

/**
* Do NOT use. This property has been removed.
*
* @deprecated Use the constructor instead.
*/
private get locales(): never {
throw new FakerError(
'The locales property has been removed. Please use the constructor instead.'
);
}

/**
* Do NOT use. This property has been removed.
*
* @deprecated Use the constructor instead.
*/
private set locales(value: never) {
throw new FakerError(
'The locales property has been removed. Please use the constructor instead.'
);
}

/**
* Do NOT use. This property has been removed.
*
* @deprecated Use the constructor instead.
*/
private get locale(): never {
throw new FakerError(
'The locale property has been removed. Please use the constructor instead.'
);
}

/**
* Do NOT use. This property has been removed.
*
* @deprecated Use the constructor instead.
*/
private set locale(value: never) {
throw new FakerError(
'The locale property has been removed. Please use the constructor instead.'
);
}

/**
* Do NOT use. This property has been removed.
*
* @deprecated Use the constructor instead.
*/
private get localeFallback(): never {
throw new FakerError(
'The localeFallback property has been removed. Please use the constructor instead.'
);
}

/**
* Do NOT use. This property has been removed.
*
* @deprecated Use the constructor instead.
*/
private set localeFallback(value: never) {
throw new FakerError(
'The localeFallback property has been removed. Please use the constructor instead.'
);
}

/**
* Do NOT use. This property has been removed.
*
* @deprecated Use the constructor instead.
*/
private setLocale(): never {
throw new FakerError(
'This method has been removed. Please use the constructor instead.'
);
}
}

export type FakerOptions = ConstructorParameters<typeof Faker>[0];
Loading

0 comments on commit b7b10a3

Please sign in to comment.