|
| 1 | +import type { Faker } from '.'; |
| 2 | + |
| 3 | +export class Animal { |
| 4 | + constructor(private readonly faker: Faker) { |
| 5 | + // Bind `this` so namespaced is working correctly |
| 6 | + for (const name of Object.getOwnPropertyNames(Animal.prototype)) { |
| 7 | + if (name === 'constructor' || typeof this[name] !== 'function') { |
| 8 | + continue; |
| 9 | + } |
| 10 | + this[name] = this[name].bind(this); |
| 11 | + } |
| 12 | + } |
| 13 | + |
| 14 | + /** |
| 15 | + * dog |
| 16 | + * |
| 17 | + * @method faker.animal.dog |
| 18 | + */ |
| 19 | + dog() { |
| 20 | + return this.faker.random.arrayElement(this.faker.definitions.animal.dog); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * cat |
| 25 | + * |
| 26 | + * @method faker.animal.cat |
| 27 | + */ |
| 28 | + cat() { |
| 29 | + return this.faker.random.arrayElement(this.faker.definitions.animal.cat); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * snake |
| 34 | + * |
| 35 | + * @method faker.animal.snake |
| 36 | + */ |
| 37 | + snake() { |
| 38 | + return this.faker.random.arrayElement(this.faker.definitions.animal.snake); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * bear |
| 43 | + * |
| 44 | + * @method faker.animal.bear |
| 45 | + */ |
| 46 | + bear() { |
| 47 | + return this.faker.random.arrayElement(this.faker.definitions.animal.bear); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * lion |
| 52 | + * |
| 53 | + * @method faker.animal.lion |
| 54 | + */ |
| 55 | + lion() { |
| 56 | + return this.faker.random.arrayElement(this.faker.definitions.animal.lion); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * cetacean |
| 61 | + * |
| 62 | + * @method faker.animal.cetacean |
| 63 | + */ |
| 64 | + cetacean() { |
| 65 | + return this.faker.random.arrayElement( |
| 66 | + this.faker.definitions.animal.cetacean |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * horse |
| 72 | + * |
| 73 | + * @method faker.animal.horse |
| 74 | + */ |
| 75 | + horse() { |
| 76 | + return this.faker.random.arrayElement(this.faker.definitions.animal.horse); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * bird |
| 81 | + * |
| 82 | + * @method faker.animal.bird |
| 83 | + */ |
| 84 | + bird() { |
| 85 | + return this.faker.random.arrayElement(this.faker.definitions.animal.bird); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * cow |
| 90 | + * |
| 91 | + * @method faker.animal.cow |
| 92 | + */ |
| 93 | + cow() { |
| 94 | + return this.faker.random.arrayElement(this.faker.definitions.animal.cow); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * fish |
| 99 | + * |
| 100 | + * @method faker.animal.fish |
| 101 | + */ |
| 102 | + fish() { |
| 103 | + return this.faker.random.arrayElement(this.faker.definitions.animal.fish); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * crocodilia |
| 108 | + * |
| 109 | + * @method faker.animal.crocodilia |
| 110 | + */ |
| 111 | + crocodilia() { |
| 112 | + return this.faker.random.arrayElement( |
| 113 | + this.faker.definitions.animal.crocodilia |
| 114 | + ); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * insect |
| 119 | + * |
| 120 | + * @method faker.animal.insect |
| 121 | + */ |
| 122 | + insect() { |
| 123 | + return this.faker.random.arrayElement(this.faker.definitions.animal.insect); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * rabbit |
| 128 | + * |
| 129 | + * @method faker.animal.rabbit |
| 130 | + */ |
| 131 | + rabbit() { |
| 132 | + return this.faker.random.arrayElement(this.faker.definitions.animal.rabbit); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * type |
| 137 | + * |
| 138 | + * @method faker.animal.type |
| 139 | + */ |
| 140 | + type() { |
| 141 | + return this.faker.random.arrayElement(this.faker.definitions.animal.type); |
| 142 | + } |
| 143 | +} |
0 commit comments