src/lib/helpers.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 33
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 1
mnd 0
bc 0
fnc 1
bpm 0
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A helpers.ts ➔ lstatSafe 0 5 1
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