BREAKING CHANGE(package): change scope

This commit is contained in:
2018-07-21 23:26:11 +02:00
parent 09d424e972
commit 53905df003
30 changed files with 1185 additions and 636 deletions

View File

@ -1,13 +1,8 @@
// import modules
import * as check from './smartpath.check'
import * as get from './smartpath.get'
import * as transform from './smartpath.transform'
import * as check from './smartpath.check';
import * as get from './smartpath.get';
import * as transform from './smartpath.transform';
export { check, get, transform };
export {
check,
get,
transform
}
export * from './smartpath.classes.smartpath'
export * from './smartpath.classes.smartpath';

View File

@ -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
}
export let isFile = function(pathArg) {
return /\.[a-zA-Z]*$/.test(pathArg); // checks if there is a .anything at the end
};

View File

@ -1,15 +1,15 @@
import * as plugins from './smartpath.plugins'
import * as getMod from './smartpath.get'
import * as plugins from './smartpath.plugins';
import * as getMod from './smartpath.get';
export class Smartpath {
originalPath: string
type: getMod.TPathType
pathLevels: string[]
pathLevelsBackwards: string[]
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)
this.originalPath = pathArg;
this.type = getMod.type(this.originalPath);
this.pathLevels = getMod.pathLevels(this.originalPath);
this.pathLevelsBackwards = getMod.pathLevelsBackwards(this.originalPath);
}
}

View File

@ -1,36 +1,36 @@
import plugins = require('./smartpath.plugins')
export type TPathType = 'url' | 'local'
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): TPathType {
let urlRegex = /http[s|\s]:\/\/.*/i
if (urlRegex.exec(pathStringArg)) {
return 'url'
} else {
return 'local'
};
}
export let type = function(pathStringArg: string): TPathType {
let urlRegex = /http[s|\s]:\/\/.*/i;
if (urlRegex.exec(pathStringArg)) {
return 'url';
} else {
return 'local';
}
};
export let home = function (pathArgument?: string) {
if (pathArgument) {
return plugins.home.resolve(pathArgument)
} else {
return plugins.home()
}
}
export let home = function(pathArgument?: string) {
if (pathArgument) {
return pathArgument.replace('~', plugins.os.homedir());
} else {
return plugins.os.homedir();
}
};
export type TSystemArg = 'dynamic' | 'windows' | 'linux' | 'osx'
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
}
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()
}
return pathLevels(pathArg, systemArg).reverse();
};

View File

@ -1,8 +1,4 @@
import 'typings-global'
let home = require('home')
import * as path from 'path'
import * as os from 'os';
import * as path from 'path';
export {
home,
path
}
export { os, path };

View File

@ -1,40 +1,42 @@
import 'typings-global'
import plugins = require('./smartpath.plugins')
import 'typings-global';
import plugins = require('./smartpath.plugins');
/* ------------------------------------------ *
* ------------ helpers --------------------- *
* ------------------------------------------ */
// checks a file
// 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 = localPathArg
}
return absolutePath
}
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 = localPathArg;
}
return absolutePath;
};
/* ------------------------------------------ *
* ------- export functions ----------------- *
* ------------------------------------------ */
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
} else {
console.error('smartpath.absolute() could not make sense of the input. ' +
'Input is neither String nor Array')
return false
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;
} else {
console.error(
'smartpath.absolute() could not make sense of the input. ' +
'Input is neither String nor Array'
);
return false;
}
};