Skip to content

Commit 0556c7b

Browse files
committed
feat: migrate hacker
1 parent 64b8db8 commit 0556c7b

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

src/hacker.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import type { Faker } from '.';
2+
3+
export class Hacker {
4+
constructor(private readonly faker: Faker) {
5+
// Bind `this` so namespaced is working correctly
6+
for (const name of Object.getOwnPropertyNames(Hacker.prototype)) {
7+
if (name === 'constructor' || typeof this[name] !== 'function') {
8+
continue;
9+
}
10+
this[name] = this[name].bind(this);
11+
}
12+
}
13+
14+
/**
15+
* abbreviation
16+
*
17+
* @method faker.hacker.abbreviation
18+
*/
19+
abbreviation() {
20+
return this.faker.random.arrayElement(
21+
this.faker.definitions.hacker.abbreviation
22+
);
23+
}
24+
25+
/**
26+
* adjective
27+
*
28+
* @method faker.hacker.adjective
29+
*/
30+
adjective() {
31+
return this.faker.random.arrayElement(
32+
this.faker.definitions.hacker.adjective
33+
);
34+
}
35+
36+
/**
37+
* noun
38+
*
39+
* @method faker.hacker.noun
40+
*/
41+
noun() {
42+
return this.faker.random.arrayElement(this.faker.definitions.hacker.noun);
43+
}
44+
45+
/**
46+
* verb
47+
*
48+
* @method faker.hacker.verb
49+
*/
50+
verb() {
51+
return this.faker.random.arrayElement(this.faker.definitions.hacker.verb);
52+
}
53+
54+
/**
55+
* ingverb
56+
*
57+
* @method faker.hacker.ingverb
58+
*/
59+
ingverb() {
60+
return this.faker.random.arrayElement(
61+
this.faker.definitions.hacker.ingverb
62+
);
63+
}
64+
65+
/**
66+
* phrase
67+
*
68+
* @method faker.hacker.phrase
69+
*/
70+
phrase() {
71+
const data = {
72+
abbreviation: this.abbreviation,
73+
adjective: this.adjective,
74+
ingverb: this.ingverb,
75+
noun: this.noun,
76+
verb: this.verb,
77+
};
78+
79+
const phrase = this.faker.random.arrayElement(
80+
this.faker.definitions.hacker.phrase
81+
);
82+
return this.faker.helpers.mustache(phrase, data);
83+
}
84+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Datatype } from './datatype';
2+
import { Hacker } from './hacker';
23
import { Mersenne } from './mersenne';
34
import { Random } from './random';
45

@@ -153,6 +154,7 @@ export class Faker {
153154

154155
readonly mersenne: Mersenne = new Mersenne();
155156
random: Random = new Random(this);
157+
readonly hacker: Hacker = new Hacker(this);
156158
datatype: Datatype = new Datatype(this);
157159

158160
constructor(opts: FakerOptions = {}) {

0 commit comments

Comments
 (0)