diff --git a/faker/faker-tests.ts b/faker/faker-tests.ts index 4dc2a3735f..5fb6a53746 100644 --- a/faker/faker-tests.ts +++ b/faker/faker-tests.ts @@ -52,6 +52,11 @@ resultStr = faker.company.bsAdjective(); resultStr = faker.company.bsBuzz(); resultStr = faker.company.bsNoun(); +resultStr = faker.database.column(); +resultStr = faker.database.type(); +resultStr = faker.database.collation(); +resultStr = faker.database.engine(); + resultDate = faker.date.past(); resultDate = faker.date.future(); resultDate = faker.date.between('foo', 'bar'); @@ -80,6 +85,8 @@ resultStr = faker.finance.transactionType(); resultStr = faker.finance.currencyCode(); resultStr = faker.finance.currencyName(); resultStr = faker.finance.currencySymbol(); +resultStr = faker.finance.bitcoinAddress(); +resultStr = faker.finance.bic(); resultStr = faker.hacker.abbreviation(); resultStr = faker.hacker.adjective(); @@ -110,6 +117,8 @@ resultStr = userCard.address.suite; resultStr = faker.internet.avatar(); resultStr = faker.internet.email(); resultStr = faker.internet.email('foo', 'bar', 'quux'); +resultStr = faker.internet.exampleEmail(); +resultStr = faker.internet.exampleEmail('foo', 'bar'); resultStr = faker.internet.protocol(); resultStr = faker.internet.url(); resultStr = faker.internet.domainName(); @@ -128,12 +137,18 @@ resultStr = faker.lorem.words(); resultStr = faker.lorem.words(0); resultStr = faker.lorem.sentence(); resultStr = faker.lorem.sentence(0, 0); +resultStr = faker.lorem.slug(); +resultStr = faker.lorem.slug(0); resultStr = faker.lorem.sentences(); resultStr = faker.lorem.sentences(0); resultStr = faker.lorem.paragraph(); resultStr = faker.lorem.paragraph(0); resultStr = faker.lorem.paragraphs(); resultStr = faker.lorem.paragraphs(0, ''); +resultStr = faker.lorem.text(); +resultStr = faker.lorem.text(0); +resultStr = faker.lorem.lines(); +resultStr = faker.lorem.lines(0); resultStr = faker.name.firstName(); resultStr = faker.name.firstName(0); @@ -169,6 +184,13 @@ resultStr = faker.random.objectElement(); resultStr = faker.random.objectElement({foo: 'bar', field: 'foo'}); resultStr = faker.random.uuid(); resultBool = faker.random.boolean(); +resultStr = faker.random.word(); +resultStr = faker.random.words(); +resultStr = faker.random.words(0); +resultStr = faker.random.image(); +resultStr = faker.random.locale(); +resultStr = faker.random.alphaNumeric(); +resultStr = faker.random.alphaNumeric(0); resultStr = faker.system.fileName( "foo", "bar" ); resultStr = faker.system.commonFileName( "foo", "bar" ); diff --git a/faker/index.d.ts b/faker/index.d.ts index 01e01b8b8b..ccca40e51a 100644 --- a/faker/index.d.ts +++ b/faker/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for faker v3.1 +// Type definitions for faker v4.1.0 // Project: http://marak.com/faker.js/ -// Definitions by: Bas Pennings , Yuki Kokubun +// Definitions by: Ben Swartz , Bas Pennings , Yuki Kokubun // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare var fakerStatic: Faker.FakerStatic; @@ -52,6 +52,13 @@ declare namespace Faker { bsNoun(): string; }; + database: { + column(): string; + type(): string; + collation(): string; + engine(): string; + }; + date: { past(years?: number, refDate?: string|Date): Date; future(years?: number, refDate?: string|Date): Date; @@ -72,6 +79,8 @@ declare namespace Faker { currencyCode(): string; currencyName(): string; currencySymbol(): string; + bitcoinAddress(): string; + bic(): string }; hacker: { @@ -116,11 +125,13 @@ 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; }; internet: { avatar(): string; email(firstName?: string, lastName?: string, provider?: string): string; + exampleEmail(firstName?: string, lastName?: string): string; userName(firstName?: string, lastName?: string): string; protocol(): string; url(): string; @@ -128,6 +139,7 @@ declare namespace Faker { domainSuffix(): string; domainWord(): string; ip(): string; + ipv6(): string; userAgent(): string; color(baseRed255?: number, baseGreen255?: number, baseBlue255?: number): string; mac(): string; @@ -138,9 +150,12 @@ declare namespace Faker { word(): string; words(num?: number): string; sentence(wordCount?: number, range?: number): string; + slug(wordCount?: number): string; sentences(sentenceCount?: number): string; paragraph(sentenceCount?: number): string; paragraphs(paragraphCount?: number, separator?: string): string; + text(times?: number): string; + lines(lineCount?: number): string; }; name: { @@ -171,6 +186,11 @@ declare namespace Faker { objectElement(object?: { [key: string]: T }, field?: any): T; uuid(): string; boolean(): boolean; + word(): string; // TODO: have ability to return specific type of word? As in: noun, adjective, verb, etc + words(count?: number): string; + image(): string; + locale(): string; + alphaNumeric(count?: number): string; }; system: { @@ -275,6 +295,14 @@ declare module "faker" { export = fakerStatic; } +declare module "faker/locale/az" { + export = fakerStatic; +} + +declare module "faker/locale/cz" { + export = fakerStatic; +} + declare module "faker/locale/de" { export = fakerStatic; } @@ -351,6 +379,10 @@ declare module "faker/locale/ge" { export = fakerStatic; } +declare module "faker/locale/id_ID" { + export = fakerStatic; +} + declare module "faker/locale/it" { export = fakerStatic; } diff --git a/faker/tsconfig.json b/faker/tsconfig.json index c2ce14c941..0589e5dc54 100644 --- a/faker/tsconfig.json +++ b/faker/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -19,4 +19,4 @@ "index.d.ts", "faker-tests.ts" ] -} \ No newline at end of file +} diff --git a/faker/v3/faker-tests.ts b/faker/v3/faker-tests.ts new file mode 100644 index 0000000000..4dc2a3735f --- /dev/null +++ b/faker/v3/faker-tests.ts @@ -0,0 +1,183 @@ + + +let resultStr: string; +let resultBool: boolean; +let resultNum: number; +let resultStrArr: string[]; +let resultDate: Date; + +import faker = require('faker'); +faker.locale = 'en'; + +resultStr = faker.address.zipCode(); +resultStr = faker.address.zipCode('###'); +resultStr = faker.address.city(); +resultStr = faker.address.city(0); +resultStr = faker.address.cityPrefix(); +resultStr = faker.address.citySuffix(); +resultStr = faker.address.streetName(); +resultStr = faker.address.streetAddress(); +resultStr = faker.address.streetAddress(false);; +resultStr = faker.address.streetSuffix(); +resultStr = faker.address.streetPrefix(); +resultStr = faker.address.secondaryAddress(); +resultStr = faker.address.county(); +resultStr = faker.address.country(); +resultStr = faker.address.countryCode(); +resultStr = faker.address.state(); +resultStr = faker.address.state(false); +resultStr = faker.address.stateAbbr(); +resultStr = faker.address.latitude(); +resultStr = faker.address.longitude(); + +resultStr = faker.commerce.color(); +resultStr = faker.commerce.department(); +resultStr = faker.commerce.productName(); +resultStr = faker.commerce.price(); +resultStr = faker.commerce.price(0, 0, 0, '#'); +resultStr = faker.commerce.productAdjective(); +resultStr = faker.commerce.productMaterial(); +resultStr = faker.commerce.product(); + +resultStrArr = faker.company.suffixes(); +resultStr = faker.company.companyName(); +resultStr = faker.company.companyName(0); +resultStr = faker.company.companySuffix(); +resultStr = faker.company.catchPhrase(); +resultStr = faker.company.bs(); +resultStr = faker.company.catchPhraseAdjective(); +resultStr = faker.company.catchPhraseDescriptor(); +resultStr = faker.company.catchPhraseNoun(); +resultStr = faker.company.bsAdjective(); +resultStr = faker.company.bsBuzz(); +resultStr = faker.company.bsNoun(); + +resultDate = faker.date.past(); +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); +resultStr = faker.date.month(); +resultStr = faker.date.month({ + abbr: true, + context: true +}); +resultStr = faker.date.weekday(); +resultStr = faker.date.weekday({ + abbr: true, + context: true +}); + +resultStr = faker.finance.account(); +resultStr = faker.finance.account(0); +resultStr = faker.finance.accountName(); +resultStr = faker.finance.mask(); +resultStr = faker.finance.mask(0, false, false); +resultStr = faker.finance.amount(); +resultStr = faker.finance.amount(0, 0, 0, '#'); +resultStr = faker.finance.transactionType(); +resultStr = faker.finance.currencyCode(); +resultStr = faker.finance.currencyName(); +resultStr = faker.finance.currencySymbol(); + +resultStr = faker.hacker.abbreviation(); +resultStr = faker.hacker.adjective(); +resultStr = faker.hacker.noun(); +resultStr = faker.hacker.verb(); +resultStr = faker.hacker.ingverb(); +resultStr = faker.hacker.phrase(); + +resultStr = faker.helpers.randomize(); +resultNum = faker.helpers.randomize([1,2,3,4]); +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#'); +resultStrArr = faker.helpers.shuffle(['foo', 'bar', 'quux']); +resultStr = faker.helpers.mustache('{{foo}}{{bar}}', {foo: 'x', bar: 'y'}); + +const card = faker.helpers.createCard(); +resultStr = card.name; +resultStr = card.address.streetA; +const contextualCard = faker.helpers.contextualCard(); +resultStr = contextualCard.name; +resultStr = contextualCard.address.suite; +const userCard = faker.helpers.userCard(); +resultStr = userCard.name; +resultStr = userCard.address.suite; + +resultStr = faker.internet.avatar(); +resultStr = faker.internet.email(); +resultStr = faker.internet.email('foo', 'bar', 'quux'); +resultStr = faker.internet.protocol(); +resultStr = faker.internet.url(); +resultStr = faker.internet.domainName(); +resultStr = faker.internet.domainSuffix(); +resultStr = faker.internet.domainWord(); +resultStr = faker.internet.ip(); +resultStr = faker.internet.userAgent(); +resultStr = faker.internet.color(); +resultStr = faker.internet.color(0, 0, 0); +resultStr = faker.internet.mac(); +resultStr = faker.internet.password(); +resultStr = faker.internet.password(0, false, '#', 'foo'); + +resultStr = faker.lorem.word(); +resultStr = faker.lorem.words(); +resultStr = faker.lorem.words(0); +resultStr = faker.lorem.sentence(); +resultStr = faker.lorem.sentence(0, 0); +resultStr = faker.lorem.sentences(); +resultStr = faker.lorem.sentences(0); +resultStr = faker.lorem.paragraph(); +resultStr = faker.lorem.paragraph(0); +resultStr = faker.lorem.paragraphs(); +resultStr = faker.lorem.paragraphs(0, ''); + +resultStr = faker.name.firstName(); +resultStr = faker.name.firstName(0); +resultStr = faker.name.lastName(); +resultStr = faker.name.lastName(0); +resultStr = faker.name.findName(); +resultStr = faker.name.findName('', '', 0); +resultStr = faker.name.jobTitle(); +resultStr = faker.name.prefix(); +resultStr = faker.name.suffix(); +resultStr = faker.name.title(); +resultStr = faker.name.jobDescriptor(); +resultStr = faker.name.jobArea(); +resultStr = faker.name.jobType(); + +resultStr = faker.phone.phoneNumber(); +resultStr = faker.phone.phoneNumber('#'); +resultStr = faker.phone.phoneNumberFormat(); +// https://github.com/Marak/faker.js/blob/master/lib/phone_number.js#L9-L13 +resultStr = faker.phone.phoneNumberFormat(0); +resultStr = faker.phone.phoneFormats(); + +resultNum = faker.random.number(); +resultNum = faker.random.number(0); +resultNum = faker.random.number({ + min: 0, + max: 0, + precision: 0 +}); +resultStr = faker.random.arrayElement(); +resultStr = faker.random.arrayElement(['foo', 'bar', 'quux']) +resultStr = faker.random.objectElement(); +resultStr = faker.random.objectElement({foo: 'bar', field: 'foo'}); +resultStr = faker.random.uuid(); +resultBool = faker.random.boolean(); + +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.semver(); + +import fakerEn = require('faker/locale/en'); +resultStr = faker.name.firstName(); diff --git a/faker/v3/index.d.ts b/faker/v3/index.d.ts new file mode 100644 index 0000000000..01e01b8b8b --- /dev/null +++ b/faker/v3/index.d.ts @@ -0,0 +1,416 @@ +// Type definitions for faker v3.1 +// Project: http://marak.com/faker.js/ +// Definitions by: Bas Pennings , Yuki Kokubun +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare var fakerStatic: Faker.FakerStatic; + +declare namespace Faker { + interface FakerStatic { + locale: string; + + address: { + zipCode(format?: string): string; + city(format?: number): string; + cityPrefix(): string; + citySuffix(): string; + streetName(): string; + streetAddress(useFullAddress?: boolean): string; + streetSuffix(): string; + streetPrefix(): string; + secondaryAddress(): string; + county(): string; + country(): string; + countryCode(): string; + state(useAbbr?: boolean): string; + stateAbbr(): string; + latitude(): string; + longitude(): string; + }; + + commerce: { + color(): string; + department(): string; + productName(): string; + price(min?: number, max?: number, dec?: number, symbol?: string): string; + productAdjective(): string; + productMaterial(): string; + product(): string; + }; + + company: { + suffixes(): string[]; + companyName(format?: number): string; + companySuffix(): string; + catchPhrase(): string; + bs(): string; + catchPhraseAdjective(): string; + catchPhraseDescriptor(): string; + catchPhraseNoun(): string; + bsAdjective(): string; + bsBuzz(): string; + bsNoun(): string; + }; + + 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; + }; + + fake(str: string): string; + + finance: { + account(length?: number): string; + accountName(): string; + mask(length?: number, parens?: boolean, elipsis?: boolean): string; + amount(min?:number, max?: number, dec?: number, symbol?: string): string; + transactionType(): string; + currencyCode(): string; + currencyName(): string; + currencySymbol(): string; + }; + + hacker: { + abbreviation(): string; + adjective(): string; + noun(): string; + verb(): string; + ingverb(): string; + phrase(): string; + }; + + helpers: { + randomize(array: T[]): T; + randomize(): string; + slugify(string?: string): string; + replaceSymbolWithNumber(string?: string, symbol?: string): string; + replaceSymbols(string?: string): string; + shuffle(o: T[]): T[]; + shuffle(): string[]; + mustache(str: string, data: { [key: string]: string|((substring: string, ...args: any[]) => string) }): string; + createCard(): Faker.Card; + contextualCard(): Faker.ContextualCard; + userCard(): Faker.UserCard; + createTransaction(): Faker.Transaction; + }; + + + image: { + image(): string; + avatar(): string; + imageUrl(width?: number, height?: number, category?: string): string; + abstract(width?: number, height?: number): string; + animals(width?: number, height?: number): string; + business(width?: number, height?: number): string; + cats(width?: number, height?: number): string; + city(width?: number, height?: number): string; + food(width?: number, height?: number): string; + nightlife(width?: number, height?: number): string; + fashion(width?: number, height?: number): string; + people(width?: number, height?: number): string; + nature(width?: number, height?: number): string; + sports(width?: number, height?: number): string; + technics(width?: number, height?: number): string; + transport(width?: number, height?: number): string; + }; + + internet: { + avatar(): string; + email(firstName?: string, lastName?: string, provider?: string): string; + userName(firstName?: string, lastName?: string): string; + protocol(): string; + url(): string; + domainName(): string; + domainSuffix(): string; + domainWord(): string; + ip(): string; + userAgent(): string; + color(baseRed255?: number, baseGreen255?: number, baseBlue255?: number): string; + mac(): string; + password(len?: number, memorable?: boolean, pattern?: string|RegExp, prefix?: string): string; + }; + + lorem: { + word(): string; + words(num?: number): string; + sentence(wordCount?: number, range?: number): string; + sentences(sentenceCount?: number): string; + paragraph(sentenceCount?: number): string; + paragraphs(paragraphCount?: number, separator?: string): string; + }; + + name: { + firstName(gender?: number): string; + lastName(gender?: number): string; + findName(firstName?: string, lastName?: string, gender?: number): string; + jobTitle(): string; + prefix(): string; + suffix(): string; + title(): string; + jobDescriptor(): string; + jobArea(): string; + jobType(): string; + }; + + phone: { + phoneNumber(format?: string): string; + phoneNumberFormat(phoneFormatsArrayIndex?: number): string; + phoneFormats(): string; + }; + + random: { + number(max: number): number; + number(options?: { min?: number, max?: number, precision?: number }): number; + arrayElement(): string; + arrayElement(array: T[]): T; + objectElement(object?: { [key: string]: any }, field?: "key"): string; + objectElement(object?: { [key: string]: T }, field?: any): T; + uuid(): string; + boolean(): boolean; + }; + + system: { + fileName(ext: string, type: string): string; + commonFileName(ext: string, type: string): string; + mimeType(): string; + commonFileType(): string; + commonFileExt(): string; + fileType(): string; + fileExt(mimeType: string): string; + //directoryPath(): string; + //filePath(): string; + semver(): string; + }; + + seed(value: number): void; + } + + interface Card { + name: string; + username: string; + email: string; + address: FullAddress; + phone: string; + website: string; + company: Company; + posts: Post[]; + accountHistory: string[]; + } + + interface FullAddress { + streetA: string; + streetB: string; + streetC: string; + streetD: string; + city: string; + state: string; + county: string; + zipcode: string; + geo: Geo; + } + + interface Geo { + lat: string; + lng: string; + } + + interface Company { + name: string; + catchPhrase: string; + bs: string; + } + + interface Post { + words: string; + sentence: string; + sentences: string; + paragraph: string; + } + + interface ContextualCard { + name: string; + username: string; + email: string; + dob: Date; + phone: string; + address: Address; + website: string; + company: Company; + } + + interface Address { + street: string; + suite: string; + city: string; + state: string; + zipcode: string; + geo: Geo; + } + + interface UserCard { + name: string; + username: string; + email: string; + address: Address; + phone: string; + website: string; + company: Company; + } + + interface Transaction { + amount: string; + date: Date; + business: string; + name: string; + type: string; + account: string; + } +} + +declare module "faker" { + export = fakerStatic; +} + +declare module "faker/locale/de" { + export = fakerStatic; +} + +declare module "faker/locale/de_AT" { + export = fakerStatic; +} + +declare module "faker/locale/de_CH" { + export = fakerStatic; +} + +declare module "faker/locale/el_GR" { + export = fakerStatic; +} + +declare module "faker/locale/en" { + export = fakerStatic; +} + +declare module "faker/locale/en_AU" { + export = fakerStatic; +} + +declare module "faker/locale/en_BORK" { + export = fakerStatic; +} + +declare module "faker/locale/en_CA" { + export = fakerStatic; +} + +declare module "faker/locale/en_GB" { + export = fakerStatic; +} + +declare module "faker/locale/en_IE" { + export = fakerStatic; +} + +declare module "faker/locale/en_IND" { + export = fakerStatic; +} + +declare module "faker/locale/en_US" { + export = fakerStatic; +} + +declare module "faker/locale/en_au_ocker" { + export = fakerStatic; +} + +declare module "faker/locale/es" { + export = fakerStatic; +} + +declare module "faker/locale/es_MX" { + export = fakerStatic; +} + +declare module "faker/locale/fa" { + export = fakerStatic; +} + +declare module "faker/locale/fr" { + export = fakerStatic; +} + +declare module "faker/locale/fr_CA" { + export = fakerStatic; +} + +declare module "faker/locale/ge" { + export = fakerStatic; +} + +declare module "faker/locale/it" { + export = fakerStatic; +} + +declare module "faker/locale/ja" { + export = fakerStatic; +} + +declare module "faker/locale/ko" { + export = fakerStatic; +} + +declare module "faker/locale/nb_NO" { + export = fakerStatic; +} + +declare module "faker/locale/nep" { + export = fakerStatic; +} + +declare module "faker/locale/nl" { + export = fakerStatic; +} + +declare module "faker/locale/pl" { + export = fakerStatic; +} + +declare module "faker/locale/pt_BR" { + export = fakerStatic; +} + +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; +} diff --git a/faker/v3/tsconfig.json b/faker/v3/tsconfig.json new file mode 100644 index 0000000000..052493a9c7 --- /dev/null +++ b/faker/v3/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "paths": { + "faker": [ "faker/v3" ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "faker-tests.ts" + ] +}