Skip to content

Commit

Permalink
Merge branch 'main' into jsdocs/database
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Feb 6, 2022
2 parents 23d3ef8 + 7d9ae2f commit b10a615
Show file tree
Hide file tree
Showing 40 changed files with 141 additions and 114 deletions.
4 changes: 2 additions & 2 deletions src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ export class Address {
if (coordinate === undefined) {
return [this.faker.address.latitude(), this.faker.address.longitude()];
}
radius ||= 10.0;
isMetric ||= false;
radius = radius || 10.0;
isMetric = isMetric || false;

// TODO: implement either a gaussian/uniform distribution of points in circular region.
// Possibly include param to function that allows user to choose between distributions.
Expand Down
34 changes: 32 additions & 2 deletions src/animal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Faker } from '.';

/**
* Module to generate animal related entries.
*/
export class Animal {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
Expand All @@ -14,6 +17,8 @@ export class Animal {
/**
* Returns a random dog breed.
*
* @example
* faker.animal.dog() // 'Irish Water Spaniel'
*/
dog(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.dog);
Expand All @@ -22,6 +27,8 @@ export class Animal {
/**
* Returns a random cat breed.
*
* @example
* faker.animal.cat() // 'Singapura'
*/
cat(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.cat);
Expand All @@ -30,6 +37,8 @@ export class Animal {
/**
* Returns a random snake species.
*
* @example
* faker.animal.snake() // 'Eyelash viper'
*/
snake(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.snake);
Expand All @@ -38,6 +47,8 @@ export class Animal {
/**
* Returns a random bear species.
*
* @example
* faker.animal.bear() // 'Asian black bear'
*/
bear(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.bear);
Expand All @@ -46,6 +57,8 @@ export class Animal {
/**
* Returns a random lion species.
*
* @example
* faker.animal.lion() // 'Northeast Congo Lion'
*/
lion(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.lion);
Expand All @@ -54,7 +67,8 @@ export class Animal {
/**
* Returns a random cetacean species.
*
* @method faker.animal.cetacean
* @example
* faker.animal.cetacean() // 'Spinner Dolphin'
*/
cetacean(): string {
return this.faker.random.arrayElement(
Expand All @@ -65,6 +79,8 @@ export class Animal {
/**
* Returns a random horse breed.
*
* @example
* faker.animal.horse() // 'Swedish Warmblood'
*/
horse(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.horse);
Expand All @@ -73,6 +89,8 @@ export class Animal {
/**
* Returns a random bird species.
*
* @example
* faker.animal.bird() // 'Buller's Shearwater'
*/
bird(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.bird);
Expand All @@ -81,6 +99,8 @@ export class Animal {
/**
* Returns a random cow species.
*
* @example
* faker.animal.cow() // 'Brava'
*/
cow(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.cow);
Expand All @@ -89,6 +109,8 @@ export class Animal {
/**
* Returns a random fish species.
*
* @example
* faker.animal.fish() // 'Mandarin fish'
*/
fish(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.fish);
Expand All @@ -97,6 +119,8 @@ export class Animal {
/**
* Returns a random crocodilian species.
*
* @example
* faker.animal.crocodilia() // 'Philippine Crocodile'
*/
crocodilia(): string {
return this.faker.random.arrayElement(
Expand All @@ -107,14 +131,18 @@ export class Animal {
/**
* Returns a random insect species.
*
* @example
* faker.animal.insect() // 'Pyramid ant'
*/
insect(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.insect);
}

/**
* Returns a random rabbit species
* Returns a random rabbit species.
*
* @example
* faker.animal.rabbit() // 'Florida White'
*/
rabbit(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.rabbit);
Expand All @@ -123,6 +151,8 @@ export class Animal {
/**
* Returns a random animal type.
*
* @example
* faker.animal.type() // 'crocodilia'
*/
type(): string {
return this.faker.random.arrayElement(this.faker.definitions.animal.type);
Expand Down
60 changes: 37 additions & 23 deletions src/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { Fake } from './fake';

let f: Fake['fake'];

/**
* Module to generate company related entries.
*/
export class Company {
constructor(private readonly faker: Faker) {
f = this.faker.fake;
Expand All @@ -17,20 +20,22 @@ export class Company {
}

/**
* suffixes
* Returns an array with possible company name suffixes.
*
* @method faker.company.suffixes
* @example
* faker.company.suffixes() // [ 'Inc', 'and Sons', 'LLC', 'Group' ]
*/
suffixes(): string[] {
// Don't want the source array exposed to modification, so return a copy
return this.faker.definitions.company.suffix.slice(0);
}

/**
* companyName
* Generates a random company name.
* @param format The optional format index used to select a format.
*
* @method faker.company.companyName
* @param format
* @example
* faker.company.companyName() // 'Zieme, Hauck and McClure'
*/
companyName(format?: number): string {
const formats = [
Expand All @@ -47,18 +52,20 @@ export class Company {
}

/**
* companySuffix
* Returns a random company suffix.
*
* @method faker.company.companySuffix
* @example
* faker.company.companySuffix() // 'and Sons'
*/
companySuffix(): string {
return this.faker.random.arrayElement(this.faker.company.suffixes());
}

/**
* catchPhrase
* Generates a random business catch phrase.
*
* @method faker.company.catchPhrase
* @example
* faker.company.catchPhrase() // 'Upgradable systematic flexibility'
*/
catchPhrase(): string {
return f(
Expand All @@ -67,18 +74,20 @@ export class Company {
}

/**
* bs
* Generates a random company bs phrase.
*
* @method faker.company.bs
* @example
* faker.company.bs() // 'cultivate synergistic e-markets'
*/
bs(): string {
return f('{{company.bsBuzz}} {{company.bsAdjective}} {{company.bsNoun}}');
}

/**
* catchPhraseAdjective
* Returns a random catch phrase adjective.
*
* @method faker.company.catchPhraseAdjective
* @example
* faker.company.catchPhraseAdjective() // 'Multi-tiered'
*/
catchPhraseAdjective(): string {
return this.faker.random.arrayElement(
Expand All @@ -87,9 +96,10 @@ export class Company {
}

/**
* catchPhraseDescriptor
* Returns a random catch phrase descriptor.
*
* @method faker.company.catchPhraseDescriptor
* @example
* faker.company.catchPhraseDescriptor() // 'composite'
*/
catchPhraseDescriptor(): string {
return this.faker.random.arrayElement(
Expand All @@ -98,18 +108,20 @@ export class Company {
}

/**
* catchPhraseNoun
* Returns a random catch phrase noun.
*
* @method faker.company.catchPhraseNoun
* @example
* faker.company.catchPhraseNoun() // 'leverage'
*/
catchPhraseNoun(): string {
return this.faker.random.arrayElement(this.faker.definitions.company.noun);
}

/**
* bsAdjective
* Returns a random company bs adjective.
*
* @method faker.company.bsAdjective
* @example
* faker.company.bsAdjective() // 'one-to-one'
*/
bsAdjective(): string {
return this.faker.random.arrayElement(
Expand All @@ -118,9 +130,10 @@ export class Company {
}

/**
* bsBuzz
* Returns a random company bs buzz word.
*
* @method faker.company.bsBuzz
* @example
* faker.company.bsBuzz() // 'empower'
*/
bsBuzz(): string {
return this.faker.random.arrayElement(
Expand All @@ -129,9 +142,10 @@ export class Company {
}

/**
* bsNoun
* Returns a random company bs noun.
*
* @method faker.company.bsNoun
* @example
* faker.company.bsNoun() // 'paradigms'
*/
bsNoun(): string {
return this.faker.random.arrayElement(
Expand Down
2 changes: 1 addition & 1 deletion src/finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Finance {
* @param length
*/
account(length?: number): string {
length ||= 8;
length = length || 8;
let template = '';

for (let i = 0; i < length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export class Helpers {
return o || [];
}

o ||= ['a', 'b', 'c'] as unknown as T[];
o = o || (['a', 'b', 'c'] as unknown as T[]);
for (let x: T, j: number, i = o.length - 1; i > 0; --i) {
j = this.faker.datatype.number(i);
x = o[i];
Expand Down
4 changes: 2 additions & 2 deletions src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export class Image {
randomize?: boolean,
https?: boolean
): string {
width ||= 640;
height ||= 480;
width = width || 640;
height = height || 480;
let protocol = 'http://';
if (typeof https !== 'undefined' && https === true) {
protocol = 'https://';
Expand Down
4 changes: 2 additions & 2 deletions src/image_providers/lorempicsum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export class LoremPicsum {
blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10,
seed?: string
): string {
width ||= 640;
height ||= 480;
width = width || 640;
height = height || 480;

let url = 'https://picsum.photos';

Expand Down
4 changes: 2 additions & 2 deletions src/image_providers/lorempixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export class Lorempixel {
category?: string,
randomize?: boolean
): string {
width ||= 640;
height ||= 480;
width = width || 640;
height = height || 480;

let url = `https://lorempixel.com/${width}/${height}`;
if (typeof category !== 'undefined') {
Expand Down
4 changes: 2 additions & 2 deletions src/image_providers/unsplash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export class Unsplash {
category?: string,
keyword?: string
): string {
width ||= 640;
height ||= 480;
width = width || 640;
height = height || 480;

let url = 'https://source.unsplash.com';

Expand Down
14 changes: 8 additions & 6 deletions src/internet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ export class Internet {
* @param provider
*/
email(firstName?: string, lastName?: string, provider?: string): string {
provider ||= this.faker.random.arrayElement(
this.faker.definitions.internet.free_email
);
provider =
provider ||
this.faker.random.arrayElement(
this.faker.definitions.internet.free_email
);
return (
this.faker.helpers.slugify(
this.faker.internet.userName(firstName, lastName)
Expand Down Expand Up @@ -234,8 +236,8 @@ export class Internet {
*/
userName(firstName?: string, lastName?: string): string {
let result: string;
firstName ||= this.faker.name.firstName();
lastName ||= this.faker.name.lastName();
firstName = firstName || this.faker.name.firstName();
lastName = lastName || this.faker.name.lastName();
switch (this.faker.datatype.number(2)) {
case 0:
result = `${firstName}${this.faker.datatype.number(99)}`;
Expand Down Expand Up @@ -481,7 +483,7 @@ export class Internet {
pattern?: RegExp,
prefix?: string
): string {
len ||= 15;
len = len || 15;
if (typeof memorable === 'undefined') {
memorable = false;
}
Expand Down
Loading

0 comments on commit b10a615

Please sign in to comment.