added Smartpath class and path level array

This commit is contained in:
2016-11-26 22:46:36 +01:00
parent c52c1902ee
commit 7916929550
18 changed files with 250 additions and 198 deletions

View File

@@ -1,19 +1,13 @@
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')
import check = require('./smartpath.check')
import get = require('./smartpath.get')
import transform = require('./smartpath.transform')
/**
*
* @type {{getPath: (function(any): undefined)}}
*/
let smartpath = {
check: SmartpathCheck,
get: SmartpathGet,
transform: SmartpathTransform
export {
check,
get,
transform
}
export = smartpath
export * from './smartpath.classes.smartpath'

View File

@@ -0,0 +1,15 @@
import * as plugins from './smartpath.plugins'
import * as getMod from './smartpath.get'
export class Smartpath {
originalPath: string
type: getMod.TPathType
pathLevels: string[]
pathLevelsBackwards: string[]
constructor(pathArg: string) {
this.originalPath = pathArg
this.type = getMod.type(this.originalPath)
this.pathLevels = getMod.pathLevels(this.originalPath)
this.pathLevelsBackwards = getMod.pathLevelsBackwards(this.originalPath)
}
}

View File

@@ -1,22 +1,36 @@
import "typings-global";
import plugins = require("./smartpath.plugins");
import plugins = require('./smartpath.plugins')
export type TPathType = 'url' | 'local'
/**
* returns the type of the given path. Can be "url" or "local"
*/
export let type = function(pathStringArg:string):string {
export let type = function (pathStringArg: string): TPathType {
let urlRegex = /http[s|\s]:\/\/.*/i
if(urlRegex.exec(pathStringArg)){
return "url";
if (urlRegex.exec(pathStringArg)) {
return 'url'
} else {
return "local";
return 'local'
};
};
}
export let home = function(pathArgument?:string){
if(pathArgument){
return plugins.home.resolve(pathArgument);
export let home = function (pathArgument?: string) {
if (pathArgument) {
return plugins.home.resolve(pathArgument)
} else {
return plugins.home();
return plugins.home()
}
};
}
export type TSystemArg = 'dynamic' | 'windows' | 'linux' | 'osx'
export let pathLevels = (pathArg: string, systemArg: TSystemArg = 'dynamic') => {
let pathLevelArray: string[]
if (systemArg === 'dynamic') {
pathLevelArray = pathArg.split(plugins.path.sep)
}
return pathLevelArray
}
export let pathLevelsBackwards = (pathArg: string, systemArg?: TSystemArg) => {
return pathLevels(pathArg, systemArg).reverse()
}

View File

@@ -1,4 +1,3 @@
import 'typings-global'
export import beautylog = require ('beautylog')
export var home = require('home')
export import path = require('path')

View File

@@ -33,7 +33,7 @@ export let toAbsolute = function(relativeArg: string | string[], baseArg?: strin
}
return absoluteArray
} else {
plugins.beautylog.error('smartpath.absolute() could not make sense of the input. ' +
console.error('smartpath.absolute() could not make sense of the input. ' +
'Input is neither String nor Array')
return false
}