Skip to content

Commit 818ee65

Browse files
committed
chore: refactor to strictly typed convience method
1 parent b72461c commit 818ee65

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/modules/security/index.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Faker } from '../..';
2+
import { faker } from '../..';
23
import { toDate } from '../../internal/toDate';
34

45
/**
@@ -111,20 +112,32 @@ export class SecurityModule {
111112
score,
112113
vector: [
113114
'CVSS:3.1',
114-
`AV:${this.faker.helpers.arrayElement('NALP'.split(''))}`,
115-
`AC:${this.faker.helpers.arrayElement('LH'.split(''))}`,
116-
`PR:${this.faker.helpers.arrayElement('NLH'.split(''))}`,
117-
`UI:${this.faker.helpers.arrayElement('NR'.split(''))}`,
118-
`S:${this.faker.helpers.arrayElement('UC'.split(''))}`,
119-
`C:${this.faker.helpers.arrayElement('NLH'.split(''))}`,
120-
`I:${this.faker.helpers.arrayElement('NLH'.split(''))}`,
121-
`A:${this.faker.helpers.arrayElement('NLH'.split(''))}`,
115+
`AV:${randomCharFromString('NALP')}`,
116+
`AC:${randomCharFromString('LH')}`,
117+
`PR:${randomCharFromString('NLH')}`,
118+
`UI:${randomCharFromString('NR')}`,
119+
`S:${randomCharFromString('UC')}`,
120+
`C:${randomCharFromString('NLH')}`,
121+
`I:${randomCharFromString('NLH')}`,
122+
`A:${randomCharFromString('NLH')}`,
122123
].join('/'),
123124
rating: getRating(score),
124125
};
125126
}
126127
}
127128

129+
/**
130+
* Returns a random character from a string.
131+
*
132+
* @param string
133+
*
134+
* @example
135+
* randomCharFromString('abc'); // 'b'
136+
*/
137+
function randomCharFromString(string: string): string {
138+
return String(faker.helpers.arrayElement(string.split('')));
139+
}
140+
128141
/**
129142
* Returns the textual representation of a score.
130143
*

0 commit comments

Comments
 (0)