2016-11-26 21:46:36 +00:00
|
|
|
import plugins = require('./smartpath.plugins')
|
|
|
|
export type TPathType = 'url' | 'local'
|
2016-03-20 17:59:30 +00:00
|
|
|
|
2016-04-04 14:25:17 +00:00
|
|
|
/**
|
|
|
|
* returns the type of the given path. Can be "url" or "local"
|
|
|
|
*/
|
2016-11-26 21:46:36 +00:00
|
|
|
export let type = function (pathStringArg: string): TPathType {
|
2016-03-20 17:59:30 +00:00
|
|
|
let urlRegex = /http[s|\s]:\/\/.*/i
|
2016-11-26 21:46:36 +00:00
|
|
|
if (urlRegex.exec(pathStringArg)) {
|
|
|
|
return 'url'
|
2016-03-20 17:59:30 +00:00
|
|
|
} else {
|
2016-11-26 21:46:36 +00:00
|
|
|
return 'local'
|
2016-03-20 17:59:30 +00:00
|
|
|
};
|
2016-11-26 21:46:36 +00:00
|
|
|
}
|
2016-04-04 14:25:17 +00:00
|
|
|
|
2016-11-26 21:46:36 +00:00
|
|
|
export let home = function (pathArgument?: string) {
|
|
|
|
if (pathArgument) {
|
|
|
|
return plugins.home.resolve(pathArgument)
|
2016-04-04 14:25:17 +00:00
|
|
|
} else {
|
2016-11-26 21:46:36 +00:00
|
|
|
return plugins.home()
|
2016-04-04 14:25:17 +00:00
|
|
|
}
|
2016-11-26 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|