added Smartpath class and path level array

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

19
dist/index.d.ts vendored
View File

@ -1,14 +1,5 @@
import 'typings-global';
import SmartpathCheck = require('./smartpath.check');
import SmartpathGet = require('./smartpath.get');
import SmartpathTransform = require('./smartpath.transform');
/**
*
* @type {{getPath: (function(any): undefined)}}
*/
declare let smartpath: {
check: typeof SmartpathCheck;
get: typeof SmartpathGet;
transform: typeof SmartpathTransform;
};
export = smartpath;
import check = require('./smartpath.check');
import get = require('./smartpath.get');
import transform = require('./smartpath.transform');
export { check, get, transform };
export * from './smartpath.classes.smartpath';

26
dist/index.js vendored
View File

@ -1,17 +1,13 @@
"use strict";
require("typings-global");
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
// import modules
const SmartpathCheck = require("./smartpath.check");
const SmartpathGet = require("./smartpath.get");
const SmartpathTransform = require("./smartpath.transform");
/**
*
* @type {{getPath: (function(any): undefined)}}
*/
let smartpath = {
check: SmartpathCheck,
get: SmartpathGet,
transform: SmartpathTransform
};
module.exports = smartpath;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR3ZCLGlCQUFpQjtBQUNqQixvREFBb0Q7QUFDcEQsZ0RBQWdEO0FBQ2hELDREQUE0RDtBQUU1RDs7O0dBR0c7QUFDSCxJQUFJLFNBQVMsR0FBRztJQUNaLEtBQUssRUFBRSxjQUFjO0lBQ3JCLEdBQUcsRUFBRSxZQUFZO0lBQ2pCLFNBQVMsRUFBRSxrQkFBa0I7Q0FDaEMsQ0FBQTtBQUVELGlCQUFTLFNBQVMsQ0FBQSJ9
const check = require("./smartpath.check");
exports.check = check;
const get = require("./smartpath.get");
exports.get = get;
const transform = require("./smartpath.transform");
exports.transform = transform;
__export(require("./smartpath.classes.smartpath"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsaUJBQWlCO0FBQ2pCLDJDQUEyQztBQU12QyxzQkFBSztBQUxULHVDQUF1QztBQU1uQyxrQkFBRztBQUxQLG1EQUFtRDtBQU0vQyw4QkFBUztBQUdiLG1EQUE2QyJ9

8
dist/smartpath.classes.smartpath.d.ts vendored Normal file
View File

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

12
dist/smartpath.classes.smartpath.js vendored Normal file
View File

@ -0,0 +1,12 @@
"use strict";
const getMod = require("./smartpath.get");
class Smartpath {
constructor(pathArg) {
this.originalPath = pathArg;
this.type = getMod.type(this.originalPath);
this.pathLevels = getMod.pathLevels(this.originalPath);
this.pathLevelsBackwards = getMod.pathLevelsBackwards(this.originalPath);
}
}
exports.Smartpath = Smartpath;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLmNsYXNzZXMuc21hcnRwYXRoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRwYXRoLmNsYXNzZXMuc21hcnRwYXRoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFDQSwwQ0FBeUM7QUFFekM7SUFLSSxZQUFZLE9BQWU7UUFDdkIsSUFBSSxDQUFDLFlBQVksR0FBRyxPQUFPLENBQUE7UUFDM0IsSUFBSSxDQUFDLElBQUksR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUMxQyxJQUFJLENBQUMsVUFBVSxHQUFHLE1BQU0sQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFBO1FBQ3RELElBQUksQ0FBQyxtQkFBbUIsR0FBRyxNQUFNLENBQUMsbUJBQW1CLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFBO0lBQzVFLENBQUM7Q0FDSjtBQVhELDhCQVdDIn0=

View File

@ -1,6 +1,9 @@
import "typings-global";
export declare type TPathType = 'url' | 'local';
/**
* returns the type of the given path. Can be "url" or "local"
*/
export declare let type: (pathStringArg: string) => string;
export declare let type: (pathStringArg: string) => TPathType;
export declare let home: (pathArgument?: string) => any;
export declare type TSystemArg = 'dynamic' | 'windows' | 'linux' | 'osx';
export declare let pathLevels: (pathArg: string, systemArg?: TSystemArg) => string[];
export declare let pathLevelsBackwards: (pathArg: string, systemArg?: TSystemArg) => string[];

17
dist/smartpath.get.js vendored
View File

@ -1,5 +1,4 @@
"use strict";
require("typings-global");
const plugins = require("./smartpath.plugins");
/**
* returns the type of the given path. Can be "url" or "local"
@ -7,10 +6,10 @@ const plugins = require("./smartpath.plugins");
exports.type = function (pathStringArg) {
let urlRegex = /http[s|\s]:\/\/.*/i;
if (urlRegex.exec(pathStringArg)) {
return "url";
return 'url';
}
else {
return "local";
return 'local';
}
;
};
@ -22,4 +21,14 @@ exports.home = function (pathArgument) {
return plugins.home();
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLmdldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0cGF0aC5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUN4QiwrQ0FBZ0Q7QUFFaEQ7O0dBRUc7QUFDUSxRQUFBLElBQUksR0FBRyxVQUFTLGFBQW9CO0lBQzNDLElBQUksUUFBUSxHQUFHLG9CQUFvQixDQUFBO0lBQ25DLEVBQUUsQ0FBQSxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQSxDQUFDO1FBQzdCLE1BQU0sQ0FBQyxLQUFLLENBQUM7SUFDakIsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ0osTUFBTSxDQUFDLE9BQU8sQ0FBQztJQUNuQixDQUFDO0lBQUEsQ0FBQztBQUNOLENBQUMsQ0FBQztBQUVTLFFBQUEsSUFBSSxHQUFHLFVBQVMsWUFBb0I7SUFDM0MsRUFBRSxDQUFBLENBQUMsWUFBWSxDQUFDLENBQUEsQ0FBQztRQUNiLE1BQU0sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUM5QyxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsT0FBTyxDQUFDLElBQUksRUFBRSxDQUFDO0lBQzFCLENBQUM7QUFDTCxDQUFDLENBQUMifQ==
exports.pathLevels = (pathArg, systemArg = 'dynamic') => {
let pathLevelArray;
if (systemArg === 'dynamic') {
pathLevelArray = pathArg.split(plugins.path.sep);
}
return pathLevelArray;
};
exports.pathLevelsBackwards = (pathArg, systemArg) => {
return exports.pathLevels(pathArg, systemArg).reverse();
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLmdldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0cGF0aC5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLCtDQUErQztBQUcvQzs7R0FFRztBQUNRLFFBQUEsSUFBSSxHQUFHLFVBQVUsYUFBcUI7SUFDN0MsSUFBSSxRQUFRLEdBQUcsb0JBQ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0FBQyxDQUFBIn0=

View File

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

View File

@ -1,6 +1,5 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.home = require('home');
exports.path = require("path");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHBhdGgucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHlDQUErQztBQUNwQyxRQUFBLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7QUFDakMsK0JBQW9DIn0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHBhdGgucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ1osUUFBQSxJQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO0FBQ2pDLCtCQUFvQyJ9

View File

@ -35,9 +35,9 @@ exports.toAbsolute = function (relativeArg, baseArg) {
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;
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnRyYW5zZm9ybS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0cGF0aC50cmFuc2Zvcm0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ij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BQTtJQUN4QixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsS0FBSyxDQUFDLDBEQUEwRDtZQUNwRSxtQ0FBbUMsQ0FBQyxDQUFBO1FBQ3hDLE1BQU0sQ0FBQyxLQUFLLENBQUE7SUFDaEIsQ0FBQztBQUNMLENBQUMsQ0FBQSJ9

View File

@ -23,13 +23,13 @@
},
"homepage": "https://github.com/pushrocks/smartpath",
"dependencies": {
"beautylog": "^5.0.23",
"home": "^1.0.1",
"typings-global": "^1.0.14"
},
"devDependencies": {
"npmts-g": "^5.2.8",
"should": "^11.1.0",
"@types/should": "^8.1.30",
"npmts-g": "^5.2.10",
"should": "^11.1.1",
"typings-test": "^1.0.3"
}
}

3
test/test.d.ts vendored
View File

@ -1,2 +1 @@
import "typings-test";
import "should";
import 'typings-test';

View File

@ -1,77 +1,79 @@
"use strict";
require("typings-test");
require("should");
let smartpath = require("../dist/index.js");
describe("smartpath", function () {
describe(".check", function () {
let filePathString = "./somedir/somefile.json";
let dirPathString = "./somedir/anotherdir";
let dirPathString2 = "./somedir/another.dir/";
describe(".isFile", function () {
it("should be true for a file path", function () {
smartpath.check.isFile(filePathString)
.should.be.true();
const should = require("should");
const smartpath = require("../dist/index.js");
describe('smartpath', function () {
describe('class Smartpath', function () {
let mySmartpath;
it('should create a valid instance', function () {
mySmartpath = new smartpath.Smartpath('/some/path/to/some.file');
should(mySmartpath).be.instanceof(smartpath.Smartpath);
should(mySmartpath.pathLevelsBackwards).be.of.length(5);
});
});
describe('.check', function () {
let filePathString = './somedir/somefile.json';
let dirPathString = './somedir/anotherdir';
let dirPathString2 = './somedir/another.dir/';
describe('.isFile', function () {
it('should be true for a file path', function () {
should(smartpath.check.isFile(filePathString)).be.true();
});
it("should be false for a directory path", function () {
smartpath.check.isFile(dirPathString)
.should.be.false();
smartpath.check.isFile(dirPathString2)
.should.be.false();
it('should be false for a directory path', function () {
should(smartpath.check.isFile(dirPathString)).be.false();
should(smartpath.check.isFile(dirPathString2)).be.false();
});
});
describe(".isDir", function () {
it("should be true for a directory path", function () {
smartpath.check.isDir(dirPathString)
.should.be.true();
smartpath.check.isDir(dirPathString2)
.should.be.true();
describe('.isDir', function () {
it('should be true for a directory path', function () {
should(smartpath.check.isDir(dirPathString)).be.true();
should(smartpath.check.isDir(dirPathString2)).be.true();
});
it("should be false for a file path", function () {
smartpath.check.isDir(filePathString)
.should.be.false();
it('should be false for a file path', function () {
should(smartpath.check.isDir(filePathString)).be.false();
});
});
});
describe(".transform", function () {
describe("toAbsolute()", function () {
let baseString = "/basedir";
let relativeString = "somedir/somefile.txt";
let relativeString2 = "anotherdir/anotherfile.txt";
describe('.transform', function () {
describe('toAbsolute()', function () {
let baseString = '/basedir';
let relativeString = 'somedir/somefile.txt';
let relativeString2 = 'anotherdir/anotherfile.txt';
let relativeArray = [relativeString, relativeString, relativeString2];
it("should make a string absolute", function () {
smartpath.transform.toAbsolute(relativeString).should.startWith("/");
smartpath.transform.toAbsolute(relativeString).should.endWith(relativeString);
smartpath.transform.toAbsolute(relativeString, baseString).should.equal("/basedir/somedir/somefile.txt");
it('should make a string absolute', function () {
should(smartpath.transform.toAbsolute(relativeString)).startWith('/');
should(smartpath.transform.toAbsolute(relativeString)).endWith(relativeString);
should(smartpath.transform.toAbsolute(relativeString, baseString)).equal('/basedir/somedir/somefile.txt');
});
it("should make an array of relative Strings an Array of absolute Strings", function () {
it('should make an array of relative Strings an Array of absolute Strings', function () {
let absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString);
absoluteArray[2].should.startWith("/");
absoluteArray[2].should.endWith(relativeString2);
should(absoluteArray[2]).startWith('/');
should(absoluteArray[2]).endWith(relativeString2);
});
it("should return false if neither String nor Array", function () {
smartpath.transform.toAbsolute(3).should.be.false();
it('should return false if neither String nor Array', function () {
should(smartpath.transform.toAbsolute(3)).be.false();
});
});
});
describe(".get", function () {
describe(".type()", function () {
describe('.get', function () {
describe('.type()', function () {
it("should return 'url' for an URL", function () {
smartpath.get.type("https://push.rocks/some/url").should.equal("url");
smartpath.get.type("https://push.rocks/some/url").should.not.equal("local");
should(smartpath.get.type('https://push.rocks/some/url')).equal('url');
should(smartpath.get.type('https://push.rocks/some/url')).not.equal('local');
});
it("should return 'path' for a Path", function () {
smartpath.get.type("/some/absolute/path/").should.equal("local");
smartpath.get.type("./some/relative/path/").should.not.equal("url");
should(smartpath.get.type('/some/absolute/path/')).equal('local');
should(smartpath.get.type('./some/relative/path/')).not.equal('url');
});
});
describe(".get()", function () {
it("should a absolute path for an home relative URL", function () {
console.log(smartpath.get.home("~/test"));
describe('.get()', function () {
it('should a absolute path for an home relative URL', function () {
console.log(smartpath.get.home('~/test'));
});
it("should return the home directory path when no argument is specified", function () {
it('should return the home directory path when no argument is specified', function () {
console.log(smartpath.get.home());
});
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFzQjtBQUN0QixrQkFBZ0I7QUFDaEIsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBQUM7QUFFNUMsUUFBUSxDQUFDLFdBQVcsRUFBQztJQUNqQixRQUFRLENBQUMsUUFBUSxFQUFDO1FBQ2QsSUFBSSxjQUFjLEdBQUcseUJBQXlCLENBQUE7UUFDOUMsSUFBSSxhQUFhLEdBQUcsc0JBQXNCLENBQUE7UUFDMUMsSUFBSSxjQUFjLEdBQUcsd0JBQXdCLENBQUE7UUFDN0MsUUFBUSxDQUFDLFNBQVMsRUFBQztZQUNmLEVBQUUsQ0FBQyxnQ0FBZ0MsRUFBQztnQkFDaEMsU0FBUyxDQUFDLEtBQUssQ0FBQyxNQUFNLENBQUMsY0FBYyxDQUFDO3FCQUNqQyxNQUFNLENBQUMsRUFBRSxDQUFDLElB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QXNCLENBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQTtnQkFDakUsTUFBTSxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLHVCQUF1QixDQUFDLENBQUMsQ0FBQyxHQUFHLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxDQUFBO1lBQ3hFLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUE7UUFDRixRQUFRLENBQUMsUUFBUSxFQUFFO1lBQ2YsRUFBRSxDQUFDLGlEQUFpRCxFQUFFO2dCQUNsRCxPQUFPLENBQUMsR0FBRyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUE7WUFDN0MsQ0FBQyxDQUFDLENBQUE7WUFDRixFQUFFLENBQUMscUVBQXFFLEVBQUU7Z0JBQ3RFLE9BQU8sQ0FBQyxHQUFHLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxDQUFBO1lBQ3JDLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

View File

@ -1,77 +1,89 @@
import "typings-test";
import "should";
let smartpath = require("../dist/index.js");
import 'typings-test'
import * as should from 'should'
import * as smartpath from '../dist/index.js'
describe("smartpath",function(){
describe(".check",function(){
let filePathString = "./somedir/somefile.json"
let dirPathString = "./somedir/anotherdir"
let dirPathString2 = "./somedir/another.dir/"
describe(".isFile",function(){
it("should be true for a file path",function(){
smartpath.check.isFile(filePathString)
.should.be.true();
});
it("should be false for a directory path",function(){
smartpath.check.isFile(dirPathString)
.should.be.false();
smartpath.check.isFile(dirPathString2)
.should.be.false();
});
});
describe(".isDir",function(){
it("should be true for a directory path",function(){
smartpath.check.isDir(dirPathString)
.should.be.true();
smartpath.check.isDir(dirPathString2)
.should.be.true();
});
it("should be false for a file path",function(){
smartpath.check.isDir(filePathString)
.should.be.false();
});
});
});
describe(".transform",function(){
describe("toAbsolute()",function(){
let baseString = "/basedir";
let relativeString = "somedir/somefile.txt";
let relativeString2 = "anotherdir/anotherfile.txt";
let relativeArray = [relativeString,relativeString,relativeString2];
it("should make a string absolute",function(){
smartpath.transform.toAbsolute(relativeString).should.startWith("/");
smartpath.transform.toAbsolute(relativeString).should.endWith(relativeString);
smartpath.transform.toAbsolute(relativeString,baseString).should.equal("/basedir/somedir/somefile.txt");
});
it("should make an array of relative Strings an Array of absolute Strings",function(){
let absoluteArray = smartpath.transform.toAbsolute(relativeArray,baseString);
absoluteArray[2].should.startWith("/");
absoluteArray[2].should.endWith(relativeString2);
describe('smartpath', function () {
describe('class Smartpath', function() {
let mySmartpath: smartpath.Smartpath
it('should create a valid instance', function() {
mySmartpath = new smartpath.Smartpath('/some/path/to/some.file')
should(mySmartpath).be.instanceof(smartpath.Smartpath)
should(mySmartpath.pathLevelsBackwards).be.of.length(5)
})
})
describe('.check', function () {
let filePathString = './somedir/somefile.json'
let dirPathString = './somedir/anotherdir'
let dirPathString2 = './somedir/another.dir/'
describe('.isFile', function () {
it('should be true for a file path', function () {
should(
smartpath.check.isFile(filePathString)
).be.true()
})
it('should be false for a directory path', function () {
should(
smartpath.check.isFile(dirPathString)
).be.false()
should(
smartpath.check.isFile(dirPathString2)
).be.false()
})
})
describe('.isDir', function () {
it('should be true for a directory path', function () {
should(smartpath.check.isDir(dirPathString)
).be.true()
should(smartpath.check.isDir(dirPathString2)
).be.true()
})
it('should be false for a file path', function () {
should(
smartpath.check.isDir(filePathString)
).be.false()
})
})
})
describe('.transform', function () {
describe('toAbsolute()', function () {
let baseString = '/basedir'
let relativeString = 'somedir/somefile.txt'
let relativeString2 = 'anotherdir/anotherfile.txt'
let relativeArray = [relativeString, relativeString, relativeString2]
it('should make a string absolute', function () {
should(smartpath.transform.toAbsolute(relativeString)).startWith('/')
should(smartpath.transform.toAbsolute(relativeString)).endWith(relativeString)
should(smartpath.transform.toAbsolute(relativeString, baseString)).equal('/basedir/somedir/somefile.txt')
})
it('should make an array of relative Strings an Array of absolute Strings', function () {
let absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString)
should(absoluteArray[2]).startWith('/')
should(absoluteArray[2]).endWith(relativeString2)
})
it("should return false if neither String nor Array",function(){
smartpath.transform.toAbsolute(3).should.be.false();
});
});
});
describe(".get",function(){
describe(".type()",function(){
it("should return 'url' for an URL",function(){
smartpath.get.type("https://push.rocks/some/url").should.equal("url");
smartpath.get.type("https://push.rocks/some/url").should.not.equal("local");
});
it("should return 'path' for a Path",function(){
smartpath.get.type("/some/absolute/path/").should.equal("local");
smartpath.get.type("./some/relative/path/").should.not.equal("url");
});
});
describe(".get()",function(){
it("should a absolute path for an home relative URL",function(){
console.log(smartpath.get.home("~/test"));
});
it("should return the home directory path when no argument is specified",function(){
console.log(smartpath.get.home());
});
});
});
});
it('should return false if neither String nor Array', function () {
should(smartpath.transform.toAbsolute(3)).be.false()
})
})
})
describe('.get', function () {
describe('.type()', function () {
it("should return 'url' for an URL", function () {
should(smartpath.get.type('https://push.rocks/some/url')).equal('url')
should(smartpath.get.type('https://push.rocks/some/url')).not.equal('local')
})
it("should return 'path' for a Path", function () {
should(smartpath.get.type('/some/absolute/path/')).equal('local')
should(smartpath.get.type('./some/relative/path/')).not.equal('url')
})
})
describe('.get()', function () {
it('should a absolute path for an home relative URL', function () {
console.log(smartpath.get.home('~/test'))
})
it('should return the home directory path when no argument is specified', function () {
console.log(smartpath.get.home())
})
})
})
})

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
}