aboutsummaryrefslogtreecommitdiff
path: root/src/modules/git
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-08-15 10:24:50 +0200
committerGitHub <[email protected]>2022-08-15 08:24:50 +0000
commit83e5fd3db1624a2eebaa3d3714be8919e294a018 (patch)
tree02fd385690335d0aec574e0d2ed27779eed0de8a /src/modules/git
parentfda44bb899efbcbac2071a199964a3e269cbd805 (diff)
downloadfaker-83e5fd3db1624a2eebaa3d3714be8919e294a018.tar.xz
faker-83e5fd3db1624a2eebaa3d3714be8919e294a018.zip
refactor(git): reduce code duplication and follow code style (#1271)
Diffstat (limited to 'src/modules/git')
-rw-r--r--src/modules/git/index.ts45
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' });
}
}