smartpath/dist/smartpath.transform.js
2016-03-26 12:12:07 +01:00

41 lines
4.6 KiB
JavaScript

"use strict";
/// <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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC50cmFuc2Zvcm0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBDQUEwQztBQUMxQyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRWhEOztnREFFZ0Q7QUFDaEQsSUFBSSxZQUFZLEdBQUcsVUFBUyxZQUFtQixFQUFFLE9BQWU7SUFDNUQsSUFBSSxZQUFtQixDQUFDO0lBQ3hCLEVBQUUsQ0FBQSxDQUFDLE9BQU8sQ0FBQyxDQUFBLENBQUM7UUFDUixZQUFZLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFDLFlBQVksQ0FBQyxDQUFDO0lBQzNELENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNILFlBQVksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLE9B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