improve absolute path handling
This commit is contained in:
17
ts/index.ts
17
ts/index.ts
@ -1,8 +1,10 @@
|
||||
import "typings-global";
|
||||
import plugins = require("./smartpath.plugins");
|
||||
import SmartpathCheck = require("./smartpath.check");
|
||||
import SmartpathGet = require("./smartpath.get");
|
||||
import SmartpathTransform = require("./smartpath.transform");
|
||||
import 'typings-global'
|
||||
import plugins = require('./smartpath.plugins')
|
||||
|
||||
// import modules
|
||||
import SmartpathCheck = require('./smartpath.check')
|
||||
import SmartpathGet = require('./smartpath.get')
|
||||
import SmartpathTransform = require('./smartpath.transform')
|
||||
|
||||
/**
|
||||
*
|
||||
@ -12,7 +14,6 @@ let smartpath = {
|
||||
check: SmartpathCheck,
|
||||
get: SmartpathGet,
|
||||
transform: SmartpathTransform
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export = smartpath;
|
||||
export = smartpath
|
||||
|
@ -1,10 +1,10 @@
|
||||
import "typings-global";
|
||||
import plugins = require("./smartpath.plugins");
|
||||
import 'typings-global'
|
||||
import plugins = require('./smartpath.plugins')
|
||||
|
||||
export let isDir = function(pathArg:string){
|
||||
return !isFile(pathArg);
|
||||
export let isDir = function(pathArg: string){
|
||||
return !isFile(pathArg)
|
||||
}
|
||||
|
||||
export let isFile = function(pathArg){
|
||||
return /\.[a-zA-Z]*$/.test(pathArg); // checks if there is a .anything at the end
|
||||
}
|
||||
return /\.[a-zA-Z]*$/.test(pathArg) // checks if there is a .anything at the end
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require ("beautylog");
|
||||
export var home = require("home");
|
||||
export import path = require("path");
|
||||
|
||||
import 'typings-global'
|
||||
export import beautylog = require ('beautylog')
|
||||
export var home = require('home')
|
||||
export import path = require('path')
|
||||
|
@ -1,35 +1,40 @@
|
||||
import "typings-global";
|
||||
import plugins = require("./smartpath.plugins");
|
||||
import 'typings-global'
|
||||
import plugins = require('./smartpath.plugins')
|
||||
|
||||
/* ------------------------------------------ *
|
||||
* ------------ helpers --------------------- *
|
||||
* ------------------------------------------ */
|
||||
let makeAbsolute = function(localPathArg:string, baseArg?:string):string {
|
||||
let absolutePath:string;
|
||||
if(baseArg){
|
||||
absolutePath = plugins.path.join(baseArg,localPathArg);
|
||||
|
||||
// checks a file
|
||||
let makeAbsolute = function(localPathArg: string, baseArg?: string): string {
|
||||
let absolutePath: string
|
||||
let alreadyAbsolute = plugins.path.isAbsolute(localPathArg)
|
||||
if (baseArg && !alreadyAbsolute) {
|
||||
absolutePath = plugins.path.join(baseArg,localPathArg)
|
||||
} else if (!alreadyAbsolute) {
|
||||
absolutePath = plugins.path.resolve(localPathArg)
|
||||
} else {
|
||||
absolutePath = plugins.path.resolve(localPathArg);
|
||||
absolutePath = localPathArg
|
||||
}
|
||||
return absolutePath;
|
||||
};
|
||||
return absolutePath
|
||||
}
|
||||
|
||||
/* ------------------------------------------ *
|
||||
* ------- export functions ----------------- *
|
||||
* ------------------------------------------ */
|
||||
export let toAbsolute = function(relativeArg:any, baseArg?:string):any {
|
||||
if(typeof relativeArg === "string"){
|
||||
return makeAbsolute(relativeArg,baseArg);
|
||||
} else if(Array.isArray(relativeArg)){
|
||||
export let toAbsolute = function(relativeArg: string | string[], 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;
|
||||
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;
|
||||
plugins.beautylog.error('smartpath.absolute() could not make sense of the input. ' +
|
||||
'Input is neither String nor Array')
|
||||
return false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user