Code coverage report for lib/common/helpers.js

Statements: 47.62% (50 / 105)      Branches: 10% (3 / 30)      Functions: 17.39% (4 / 23)      Lines: 49.49% (49 / 99)      Ignored: none     

All files » lib/common/ » helpers.js
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140    1 1 1 1                     1 1 28   1 1     1 1     1 1 6 6       6     1 1 64 64   1 1                           1 1     1 1     1 1                 1 1     1 1     1 1 31     31   1 1       1 1         1 1               1 1               1 1                 1 1             1  
///<reference path=".d.ts"/>
"use strict";
var uuid = require("node-uuid");
var Fiber = require("fibers");
var Table = require("cli-table");
function createGUID(useBraces) {
    if (useBraces === void 0) { useBraces = true; }
    var output;
    if (useBraces) {
        output = "{" + uuid.v4() + "}";
    }
    else {
        output = uuid.v4();
    }
    return output;
}
exports.createGUID = createGUID;
function stringReplaceAll(string, find, replace) {
    return string.split(find).join(replace);
}
exports.stringReplaceAll = stringReplaceAll;
function isRequestSuccessful(request) {
    return request.statusCode >= 200 && request.statusCode < 300;
}
exports.isRequestSuccessful = isRequestSuccessful;
function isResponseRedirect(response) {
    return _.contains([301, 302, 303, 307, 308], response.statusCode);
}
exports.isResponseRedirect = isResponseRedirect;
function formatListOfNames(names, conjunction) {
    Eif (conjunction === void 0) { conjunction = "or"; }
    Iif (names.length <= 1) {
        return names[0];
    }
    else {
        return _.initial(names).join(", ") + " " + conjunction + " " + names[names.length - 1];
    }
}
exports.formatListOfNames = formatListOfNames;
function getRelativeToRootPath(rootPath, filePath) {
    var relativeToRootPath = filePath.substr(rootPath.length);
    return relativeToRootPath;
}
exports.getRelativeToRootPath = getRelativeToRootPath;
function versionCompare(version1, version2) {
    version1 = version1.split("-")[0];
    version2 = version2.split("-")[0];
    var v1array = _.map(version1.split("."), function (x) { return parseInt(x, 10); }), v2array = _.map(version2.split("."), function (x) { return parseInt(x, 10); });
    if (v1array.length !== v2array.length) {
        throw new Error("Version strings are not in the same format");
    }
    for (var i = 0; i < v1array.length; ++i) {
        if (v1array[i] !== v2array[i]) {
            return v1array[i] > v2array[i] ? 1 : -1;
        }
    }
    return 0;
}
exports.versionCompare = versionCompare;
function isInteractive() {
    return process.stdout.isTTY && process.stdin.isTTY;
}
exports.isInteractive = isInteractive;
function toBoolean(str) {
    return str === "true";
}
exports.toBoolean = toBoolean;
function block(operation) {
    if (isInteractive()) {
        process.stdin.setRawMode(false);
    }
    operation();
    if (isInteractive()) {
        process.stdin.setRawMode(true);
    }
}
exports.block = block;
function isNumber(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}
exports.isNumber = isNumber;
function fromWindowsRelativePathToUnix(windowsRelativePath) {
    return windowsRelativePath.replace(/\\/g, "/");
}
exports.fromWindowsRelativePathToUnix = fromWindowsRelativePathToUnix;
function isNullOrWhitespace(input) {
    Iif (!input) {
        return true;
    }
    return input.replace(/\s/gi, "").length < 1;
}
exports.isNullOrWhitespace = isNullOrWhitespace;
function getCurrentEpochTime() {
    var dateTime = new Date();
    return dateTime.getTime();
}
exports.getCurrentEpochTime = getCurrentEpochTime;
function sleep(ms) {
    var fiber = Fiber.current;
    setTimeout(function () { return fiber.run(); }, ms);
    Fiber.yield();
}
exports.sleep = sleep;
function createTable(headers, data) {
    var table = new Table({
        head: headers,
        chars: { "mid": "", "left-mid": "", "mid-mid": "", "right-mid": "" }
    });
    _.forEach(data, function (row) { return table.push(row); });
    return table;
}
exports.createTable = createTable;
function remove(array, predicate, numberOfElements) {
    numberOfElements = numberOfElements || 1;
    var index = _.findIndex(array, predicate);
    if (index === -1) {
        return new Array();
    }
    return array.splice(index, numberOfElements);
}
exports.remove = remove;
function trimSymbol(str, symbol) {
    while (str.charAt(0) === symbol) {
        str = str.substr(1);
    }
    while (str.charAt(str.length - 1) === symbol) {
        str = str.substr(0, str.length - 1);
    }
    return str;
}
exports.trimSymbol = trimSymbol;
function appendZeroesToVersion(version, requiredVersionLength) {
    var zeroesToAppend = requiredVersionLength - version.split(".").length;
    for (var index = 0; index < zeroesToAppend; index++) {
        version += ".0";
    }
    return version;
}
exports.appendZeroesToVersion = appendZeroesToVersion;