Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 33 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { lstatSync } from 'fs'; |
||
2 | import { customAlphabet } from 'nanoid'; |
||
3 | import semver, { SemVer } from 'semver'; |
||
4 | |||
5 | /** |
||
6 | * It takes a version string like '1' or '1.0.3' and return the short version like '1.0'. |
||
7 | * @param {string} version - The version string to convert. |
||
8 | * @returns {string}A string |
||
9 | */ |
||
10 | export const versionToShortVersion = (version: string) => { |
||
11 | const sv = <SemVer>semver.coerce(version); |
||
12 | |||
13 | return `${sv.major}.${sv.minor}`; |
||
14 | }; |
||
15 | |||
16 | /** |
||
17 | * generates a unique run id for a boost run |
||
18 | * @returns {string} |
||
19 | */ |
||
20 | export const generateRunId = () => { |
||
21 | const alphabet = 'abcdefghijklmnopqrstuvwxyz'; |
||
22 | const numbers = '0123456789'; |
||
23 | const func = customAlphabet(alphabet + numbers, 14); |
||
24 | |||
25 | return func(14); |
||
26 | }; |
||
27 | |||
28 | export function lstatSafe(filename) { |
||
29 | const result = lstatSync(filename, { throwIfNoEntry: false }) || null; |
||
30 | |||
31 | return result; |
||
32 | } |
||
33 |