40 lines
4.6 KiB
JavaScript
40 lines
4.6 KiB
JavaScript
/// <reference path="typings/main.d.ts" />
|
|
var plugins = require("./smartpath.plugins");
|
|
/* ------------------------------------------ *
|
|
* ------------ helpers --------------------- *
|
|
* ------------------------------------------ */
|
|
var makeAbsolute = function (localPathArg, baseArg) {
|
|
var absolutePath;
|
|
if (baseArg) {
|
|
absolutePath = plugins.path.join(baseArg, localPathArg);
|
|
}
|
|
else {
|
|
absolutePath = plugins.path.resolve(localPathArg);
|
|
}
|
|
return absolutePath;
|
|
};
|
|
/* ------------------------------------------ *
|
|
* ------- export functions ----------------- *
|
|
* ------------------------------------------ */
|
|
exports.toAbsolute = function (relativeArg, baseArg) {
|
|
if (typeof relativeArg === "string") {
|
|
return makeAbsolute(relativeArg, baseArg);
|
|
}
|
|
else if (Array.isArray(relativeArg)) {
|
|
var relativeArray = relativeArg;
|
|
var absoluteArray = [];
|
|
for (var key in relativeArray) {
|
|
absoluteArray.push(makeAbsolute(relativeArray[key], baseArg));
|
|
}
|
|
;
|
|
return absoluteArray;
|
|
}
|
|
else {
|
|
plugins.beautylog.error("smartpath.absolute() could not make sense of the input. " +
|
|
"Input is neither String nor Array");
|
|
return false;
|
|
}
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC50cmFuc2Zvcm0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDO0FBQzFDLElBQU8sT0FBTyxXQUFXLHFCQUFxQixDQUFDLENBQUM7QUFFaEQ7O2dEQUVnRDtBQUNoRCxJQUFJLFlBQVksR0FBRyxVQUFTLFlBQW1CLEVBQUUsT0FBZTtJQUM1RCxJQUFJLFlBQW1CLENBQUM7SUFDeEIsRUFBRSxDQUFBLENBQUMsT0FBTyxDQUFDLENBQUEsQ0FBQztRQUNSLFlBQVksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FB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