-
-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b02094
commit e73890c
Showing
2 changed files
with
86 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,84 @@ | ||
import type { Faker } from '.'; | ||
|
||
export class Hacker { | ||
constructor(private readonly faker: Faker) { | ||
// Bind `this` so namespaced is working correctly | ||
for (const name of Object.getOwnPropertyNames(Hacker.prototype)) { | ||
if (name === 'constructor' || typeof this[name] !== 'function') { | ||
continue; | ||
} | ||
this[name] = this[name].bind(this); | ||
} | ||
} | ||
|
||
/** | ||
* abbreviation | ||
* | ||
* @method faker.hacker.abbreviation | ||
*/ | ||
abbreviation() { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.hacker.abbreviation | ||
); | ||
} | ||
|
||
/** | ||
* adjective | ||
* | ||
* @method faker.hacker.adjective | ||
*/ | ||
adjective() { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.hacker.adjective | ||
); | ||
} | ||
|
||
/** | ||
* noun | ||
* | ||
* @method faker.hacker.noun | ||
*/ | ||
noun() { | ||
return this.faker.random.arrayElement(this.faker.definitions.hacker.noun); | ||
} | ||
|
||
/** | ||
* verb | ||
* | ||
* @method faker.hacker.verb | ||
*/ | ||
verb() { | ||
return this.faker.random.arrayElement(this.faker.definitions.hacker.verb); | ||
} | ||
|
||
/** | ||
* ingverb | ||
* | ||
* @method faker.hacker.ingverb | ||
*/ | ||
ingverb() { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.hacker.ingverb | ||
); | ||
} | ||
|
||
/** | ||
* phrase | ||
* | ||
* @method faker.hacker.phrase | ||
*/ | ||
phrase() { | ||
const data = { | ||
abbreviation: this.abbreviation, | ||
adjective: this.adjective, | ||
ingverb: this.ingverb, | ||
noun: this.noun, | ||
verb: this.verb, | ||
}; | ||
|
||
const phrase = this.faker.random.arrayElement( | ||
this.faker.definitions.hacker.phrase | ||
); | ||
return this.faker.helpers.mustache(phrase, data); | ||
} | ||
} |
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