Skip to content

Commit

Permalink
chore: refactor to strictly typed convience method
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts committed Sep 13, 2022
1 parent 02e2367 commit 3901aac
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/modules/security/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Faker } from '../..';
import { faker } from '../..';
import { toDate } from '../../internal/toDate';

/**
Expand Down Expand Up @@ -111,20 +112,32 @@ export class SecurityModule {
score,
vector: [
'CVSS:3.1',
`AV:${this.faker.helpers.arrayElement('NALP'.split(''))}`,
`AC:${this.faker.helpers.arrayElement('LH'.split(''))}`,
`PR:${this.faker.helpers.arrayElement('NLH'.split(''))}`,
`UI:${this.faker.helpers.arrayElement('NR'.split(''))}`,
`S:${this.faker.helpers.arrayElement('UC'.split(''))}`,
`C:${this.faker.helpers.arrayElement('NLH'.split(''))}`,
`I:${this.faker.helpers.arrayElement('NLH'.split(''))}`,
`A:${this.faker.helpers.arrayElement('NLH'.split(''))}`,
`AV:${randomCharFromString('NALP')}`,
`AC:${randomCharFromString('LH')}`,
`PR:${randomCharFromString('NLH')}`,
`UI:${randomCharFromString('NR')}`,
`S:${randomCharFromString('UC')}`,
`C:${randomCharFromString('NLH')}`,
`I:${randomCharFromString('NLH')}`,
`A:${randomCharFromString('NLH')}`,
].join('/'),
rating: getRating(score),
};
}
}

/**
* Returns a random character from a string.
*
* @param string
*
* @example
* randomCharFromString('abc'); // 'b'
*/
function randomCharFromString(string: string): string {
return String(faker.helpers.arrayElement(string.split('')));
}

/**
* Returns the textual representation of a score.
*
Expand Down

0 comments on commit 3901aac

Please sign in to comment.