aboutsummaryrefslogtreecommitdiff
path: root/src/modules/random
diff options
context:
space:
mode:
authorShinigami <[email protected]>2024-02-25 10:36:31 +0100
committerGitHub <[email protected]>2024-02-25 09:36:31 +0000
commit64ff107b8a9cd0965a67f00fd30cded144c02fd6 (patch)
treec727728fd3c98c2abac39bdd9868ada5d430d01d /src/modules/random
parenta9dc7017b4a2b2bf79c42fe947de6029fae5e937 (diff)
downloadfaker-64ff107b8a9cd0965a67f00fd30cded144c02fd6.tar.xz
faker-64ff107b8a9cd0965a67f00fd30cded144c02fd6.zip
refactor(random)!: remove deprecated random module (#2678)
Diffstat (limited to 'src/modules/random')
-rw-r--r--src/modules/random/index.ts374
1 files changed, 0 insertions, 374 deletions
diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts
deleted file mode 100644
index 371c810e..00000000
--- a/src/modules/random/index.ts
+++ /dev/null
@@ -1,374 +0,0 @@
-import { FakerError } from '../../errors/faker-error';
-import { deprecated } from '../../internal/deprecated';
-import { ModuleBase } from '../../internal/module-base';
-import type { LiteralUnion } from '../../utils/types';
-import type {
- AlphaChar,
- AlphaNumericChar,
- Casing,
- NumericChar,
-} from '../string';
-
-/**
- * Generates random values of different kinds.
- *
- * @deprecated Use the modules specific to the type of data you want to generate instead.
- */
-export class RandomModule extends ModuleBase {
- /**
- * Returns a random word.
- *
- * @see faker.lorem.word(): For generating a random placeholder word.
- * @see faker.word.sample(): For generating a random real word.
- *
- * @example
- * faker.random.word() // 'Seamless'
- *
- * @since 3.1.0
- *
- * @deprecated Use `faker.lorem.word()` or `faker.word.sample()` instead.
- */
- word(): string {
- deprecated({
- deprecated: 'faker.random.word()',
- proposed: 'faker.lorem.word() or faker.word.sample()',
- since: '8.0',
- until: '9.0',
- });
-
- const wordMethods = [
- () => this.faker.location.cardinalDirection(),
- this.faker.location.country,
- this.faker.location.county,
- () => this.faker.location.direction(),
- () => this.faker.location.ordinalDirection(),
- this.faker.location.state,
- this.faker.location.street,
-
- this.faker.color.human,
-
- this.faker.commerce.department,
- this.faker.commerce.product,
- this.faker.commerce.productAdjective,
- this.faker.commerce.productMaterial,
- this.faker.commerce.productName,
-
- this.faker.company.buzzAdjective,
- this.faker.company.buzzNoun,
- this.faker.company.buzzVerb,
- this.faker.company.catchPhraseAdjective,
- this.faker.company.catchPhraseDescriptor,
- this.faker.company.catchPhraseNoun,
-
- this.faker.finance.accountName,
- this.faker.finance.currencyName,
- this.faker.finance.transactionType,
-
- this.faker.hacker.abbreviation,
- this.faker.hacker.adjective,
- this.faker.hacker.ingverb,
- this.faker.hacker.noun,
- this.faker.hacker.verb,
-
- this.faker.lorem.word,
-
- this.faker.music.genre,
-
- this.faker.person.gender,
- this.faker.person.jobArea,
- this.faker.person.jobDescriptor,
- this.faker.person.jobTitle,
- this.faker.person.jobType,
- this.faker.person.sex,
-
- () => this.faker.science.chemicalElement().name,
- () => this.faker.science.unit().name,
-
- this.faker.vehicle.bicycle,
- this.faker.vehicle.color,
- this.faker.vehicle.fuel,
- this.faker.vehicle.manufacturer,
- this.faker.vehicle.type,
-
- this.faker.word.adjective,
- this.faker.word.adverb,
- this.faker.word.conjunction,
- this.faker.word.interjection,
- this.faker.word.noun,
- this.faker.word.preposition,
- this.faker.word.verb,
- ];
-
- const bannedChars = [
- '!',
- '#',
- '%',
- '&',
- '*',
- ')',
- '(',
- '+',
- '=',
- '.',
- '<',
- '>',
- '{',
- '}',
- '[',
- ']',
- ':',
- ';',
- "'",
- '"',
- '_',
- '-',
- ];
- let result = '';
-
- let iteration = 0;
-
- do {
- // randomly pick from the many faker methods that can generate words
- const randomWordMethod = this.faker.helpers.arrayElement(wordMethods);
-
- try {
- result = randomWordMethod();
- } catch {
- // catch missing locale data potentially required by randomWordMethod
- iteration++;
-
- if (iteration > 100) {
- throw new FakerError(
- 'No matching word data available for the current locale'
- );
- }
-
- continue;
- }
- } while (!result || bannedChars.some((char) => result.includes(char)));
-
- return this.faker.helpers.arrayElement(result.split(' '));
- }
-
- /**
- * Returns a string with a given number of random words.
- *
- * @param count The number or range of words. Defaults to a random value between `1` and `3`.
- * @param count.min The minimum number of words. Defaults to `1`.
- * @param count.max The maximum number of words. Defaults to `3`.
- *
- * @see faker.lorem.words(): For generating a sequence of random placeholder words.
- * @see faker.word.words(): For generating a sequence of random real words.
- *
- * @example
- * faker.random.words() // 'neural'
- * faker.random.words(5) // 'copy Handcrafted bus client-server Point'
- * faker.random.words({ min: 3, max: 5 }) // 'cool sticky Borders'
- *
- * @since 3.1.0
- *
- * @deprecated Use `faker.lorem.words()` or `faker.word.words()` instead.
- */
- words(
- count:
- | number
- | {
- /**
- * The minimum number of words.
- */
- min: number;
- /**
- * The maximum number of words.
- */
- max: number;
- } = { min: 1, max: 3 }
- ): string {
- deprecated({
- deprecated: 'faker.random.words()',
- proposed: 'faker.lorem.words() or faker.word.words()',
- since: '8.0',
- until: '9.0',
- });
-
- // eslint-disable-next-line deprecation/deprecation
- return this.faker.helpers.multiple(this.word, { count }).join(' ');
- }
-
- /**
- * Do NOT use. This property has been removed.
- *
- * @example
- * faker.helpers.objectKey(allLocales)
- * faker.helpers.objectValue(allFakers)
- *
- * @since 3.1.0
- *
- * @deprecated Use `faker.helpers.objectKey(allLocales/allFakers)` instead.
- */
- private locale(): never {
- // We cannot invoke this ourselves, because this would link to all locale data and increase the bundle size by a lot.
- throw new FakerError(
- 'This method has been removed. Please use `faker.helpers.objectKey(allLocales/allFakers)` instead.'
- );
- }
-
- /**
- * Generating a string consisting of letters in the English alphabet.
- *
- * @param options Either the number of characters or an options instance.
- * @param options.count The number of characters to generate. Defaults to `1`.
- * @param options.casing The casing of the characters. Defaults to `'mixed'`.
- * @param options.bannedChars An array with characters to exclude. Defaults to `[]`.
- *
- * @see faker.string.alpha(): For the replacement method.
- *
- * @example
- * faker.random.alpha() // 'b'
- * faker.random.alpha(10) // 'qccrabobaf'
- * faker.random.alpha({ count: 5, casing: 'upper', bannedChars: ['A'] }) // 'DTCIC'
- *
- * @since 5.0.0
- *
- * @deprecated Use `faker.string.alpha()` instead.
- */
- alpha(
- options:
- | number
- | {
- /**
- * The number of characters to generate.
- *
- * @default 1
- */
- count?: number;
- /**
- * The casing of the characters.
- *
- * @default 'mixed'
- */
- casing?: Casing;
- /**
- * An array with characters to exclude.
- *
- * @default []
- */
- bannedChars?: ReadonlyArray<LiteralUnion<AlphaChar>> | string;
- } = {}
- ): string {
- deprecated({
- deprecated: 'faker.random.alpha()',
- proposed: 'faker.string.alpha()',
- since: '8.0',
- until: '9.0',
- });
- if (typeof options === 'number') {
- return this.faker.string.alpha(options);
- }
-
- return this.faker.string.alpha({
- length: options.count,
- casing: options.casing,
- exclude: options.bannedChars,
- });
- }
-
- /**
- * Generating a string consisting of alpha characters and digits.
- *
- * @param count The number of characters and digits to generate. Defaults to `1`.
- * @param options The options to use.
- * @param options.casing The casing of the characters. Defaults to `'lower'`.
- * @param options.bannedChars An array of characters and digits which should be banned in the generated string. Defaults to `[]`.
- *
- * @see faker.string.alphanumeric(): For the replacement method.
- *
- * @example
- * faker.random.alphaNumeric() // '2'
- * faker.random.alphaNumeric(5) // '3e5v7'
- * faker.random.alphaNumeric(5, { bannedChars: ["a"] }) // 'xszlm'
- *
- * @since 3.1.0
- *
- * @deprecated Use `faker.string.alphanumeric()` instead.
- */
- alphaNumeric(
- count: number = 1,
- options: {
- /**
- * The casing of the characters.
- *
- * @default 'lower'
- */
- casing?: Casing;
- /**
- * An array of characters and digits which should be banned in the generated string.
- *
- * @default []
- */
- bannedChars?: ReadonlyArray<LiteralUnion<AlphaNumericChar>> | string;
- } = {}
- ): string {
- deprecated({
- deprecated: 'faker.random.alphaNumeric()',
- proposed: 'faker.string.alphanumeric()',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.string.alphanumeric({
- length: count,
- exclude: options.bannedChars,
- casing: options.casing,
- });
- }
-
- /**
- * Generates a given length string of digits.
- *
- * @param length The number of digits to generate. Defaults to `1`.
- * @param options The options to use.
- * @param options.allowLeadingZeros Whether leading zeros are allowed or not. Defaults to `true`.
- * @param options.bannedDigits An array of digits which should be banned in the generated string. Defaults to `[]`.
- *
- * @see faker.string.numeric(): For the replacement method.
- *
- * @example
- * faker.random.numeric() // '2'
- * faker.random.numeric(5) // '31507'
- * faker.random.numeric(42) // '00434563150765416546479875435481513188548'
- * faker.random.numeric(42, { allowLeadingZeros: true }) // '00564846278453876543517840713421451546115'
- * faker.random.numeric(6, { bannedDigits: ['0'] }) // '943228'
- *
- * @since 6.3.0
- *
- * @deprecated Use `faker.string.numeric()` instead.
- */
- numeric(
- length: number = 1,
- options: {
- /**
- * Whether leading zeros are allowed or not.
- *
- * @default true
- */
- allowLeadingZeros?: boolean;
- /**
- * An array of digits which should be banned in the generated string.
- *
- * @default []
- */
- bannedDigits?: ReadonlyArray<LiteralUnion<NumericChar>> | string;
- } = {}
- ): string {
- deprecated({
- deprecated: 'faker.random.numeric()',
- proposed: 'faker.string.numeric()',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.string.numeric({
- length,
- allowLeadingZeros: options.allowLeadingZeros,
- exclude: options.bannedDigits,
- });
- }
-}