🤖 Merge PR #47301 [faker.js] updates for v5 by @TastefulElk

* [faker.js] updates for v5

* [faker.js] add missing locales

* [faker.js] add tests for v5 changes

* [faker.js] style cleanup

* [faker.js] fix indentation
This commit is contained in:
Sebastian Pettersson 2020-09-24 08:04:34 +02:00 committed by GitHub
parent deea912e89
commit e98fe25b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 240 additions and 68 deletions

View File

@ -11,6 +11,7 @@ faker.seedValue === undefined;
faker.seed(123);
faker.seedValue === 123;
resultStr = faker.address.zipCodeByState('foo');
resultStr = faker.address.zipCode();
resultStr = faker.address.zipCode('###');
resultStr = faker.address.city();
@ -26,11 +27,22 @@ resultStr = faker.address.secondaryAddress();
resultStr = faker.address.county();
resultStr = faker.address.country();
resultStr = faker.address.countryCode();
resultStr = faker.address.countryCode('foo');
resultStr = faker.address.state();
resultStr = faker.address.state(false);
resultStr = faker.address.stateAbbr();
resultStr = faker.address.latitude();
resultStr = faker.address.latitude(0, 0);
resultStr = faker.address.longitude();
resultStr = faker.address.longitude(0, 0);
resultStr = faker.address.direction();
resultStr = faker.address.direction(true);
resultStr = faker.address.cardinalDirection();
resultStr = faker.address.cardinalDirection(true);
resultStr = faker.address.ordinalDirection();
resultStr = faker.address.ordinalDirection(true);
resultStr = faker.address.nearbyGPSCoordinate();
resultStr = faker.address.nearbyGPSCoordinate('foo', 0, true);
resultStr = faker.commerce.color();
resultStr = faker.commerce.department();
@ -40,6 +52,7 @@ resultStr = faker.commerce.price(0, 0, 0, '#');
resultStr = faker.commerce.productAdjective();
resultStr = faker.commerce.productMaterial();
resultStr = faker.commerce.product();
resultStr = faker.commerce.productDescription();
resultStrArr = faker.company.suffixes();
resultStr = faker.company.companyName();
@ -64,16 +77,18 @@ resultDate = faker.date.future();
resultDate = faker.date.between('foo', 'bar');
resultDate = faker.date.between(new Date(), new Date());
resultDate = faker.date.recent();
resultDate = faker.date.recent(100);
resultDate = faker.date.recent(100, new Date());
resultDate = faker.date.soon();
resultDate = faker.date.soon(100, new Date());
resultStr = faker.date.month();
resultStr = faker.date.month({
abbr: true,
context: true
context: true,
});
resultStr = faker.date.weekday();
resultStr = faker.date.weekday({
abbr: true,
context: true
context: true,
});
resultStr = faker.finance.account();
@ -112,8 +127,12 @@ resultStr = faker.helpers.randomize(['foo', 'bar', 'quux']);
resultStr = faker.helpers.slugify('foo bar quux');
resultStr = faker.helpers.replaceSymbolWithNumber('foo# bar#');
resultStr = faker.helpers.replaceSymbols('foo# bar? quux#');
resultStr = faker.helpers.replaceCreditCardSymbols();
resultStr = faker.helpers.replaceCreditCardSymbols('foo#', '*');
resultStr = faker.helpers.repeatString('foo', 2);
resultStr = faker.helpers.regexpStyleStringParse('foo');
resultStrArr = faker.helpers.shuffle(['foo', 'bar', 'quux']);
resultStr = faker.helpers.mustache('{{foo}}{{bar}}', {foo: 'x', bar: 'y'});
resultStr = faker.helpers.mustache('{{foo}}{{bar}}', { foo: 'x', bar: 'y' });
const card = faker.helpers.createCard();
resultStr = card.name;
@ -126,6 +145,39 @@ const userCard = faker.helpers.userCard();
resultStr = userCard.name;
resultStr = userCard.address.suite;
resultStr = faker.image.abstract();
resultStr = faker.image.abstract(0, 0);
resultStr = faker.image.animals();
resultStr = faker.image.animals(0, 0);
resultStr = faker.image.avatar();
resultStr = faker.image.business();
resultStr = faker.image.business(0, 0);
resultStr = faker.image.cats();
resultStr = faker.image.cats(0, 0);
resultStr = faker.image.city();
resultStr = faker.image.city(0, 0);
resultStr = faker.image.dataUri();
resultStr = faker.image.dataUri(0, 0, 'blue');
resultStr = faker.image.fashion();
resultStr = faker.image.fashion(0, 0);
resultStr = faker.image.food();
resultStr = faker.image.food(0, 0);
resultStr = faker.image.image();
resultStr = faker.image.imageUrl();
resultStr = faker.image.imageUrl(0, 0, 'cats', true, true);
resultStr = faker.image.nature();
resultStr = faker.image.nature(0, 0);
resultStr = faker.image.nightlife();
resultStr = faker.image.nightlife(0, 0);
resultStr = faker.image.people();
resultStr = faker.image.people(0, 0);
resultStr = faker.image.sports();
resultStr = faker.image.sports(0, 0);
resultStr = faker.image.technics();
resultStr = faker.image.technics(0, 0);
resultStr = faker.image.transport();
resultStr = faker.image.transport(0, 0);
resultStr = faker.internet.avatar();
resultStr = faker.internet.email();
resultStr = faker.internet.email('foo', 'bar', 'quux');
@ -141,10 +193,12 @@ resultStr = faker.internet.userAgent();
resultStr = faker.internet.color();
resultStr = faker.internet.color(0, 0, 0);
resultStr = faker.internet.mac();
resultStr = faker.internet.mac('#');
resultStr = faker.internet.password();
resultStr = faker.internet.password(0, false, '#', 'foo');
resultStr = faker.lorem.word();
resultStr = faker.lorem.word(0);
resultStr = faker.lorem.words();
resultStr = faker.lorem.words(0);
resultStr = faker.lorem.sentence();
@ -162,10 +216,14 @@ resultStr = faker.lorem.text(0);
resultStr = faker.lorem.lines();
resultStr = faker.lorem.lines(0);
resultStr = faker.music.genre();
resultStr = faker.name.firstName();
resultStr = faker.name.firstName(0);
resultStr = faker.name.lastName();
resultStr = faker.name.lastName(0);
resultStr = faker.name.middleName();
resultStr = faker.name.middleName(0);
resultStr = faker.name.findName();
resultStr = faker.name.findName('', '', 0);
resultStr = faker.name.jobTitle();
@ -187,37 +245,64 @@ resultNum = faker.random.number(0);
resultNum = faker.random.number({
min: 0,
max: 0,
precision: 0
precision: 0,
});
resultNum = faker.random.float();
resultNum = faker.random.float(0);
resultNum = faker.random.float({
min: 0,
max: 0,
precision: 0,
});
resultStr = faker.random.arrayElement();
resultStr = faker.random.arrayElement(['foo', 'bar', 'quux']);
resultStr = faker.random.arrayElement(['foo', 'bar', 'quux'] as ReadonlyArray<string>);
resultStrArr = faker.random.arrayElements();
resultStrArr = faker.random.arrayElements(['foo', 'bar', 'quux']);
(resultStrArr as ReadonlyArray<string>) = faker.random.arrayElements(['foo', 'bar', 'quux'] as ReadonlyArray<string>);
resultStr = faker.random.objectElement();
resultStr = faker.random.objectElement({foo: 'bar', field: 'foo'});
resultStr = faker.random.objectElement({ foo: 'bar', field: 'foo' });
resultStr = faker.random.uuid();
resultBool = faker.random.boolean();
resultStr = faker.random.word();
resultStr = faker.random.word("noun");
resultStr = faker.random.word('noun');
resultStr = faker.random.words();
resultStr = faker.random.words(0);
resultStr = faker.random.image();
resultStr = faker.random.locale();
resultStr = faker.random.alpha();
resultStr = faker.random.alpha({ count: 0, upcase: false });
resultStr = faker.random.alphaNumeric();
resultStr = faker.random.alphaNumeric(0);
resultStr = faker.random.hexaDecimal();
resultStr = faker.random.hexaDecimal(0);
resultStr = faker.system.fileName("foo", "bar");
resultStr = faker.system.commonFileName("foo", "bar");
resultStr = faker.system.fileName('foo', 'bar');
resultStr = faker.system.commonFileName('foo', 'bar');
resultStr = faker.system.mimeType();
resultStr = faker.system.commonFileType();
resultStr = faker.system.commonFileExt();
resultStr = faker.system.fileType();
resultStr = faker.system.fileExt("foo");
resultStr = faker.system.fileExt('foo');
resultStr = faker.system.directoryPath();
resultStr = faker.system.filePath();
resultStr = faker.system.semver();
resultDate = faker.time.recent();
resultDate = faker.time.recent('foo');
resultStr = faker.vehicle.vehicle();
resultStr = faker.vehicle.manufacturer();
resultStr = faker.vehicle.model();
resultStr = faker.vehicle.type();
resultStr = faker.vehicle.fuel();
resultStr = faker.vehicle.vin();
resultStr = faker.vehicle.color();
import fakerAz = require('faker/locale/az');
resultStr = fakerAz.name.firstName();
import fakerAr = require('faker/locale/ar');
resultStr = fakerAr.name.firstName();
import fakerCz = require('faker/locale/cz');
resultStr = fakerCz.name.firstName();
import fakerDe = require('faker/locale/de');
@ -230,6 +315,8 @@ import fakerEn = require('faker/locale/en');
resultStr = fakerEn.name.firstName();
import fakerEnAU = require('faker/locale/en_AU');
resultStr = fakerEnAU.name.firstName();
import fakerEnAuOcker = require('faker/locale/en_AU_ocker');
resultStr = fakerEnAuOcker.name.firstName();
import fakerEnBORK = require('faker/locale/en_BORK');
resultStr = fakerEnBORK.name.firstName();
import fakerEnCA = require('faker/locale/en_CA');
@ -242,8 +329,8 @@ import fakerEnIND = require('faker/locale/en_IND');
resultStr = fakerEnIND.name.firstName();
import fakerEnUS = require('faker/locale/en_US');
resultStr = fakerEnUS.name.firstName();
import fakerEnAuOcker = require('faker/locale/en_au_ocker');
resultStr = fakerEnAuOcker.name.firstName();
import fakerEnZA = require('faker/locale/en_ZA');
resultStr = fakerEnZA.name.firstName();
import fakerEs = require('faker/locale/es');
resultStr = fakerEs.name.firstName();
import fakerEsMX = require('faker/locale/es_MX');
@ -252,8 +339,12 @@ import fakerFa = require('faker/locale/fa');
resultStr = fakerFa.name.firstName();
import fakerFr = require('faker/locale/fr');
resultStr = fakerFr.name.firstName();
import fakerFi = require('faker/locale/fi');
resultStr = fakerFi.name.firstName();
import fakerFrCA = require('faker/locale/fr_CA');
resultStr = fakerFrCA.name.firstName();
import fakerFrCH = require('faker/locale/fr_CH');
resultStr = fakerFrCH.name.firstName();
import fakerGe = require('faker/locale/ge');
resultStr = fakerGe.name.firstName();
import fakerIdID = require('faker/locale/id_ID');
@ -270,10 +361,16 @@ import fakerNep = require('faker/locale/nep');
resultStr = fakerNep.name.firstName();
import fakerNl = require('faker/locale/nl');
resultStr = fakerNl.name.firstName();
import fakerNlBe = require('faker/locale/nl_BE');
resultStr = fakerNlBe.name.firstName();
import fakerPl = require('faker/locale/pl');
resultStr = fakerPl.name.firstName();
import fakerPtBR = require('faker/locale/pt_BR');
resultStr = fakerPtBR.name.firstName();
import fakerPtPT = require('faker/locale/pt_PT');
resultStr = fakerPtPT.name.firstName();
import fakerRo = require('faker/locale/ro');
resultStr = fakerRo.name.firstName();
import fakerRu = require('faker/locale/ru');
resultStr = fakerRu.name.firstName();
import fakerSk = require('faker/locale/sk');

