Skip to content

Commit

Permalink
feat: migrate company (#132)
Browse files Browse the repository at this point in the history
Co-authored-by: Shinigami92 <chrissi92@hotmail.de>
  • Loading branch information
2 people authored and damienwebdev committed Jan 14, 2022
1 parent 88afa60 commit 0205183
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 1 deletion.
141 changes: 141 additions & 0 deletions src/company.ts
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
);
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address } from './address';
import { Animal } from './animal';
import { Commerce } from './commerce';
import { Company } from './company';
import { Database } from './database';
import { Datatype } from './datatype';
import { _Date } from './date';
Expand Down Expand Up @@ -184,7 +185,7 @@ export class Faker {
readonly address: Address = new Address(this);
readonly animal: Animal = new Animal(this);
readonly commerce: Commerce = new Commerce(this);
readonly company = new (require('./company'))(this);
readonly company: Company = new Company(this);
readonly database: Database = new Database(this);
readonly date: _Date = new _Date(this);
readonly finance = new Finance(this);
Expand Down

0 comments on commit 0205183

Please sign in to comment.