diff options
Diffstat (limited to 'src/modules/git')
| -rw-r--r-- | src/modules/git/index.ts | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/src/modules/git/index.ts b/src/modules/git/index.ts index e86f6648..21596273 100644 --- a/src/modules/git/index.ts +++ b/src/modules/git/index.ts @@ -4,25 +4,6 @@ import type { Faker } from '../..'; * Module to generate git related entries. */ export class Git { - private hexChars = [ - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - 'a', - 'b', - 'c', - 'd', - 'e', - 'f', - ]; - constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly for (const name of Object.getOwnPropertyNames(Git.prototype)) { @@ -68,9 +49,14 @@ export class Git { eol?: 'LF' | 'CRLF'; } = {} ): string { + const { + merge = this.faker.datatype.number({ min: 0, max: 4 }) === 0, + eol = 'CRLF', + } = options; + const lines = [`commit ${this.faker.git.commitSha()}`]; - if (options.merge || this.faker.datatype.number({ min: 0, max: 4 }) === 0) { + if (merge) { lines.push(`Merge: ${this.shortSha()} ${this.shortSha()}`); } @@ -83,8 +69,7 @@ export class Git { '' ); - const eolOption = options.eol ?? 'CRLF'; - const eolChar = eolOption === 'CRLF' ? '\r\n' : '\n'; + const eolChar = eol === 'CRLF' ? '\r\n' : '\n'; const entry = lines.join(eolChar); return entry; @@ -107,13 +92,7 @@ export class Git { * faker.git.commitSha() // '2c6e3880fd94ddb7ef72d34e683cdc0c47bec6e6' */ commitSha(): string { - let commit = ''; - - for (let i = 0; i < 40; i++) { - commit += this.faker.helpers.arrayElement(this.hexChars); - } - - return commit; + return this.faker.datatype.hexadecimal({ length: 40, case: 'lower' }); } /** @@ -123,12 +102,6 @@ export class Git { * faker.git.shortSha() // '6155732' */ shortSha(): string { - let shortSha = ''; - - for (let i = 0; i < 7; i++) { - shortSha += this.faker.helpers.arrayElement(this.hexChars); - } - - return shortSha; + return this.faker.datatype.hexadecimal({ length: 7, case: 'lower' }); } } |
