smartpath/ts/smartpath.absolute.ts
2016-03-12 09:36:30 +01:00

31 lines
1.0 KiB
TypeScript

/// <reference path="typings/main.d.ts" />
import plugins = require("./smartpath.plugins");
var makeAbsolute = function(localPathArg:string, baseArg?:string):string {
let absolutePath:string;
if(baseArg){
absolutePath = plugins.path.join(baseArg,localPathArg);
} else {
absolutePath = plugins.path.resolve(localPathArg);
}
return absolutePath;
};
var absolute = function(relativeArg:any, baseArg?:string):any {
if(typeof relativeArg === "string"){
return makeAbsolute(relativeArg,baseArg);
} else if(Array.isArray(relativeArg)){
let relativeArray = relativeArg
let absoluteArray:string[] = [];
for (let 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;
}
};
export = absolute;