added Smartpath class and path level array
This commit is contained in:
24
ts/index.ts
24
ts/index.ts
@@ -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'
|
||||
|
15
ts/smartpath.classes.smartpath.ts
Normal file
15
ts/smartpath.classes.smartpath.ts
Normal 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)
|
||||
}
|
||||
}
|
@@ -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()
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import 'typings-global'
|
||||
export import beautylog = require ('beautylog')
|
||||
export var home = require('home')
|
||||
export import path = require('path')
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user