diff --git a/src/hacker.ts b/src/hacker.ts new file mode 100644 index 00000000000..ee36d814d43 --- /dev/null +++ b/src/hacker.ts @@ -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); + } +} diff --git a/src/index.ts b/src/index.ts index 92b710026fc..0b396056bc4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import { Datatype } from './datatype'; +import { Hacker } from './hacker'; import { Mersenne } from './mersenne'; import { Random } from './random'; @@ -153,6 +154,7 @@ export class Faker { readonly mersenne: Mersenne = new Mersenne(); random = new Random(this); + readonly hacker: Hacker = new Hacker(this); datatype: Datatype = new Datatype(this); constructor(opts: FakerOptions = {}) {