-
-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Shinigami92 <chrissi92@hotmail.de>
- Loading branch information
1 parent
88afa60
commit 0205183
Showing
2 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import type { Faker } from '.'; | ||
import type { Fake } from './fake'; | ||
|
||
let f: Fake['fake']; | ||
|
||
export class Company { | ||
constructor(private readonly faker: Faker) { | ||
f = this.faker.fake; | ||
|
||
// Bind `this` so namespaced is working correctly | ||
for (const name of Object.getOwnPropertyNames(Company.prototype)) { | ||
if (name === 'constructor' || typeof this[name] !== 'function') { | ||
continue; | ||
} | ||
this[name] = this[name].bind(this); | ||
} | ||
} | ||
|
||
/** | ||
* suffixes | ||
* | ||
* @method faker.company.suffixes | ||
*/ | ||
suffixes(): string[] { | ||
// Don't want the source array exposed to modification, so return a copy | ||
return this.faker.definitions.company.suffix.slice(0); | ||
} | ||
|
||
/** | ||
* companyName | ||
* | ||
* @method faker.company.companyName | ||
* @param format | ||
*/ | ||
companyName(format?: number): string { | ||
const formats = [ | ||
'{{name.lastName}} {{company.companySuffix}}', | ||
'{{name.lastName}} - {{name.lastName}}', | ||
'{{name.lastName}}, {{name.lastName}} and {{name.lastName}}', | ||
]; | ||
|
||
if (typeof format !== 'number') { | ||
format = this.faker.datatype.number(formats.length - 1); | ||
} | ||
|
||
return f(formats[format]); | ||
} | ||
|
||
/** | ||
* companySuffix | ||
* | ||
* @method faker.company.companySuffix | ||
*/ | ||
companySuffix(): string { | ||
return this.faker.random.arrayElement(this.faker.company.suffixes()); | ||
} | ||
|
||
/** | ||
* catchPhrase | ||
* | ||
* @method faker.company.catchPhrase | ||
*/ | ||
catchPhrase(): string { | ||
return f( | ||
'{{company.catchPhraseAdjective}} {{company.catchPhraseDescriptor}} {{company.catchPhraseNoun}}' | ||
); | ||
} | ||
|
||
/** | ||
* bs | ||
* | ||
* @method faker.company.bs | ||
*/ | ||
bs(): string { | ||
return f('{{company.bsBuzz}} {{company.bsAdjective}} {{company.bsNoun}}'); | ||
} | ||
|
||
/** | ||
* catchPhraseAdjective | ||
* | ||
* @method faker.company.catchPhraseAdjective | ||
*/ | ||
catchPhraseAdjective(): string { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.company.adjective | ||
); | ||
} | ||
|
||
/** | ||
* catchPhraseDescriptor | ||
* | ||
* @method faker.company.catchPhraseDescriptor | ||
*/ | ||
catchPhraseDescriptor(): string { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.company.descriptor | ||
); | ||
} | ||
|
||
/** | ||
* catchPhraseNoun | ||
* | ||
* @method faker.company.catchPhraseNoun | ||
*/ | ||
catchPhraseNoun(): string { | ||
return this.faker.random.arrayElement(this.faker.definitions.company.noun); | ||
} | ||
|
||
/** | ||
* bsAdjective | ||
* | ||
* @method faker.company.bsAdjective | ||
*/ | ||
bsAdjective(): string { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.company.bs_adjective | ||
); | ||
} | ||
|
||
/** | ||
* bsBuzz | ||
* | ||
* @method faker.company.bsBuzz | ||
*/ | ||
bsBuzz(): string { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.company.bs_verb | ||
); | ||
} | ||
|
||
/** | ||
* bsNoun | ||
* | ||
* @method faker.company.bsNoun | ||
*/ | ||
bsNoun(): string { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.company.bs_noun | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters