aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMohd Imran <[email protected]>2022-01-14 23:15:42 +0530
committerDamien Retzinger <[email protected]>2022-01-14 18:37:49 -0500
commit0205183ed821fa1bc04bbb290e7ab713db6e5a91 (patch)
tree7961cb3ea7d69b374ebaeaf1f8ba4520a074b560 /src
parent88afa60f739a60f08efe7365a3b80dbfd306055a (diff)
downloadfaker-0205183ed821fa1bc04bbb290e7ab713db6e5a91.tar.xz
faker-0205183ed821fa1bc04bbb290e7ab713db6e5a91.zip
feat: migrate company (#132)
Co-authored-by: Shinigami92 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/company.ts141
-rw-r--r--src/index.ts3
2 files changed, 143 insertions, 1 deletions
diff --git a/src/company.ts b/src/company.ts
new file mode 100644
index 00000000..6ca733a3
--- /dev/null
+++ b/src/company.ts
@@ -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
+ );
+ }
+}
diff --git a/src/index.ts b/src/index.ts
index 16a3b347..c7298cde 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -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';
@@ -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);