smartpath/ts/smartpath.transform.ts

35 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2016-03-12 07:24:05 +00:00
/// <reference path="typings/main.d.ts" />
import plugins = require("./smartpath.plugins");
2016-03-20 17:59:30 +00:00
/* ------------------------------------------ *
* ------------ helpers --------------------- *
* ------------------------------------------ */
let makeAbsolute = function(localPathArg:string, baseArg?:string):string {
2016-03-12 07:24:05 +00:00
let absolutePath:string;
if(baseArg){
absolutePath = plugins.path.join(baseArg,localPathArg);
} else {
absolutePath = plugins.path.resolve(localPathArg);
}
return absolutePath;
};
2016-03-20 17:59:30 +00:00
/* ------------------------------------------ *
* ------- export functions ----------------- *
* ------------------------------------------ */
export let toAbsolute = function(relativeArg:any, baseArg?:string):any {
2016-03-12 07:24:05 +00:00
if(typeof relativeArg === "string"){
2016-03-12 08:36:30 +00:00
return makeAbsolute(relativeArg,baseArg);
2016-03-12 07:24:05 +00:00
} else if(Array.isArray(relativeArg)){
let relativeArray = relativeArg
2016-03-12 08:36:30 +00:00
let absoluteArray:string[] = [];
2016-03-12 07:24:05 +00:00
for (let key in relativeArray){
2016-03-12 08:36:30 +00:00
absoluteArray.push(makeAbsolute(relativeArray[key],baseArg));
2016-03-12 07:24:05 +00:00
};
return absoluteArray;
} else {
plugins.beautylog.error("smartpath.absolute() could not make sense of the input. " +
"Input is neither String nor Array");
return false;
}
2016-03-20 17:59:30 +00:00
};