All files / lib/services util.js

73.52% Statements 25/34
90% Branches 9/10
66.66% Functions 4/6
73.52% Lines 25/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 341x 1x 1x 1x 1x 1x     1x 1x 1x 1x 24x     24x 1x 1x 6x 6x 5x 5x 1x 1x 6x 1x 1x           1x 1x
import path from 'path';
import fs from 'fs';
 
export const isVerbose = process.env.UMAMI_DEBUG_ACTION === 'true';
 
export const rethrow = (err, prefix = "") => {
    throw new Error(`${prefix} ${err?.message || JSON.stringify(err)}`);
}
 
export const isSet = value => value !== null && value !== undefined && value !== '';
 
export const assumeInputIsSet = (inputObject, name) => {
    if (!isSet(inputObject)) {
        throw new Error(`please setup your environment: ${name} expected`);
    }
}
 
export const ensureDirectoryExistence = (filePath) => {
    const dirname = path.dirname(filePath);
    if (fs.existsSync(dirname)) {
        return true;
    }
    ensureDirectoryExistence(dirname);
    fs.mkdirSync(dirname);
}
 
export const logStringifyOf = val => {
    if (!isSet(val)) {
        return;
    }
    console.info(JSON.stringify(val, null, 2));
}
 
export const isArrayWithContent = val => Array.isArray(val) && val.length > 0;