187
types/faker/index.d.ts vendored
View File

@ -16,6 +16,7 @@ declare namespace Faker {
setLocale(locale: string): void;
address: {
zipCodeByState(state: string): string;
zipCode(format?: string): string;
city(format?: number): string;
cityPrefix(): string;
@ -27,11 +28,15 @@ declare namespace Faker {
secondaryAddress(): string;
county(): string;
country(): string;
countryCode(): string;
countryCode(alphaCode?: string): string;
state(useAbbr?: boolean): string;
stateAbbr(): string;
latitude(): string;
longitude(): string;
latitude(max?: number, min?: number, precision?: number): string;
longitude(max?: number, min?: number, precision?: number): string;
direction(useAbbr?: boolean): string;
cardinalDirection(useAbbr?: boolean): string;
ordinalDirection(useAbbr?: boolean): string;
nearbyGPSCoordinate(coordinate?: string, radius?: number, isMetric?: boolean): string;
};
commerce: {
@ -42,6 +47,7 @@ declare namespace Faker {
productAdjective(): string;
productMaterial(): string;
product(): string;
productDescription(): string;
};
company: {
@ -66,12 +72,13 @@ declare namespace Faker {
};
date: {
past(years?: number, refDate?: string|Date): Date;
future(years?: number, refDate?: string|Date): Date;
between(from: string|number|Date, to: string|Date): Date;
recent(days?: number): Date;
month(options?: { abbr?: boolean, context?: boolean }): string;
weekday(options?: { abbr?: boolean, context?: boolean }): string;
past(years?: number, refDate?: string | Date): Date;
future(years?: number, refDate?: string | Date): Date;
between(from: string | number | Date, to: string | Date): Date;
recent(days?: number, refDate?: string | Date): Date;
soon(days?: number, refDate?: string | Date): Date;
month(options?: { abbr?: boolean; context?: boolean }): string;
weekday(options?: { abbr?: boolean; context?: boolean }): string;
};
fake(str: string): string;
@ -87,15 +94,23 @@ declare namespace Faker {
currencyName(): string;
currencySymbol(): string;
bitcoinAddress(): string;
iban(formatted?: boolean): string;
bic(): string;
litecoinAddress(): string;
creditCardNumber(provider?: string): string;
creditCardCVV(): string;
ethereumAddress(): string;
iban(formatted?: boolean): string;
bic(): string;
transactionDescription(): string;
};
git: {
branch(): string;
commitEntry(options?: { merge: boolean }): string;
commitMessage(): string;
commitSha(): string;
shortSha(): string;
};
hacker: {
abbreviation(): string;
adjective(): string;
@ -111,9 +126,15 @@ declare namespace Faker {
slugify(string?: string): string;
replaceSymbolWithNumber(string?: string, symbol?: string): string;
replaceSymbols(string?: string): string;
replaceCreditCardSymbols(string?: string, symbol?: string): string;
repeatString(string: string, num?: number): string;
regexpStyleStringParse(string: string): string;
shuffle<T>(o: T[]): T[];
shuffle(): string[];
mustache(str: string, data: { [key: string]: string|((substring: string, ...args: any[]) => string) }): string;
mustache(
str: string,
data: { [key: string]: string | ((substring: string, ...args: any[]) => string) },
): string;
createCard(): Card;
contextualCard(): ContextualCard;
userCard(): UserCard;
@ -137,7 +158,7 @@ declare namespace Faker {
sports(width?: number, height?: number): string;
technics(width?: number, height?: number): string;
transport(width?: number, height?: number): string;
dataUri(width?: number, height?: number): string;
dataUri(width?: number, height?: number, color?: string): string;
};
internet: {
@ -154,12 +175,12 @@ declare namespace Faker {
ipv6(): string;
userAgent(): string;
color(baseRed255?: number, baseGreen255?: number, baseBlue255?: number): string;
mac(): string;
password(len?: number, memorable?: boolean, pattern?: string|RegExp, prefix?: string): string;
mac(sep?: string): string;
password(len?: number, memorable?: boolean, pattern?: string | RegExp, prefix?: string): string;
};
lorem: {
word(): string;
word(length?: number): string;
words(num?: number): string;
sentence(wordCount?: number, range?: number): string;
slug(wordCount?: number): string;
@ -173,6 +194,7 @@ declare namespace Faker {
name: {
firstName(gender?: number): string;
lastName(gender?: number): string;
middleName(gender?: number): string;
findName(firstName?: string, lastName?: string, gender?: number): string;
jobTitle(): string;
prefix(): string;
@ -183,6 +205,10 @@ declare namespace Faker {
jobType(): string;
};
music: {
genre(): string;
};
phone: {
phoneNumber(format?: string): string;
phoneNumberFormat(phoneFormatsArrayIndex?: number): string;
@ -191,11 +217,16 @@ declare namespace Faker {
random: {
number(max?: number): number;
number(options?: { min?: number, max?: number, precision?: number }): number;
number(options?: { min?: number; max?: number; precision?: number }): number;
float(max?: number): number;
float(options?: { min?: number; max?: number; precision?: number }): number;
arrayElement(): string;
arrayElement<T>(array: T[]): T;
arrayElement<T>(array: ReadonlyArray<T>): T;
objectElement(object?: { [key: string]: any }, field?: "key"): string;
arrayElements(count?: number): string[];
arrayElements<T>(array: T[], count?: number): T[];
arrayElements<T>(array: ReadonlyArray<T>, count?: number): ReadonlyArray<T>;
objectElement(object?: { [key: string]: any }, field?: 'key'): string;
objectElement<T>(object?: { [key: string]: T }, field?: any): T;
uuid(): string;
boolean(): boolean;
@ -203,7 +234,9 @@ declare namespace Faker {
words(count?: number): string;
image(): string;
locale(): string;
alpha(options?: { count?: number; upcase?: boolean }): string;
alphaNumeric(count?: number): string;
hexaDecimal(count?: number): string;
};
system: {
@ -219,8 +252,22 @@ declare namespace Faker {
semver(): string;
};
time: {
recent(outputType?: string): Date;
};
seed(value: number): void;
seedValue?: number;
vehicle: {
vehicle(): string;
manufacturer(): string;
model(): string;
type(): string;
fuel(): string;
vin(): string;
color(): string;
};
}
interface Card {
@ -306,154 +353,182 @@ declare namespace Faker {
}
}
declare module "faker" {
declare module 'faker' {
export = fakerStatic;
}
declare module "faker/locale/az" {
declare module 'faker/locale/az' {
export = fakerStatic;
}
declare module "faker/locale/cz" {
declare module 'faker/locale/ar' {
export = fakerStatic;
}
declare module "faker/locale/de" {
declare module 'faker/locale/cz' {
export = fakerStatic;
}
declare module "faker/locale/de_AT" {
declare module 'faker/locale/de' {
export = fakerStatic;
}
declare module "faker/locale/de_CH" {
declare module 'faker/locale/de_AT' {
export = fakerStatic;
}
declare module "faker/locale/en" {
declare module 'faker/locale/de_CH' {
export = fakerStatic;
}
declare module "faker/locale/en_AU" {
declare module 'faker/locale/en' {
export = fakerStatic;
}
declare module "faker/locale/en_BORK" {
declare module 'faker/locale/en_AU' {
export = fakerStatic;
}
declare module "faker/locale/en_CA" {
declare module 'faker/locale/en_AU_ocker' {
export = fakerStatic;
}
declare module "faker/locale/en_GB" {
declare module 'faker/locale/en_BORK' {
export = fakerStatic;
}
declare module "faker/locale/en_IE" {
declare module 'faker/locale/en_CA' {
export = fakerStatic;
}
declare module "faker/locale/en_IND" {
declare module 'faker/locale/en_GB' {
export = fakerStatic;
}
declare module "faker/locale/en_US" {
declare module 'faker/locale/en_IE' {
export = fakerStatic;
}
declare module "faker/locale/en_au_ocker" {
declare module 'faker/locale/en_IND' {
export = fakerStatic;
}
declare module "faker/locale/es" {
declare module 'faker/locale/en_US' {
export = fakerStatic;
}
declare module "faker/locale/es_MX" {
declare module 'faker/locale/en_ZA' {
export = fakerStatic;
}
declare module "faker/locale/fa" {
declare module 'faker/locale/es' {
export = fakerStatic;
}
declare module "faker/locale/fr" {
declare module 'faker/locale/es_MX' {
export = fakerStatic;
}
declare module "faker/locale/fr_CA" {
declare module 'faker/locale/fa' {
export = fakerStatic;
}
declare module "faker/locale/ge" {
declare module 'faker/locale/fi' {
export = fakerStatic;
}
declare module "faker/locale/id_ID" {
declare module 'faker/locale/fr' {
export = fakerStatic;
}
declare module "faker/locale/it" {
declare module 'faker/locale/fr_CA' {
export = fakerStatic;
}
declare module "faker/locale/ja" {
declare module 'faker/locale/fr_CH' {
export = fakerStatic;
}
declare module "faker/locale/ko" {
declare module 'faker/locale/ge' {
export = fakerStatic;
}
declare module "faker/locale/nb_NO" {
declare module 'faker/locale/id_ID' {
export = fakerStatic;
}
declare module "faker/locale/nep" {
declare module 'faker/locale/it' {
export = fakerStatic;
}
declare module "faker/locale/nl" {
declare module 'faker/locale/ja' {
export = fakerStatic;
}
declare module "faker/locale/pl" {
declare module 'faker/locale/ko' {
export = fakerStatic;
}
declare module "faker/locale/pt_BR" {
declare module 'faker/locale/nb_NO' {
export = fakerStatic;
}
declare module "faker/locale/ru" {
declare module 'faker/locale/nep' {
export = fakerStatic;
}
declare module "faker/locale/sk" {
declare module 'faker/locale/nl' {
export = fakerStatic;
}
declare module "faker/locale/sv" {
declare module 'faker/locale/nl_BE' {
export = fakerStatic;
}
declare module "faker/locale/tr" {
declare module 'faker/locale/pl' {
export = fakerStatic;
}
declare module "faker/locale/uk" {
declare module 'faker/locale/pt_BR' {
export = fakerStatic;
}
declare module "faker/locale/vi" {
declare module 'faker/locale/pt_PT' {
export = fakerStatic;
}
declare module "faker/locale/zh_CN" {
declare module 'faker/locale/ro' {
export = fakerStatic;
}
declare module "faker/locale/zh_TW" {
declare module 'faker/locale/ru' {
export = fakerStatic;
}
declare module 'faker/locale/sk' {
export = fakerStatic;
}
declare module 'faker/locale/sv' {
export = fakerStatic;
}
declare module 'faker/locale/tr' {
export = fakerStatic;
}
declare module 'faker/locale/uk' {
export = fakerStatic;
}
declare module 'faker/locale/vi' {
export = fakerStatic;
}
declare module 'faker/locale/zh_CN' {
export = fakerStatic;
}
declare module 'faker/locale/zh_TW' {
export = fakerStatic;
}