now has better structure

This commit is contained in:
Philipp Kunz 2016-03-20 18:59:30 +01:00
parent b113dcfbe0
commit 2bd242ac57
9 changed files with 145 additions and 47 deletions

8
dist/index.js vendored
View File

@ -1,11 +1,13 @@
var SmartpathAbsolute = require("./smartpath.absolute");
var SmartpathTransform = require("./smartpath.transform");
var SmartpathGet = require("./smartpath.get");
/**
*
* @type {{getPath: (function(any): undefined)}}
*/
var smartpath = {
absolute: SmartpathAbsolute
transform: SmartpathTransform,
get: SmartpathGet
};
module.exports = smartpath;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLElBQU8saUJBQWlCLFdBQVcsc0JBQXNCLENBQUMsQ0FBQztBQUczRDs7O0dBR0c7QUFDSCxJQUFJLFNBQVMsR0FBRztJQUNaLFFBQVEsRUFBRSxpQkFBaUI7Q0FDOUIsQ0FBQztBQUdGLGlCQUFTLFNBQVMsQ0FBQyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCJ0eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0cGF0aC5wbHVnaW5zXCIpO1xuaW1wb3J0IFNtYXJ0cGF0aEFic29sdXRlID0gcmVxdWlyZShcIi4vc21hcnRwYXRoLmFic29sdXRlXCIpO1xuXG5cbi8qKlxuICpcbiAqIEB0eXBlIHt7Z2V0UGF0aDogKGZ1bmN0aW9uKGFueSk6IHVuZGVmaW5lZCl9fVxuICovXG5sZXQgc21hcnRwYXRoID0ge1xuICAgIGFic29sdXRlOiBTbWFydHBhdGhBYnNvbHV0ZVxufTtcblxuXG5leHBvcnQgPSBzbWFydHBhdGg7XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLElBQU8sa0JBQWtCLFdBQVcsdUJBQXVCLENBQUMsQ0FBQztBQUM3RCxJQUFPLFlBQVksV0FBVyxpQkFBaUIsQ0FBQyxDQUFDO0FBRWpEOzs7R0FHRztBQUNILElBQUksU0FBUyxHQUFHO0lBQ1osU0FBUyxFQUFFLGtCQUFrQjtJQUM3QixHQUFHLEVBQUUsWUFBWTtDQUVwQixDQUFDO0FBR0YsaUJBQVMsU0FBUyxDQUFDIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cInR5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmltcG9ydCBwbHVnaW5zID0gcmVxdWlyZShcIi4vc21hcnRwYXRoLnBsdWdpbnNcIik7XG5pbXBvcnQgU21hcnRwYXRoVHJhbnNmb3JtID0gcmVxdWlyZShcIi4vc21hcnRwYXRoLnRyYW5zZm9ybVwiKTtcbmltcG9ydCBTbWFydHBhdGhHZXQgPSByZXF1aXJlKFwiLi9zbWFydHBhdGguZ2V0XCIpO1xuXG4vKipcbiAqXG4gKiBAdHlwZSB7e2dldFBhdGg6IChmdW5jdGlvbihhbnkpOiB1bmRlZmluZWQpfX1cbiAqL1xubGV0IHNtYXJ0cGF0aCA9IHtcbiAgICB0cmFuc2Zvcm06IFNtYXJ0cGF0aFRyYW5zZm9ybSxcbiAgICBnZXQ6IFNtYXJ0cGF0aEdldFxuXG59O1xuXG5cbmV4cG9ydCA9IHNtYXJ0cGF0aDtcbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==

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

@ -0,0 +1,12 @@
exports.type = function (pathStringArg) {
var urlRegex = /http[s|\s]:\/\/.*/i;
if (urlRegex.exec(pathStringArg)) {
return "url";
}
else {
return "local";
}
;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR1csWUFBSSxHQUFHLFVBQVMsYUFBb0I7SUFDM0MsSUFBSSxRQUFRLEdBQUcsb0JBQW9CLENBQUE7SUFDbkMsRUFBRSxDQUFBLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFBLENBQUM7UUFDN0IsTUFBTSxDQUFDLEtBQUssQ0FBQztJQUNqQixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsT0FBTyxDQUFDO0lBQ25CLENBQUM7SUFBQSxDQUFDO0FBQ04sQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0cGF0aC5nZXQuanMiLCJzb3VyY2VzQ29udGVudCI6WyIvLy8gPHJlZmVyZW5jZSBwYXRoPVwidHlwaW5ncy9tYWluLmQudHNcIiAvPlxuaW1wb3J0IHBsdWdpbnMgPSByZXF1aXJlKFwiLi9zbWFydHBhdGgucGx1Z2luc1wiKTtcblxuZXhwb3J0IGxldCB0eXBlID0gZnVuY3Rpb24ocGF0aFN0cmluZ0FyZzpzdHJpbmcpOnN0cmluZyB7XG4gICAgbGV0IHVybFJlZ2V4ID0gL2h0dHBbc3xcXHNdOlxcL1xcLy4qL2lcbiAgICBpZih1cmxSZWdleC5leGVjKHBhdGhTdHJpbmdBcmcpKXtcbiAgICAgICAgcmV0dXJuIFwidXJsXCI7XG4gICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIFwibG9jYWxcIjtcbiAgICB9O1xufTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

39
dist/smartpath.transform.js vendored Normal file
View File

@ -0,0 +1,39 @@
/// <reference path="typings/main.d.ts" />
var plugins = require("./smartpath.plugins");
/* ------------------------------------------ *
* ------------ helpers --------------------- *
* ------------------------------------------ */
var makeAbsolute = function (localPathArg, baseArg) {
var absolutePath;
if (baseArg) {
absolutePath = plugins.path.join(baseArg, localPathArg);
}
else {
absolutePath = plugins.path.resolve(localPathArg);
}
return absolutePath;
};
/* ------------------------------------------ *
* ------- export functions ----------------- *
* ------------------------------------------ */
exports.toAbsolute = function (relativeArg, baseArg) {
if (typeof relativeArg === "string") {
return makeAbsolute(relativeArg, baseArg);
}
else if (Array.isArray(relativeArg)) {
var relativeArray = relativeArg;
var absoluteArray = [];
for (var key in relativeArray) {
absoluteArray.push(makeAbsolute(relativeArray[key], baseArg));
}
;
return absoluteArray;
}
else {
plugins.beautylog.error("smartpath.absolute() could not make sense of the input. " +
"Input is neither String nor Array");
return false;
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC50cmFuc2Zvcm0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDO0FBQzFDLElBQU8sT0FBTyxXQUFXLHFCQUFxQixDQUFDLENBQUM7QUFFaEQ7O2dEQUVnRDtBQUNoRCxJQUFJLFlBQVksR0FBRyxVQUFTLFlBQW1CLEVBQUUsT0FBZTtJQUM1RCxJQUFJLFlBQW1CLENBQUM7SUFDeEIsRUFBRSxDQUFBLENBQUMsT0FBTyxDQUFDLENBQUEsQ0FBQztRQUNSLFlBQVksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLEVBQUMsWUFBWSxDQUFDLENBQUM7SUFDM0QsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ0gsWUFBWSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFDO0lBQ3ZELENBQUM7SUFDRCxNQUFNLENBQUMsWUFBWSxDQUFDO0FBQ3hCLENBQUMsQ0FBQztBQUVGOztnREFFZ0Q7QUFDckMsa0JBQV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ZWxhdGl2ZUFycmF5ID0gcmVsYXRpdmVBcmdcbiAgICAgICAgbGV0IGFic29sdXRlQXJyYXk6c3RyaW5nW10gPSBbXTtcbiAgICAgICAgZm9yIChsZXQga2V5IGluIHJlbGF0aXZlQXJyYXkpe1xuICAgICAgICAgICAgYWJzb2x1dGVBcnJheS5wdXNoKG1ha2VBYnNvbHV0ZShyZWxhdGl2ZUFycmF5W2tleV0sYmFzZUFyZykpO1xuICAgICAgICB9O1xuICAgICAgICByZXR1cm4gYWJzb2x1dGVBcnJheTtcbiAgICB9IGVsc2Uge1xuICAgICAgICBwbHVnaW5zLmJlYXV0eWxvZy5lcnJvcihcInNtYXJ0cGF0aC5hYnNvbHV0ZSgpIGNvdWxkIG5vdCBtYWtlIHNlbnNlIG9mIHRoZSBpbnB1dC4gXCIgK1xuICAgICAgICAgICAgXCJJbnB1dCBpcyBuZWl0aGVyIFN0cmluZyBub3IgQXJyYXlcIik7XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9XG59OyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC/B,IAAI,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAE5C,QAAQ,CAAC,WAAW,EAAC;IACjB,QAAQ,CAAC,YAAY,EAAC;QAClB,IAAI,UAAU,GAAG,UAAU,CAAA;QAC3B,IAAI,cAAc,GAAG,sBAAsB,CAAC;QAC5C,IAAI,eAAe,GAAG,4BAA4B,CAAC;QACnD,IAAI,aAAa,GAAG,CAAC,cAAc,EAAC,cAAc,EAAC,eAAe,CAAC,CAAC;QACpE,EAAE,CAAC,+BAA+B,EAAC;YAC/B,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,MAAM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,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACjE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxE,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

View File

@ -3,24 +3,38 @@ let should = require("should");
let smartpath = require("../dist/index.js");
describe("smartpath",function(){
describe("absolute()",function(){
let baseString = "/basedir"
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.absolute(relativeString).should.startWith("/");
smartpath.absolute(relativeString).should.endWith(relativeString);
smartpath.absolute(relativeString,baseString).should.equal("/basedir/somedir/somefile.txt");
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.absolute(relativeArray);
let absoluteArray = smartpath.transform.toAbsolute(relativeArray);
absoluteArray[2].should.startWith("/");
absoluteArray[2].should.endWith(relativeString2);
})
it("should return false if neither String nor Array",function(){
smartpath.absolute(3).should.be.false();
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");
});
});
});
})
});

View File

@ -1,14 +1,16 @@
/// <reference path="typings/main.d.ts" />
import plugins = require("./smartpath.plugins");
import SmartpathAbsolute = require("./smartpath.absolute");
import SmartpathTransform = require("./smartpath.transform");
import SmartpathGet = require("./smartpath.get");
/**
*
* @type {{getPath: (function(any): undefined)}}
*/
let smartpath = {
absolute: SmartpathAbsolute
transform: SmartpathTransform,
get: SmartpathGet
};

11
ts/smartpath.get.ts Normal file
View File

@ -0,0 +1,11 @@
/// <reference path="typings/main.d.ts" />
import plugins = require("./smartpath.plugins");
export let type = function(pathStringArg:string):string {
let urlRegex = /http[s|\s]:\/\/.*/i
if(urlRegex.exec(pathStringArg)){
return "url";
} else {
return "local";
};
};

View File

@ -1,7 +1,10 @@
/// <reference path="typings/main.d.ts" />
import plugins = require("./smartpath.plugins");
var makeAbsolute = function(localPathArg:string, baseArg?:string):string {
/* ------------------------------------------ *
* ------------ helpers --------------------- *
* ------------------------------------------ */
let makeAbsolute = function(localPathArg:string, baseArg?:string):string {
let absolutePath:string;
if(baseArg){
absolutePath = plugins.path.join(baseArg,localPathArg);
@ -11,7 +14,10 @@ var makeAbsolute = function(localPathArg:string, baseArg?:string):string {
return absolutePath;
};
var absolute = function(relativeArg:any, baseArg?:string):any {
/* ------------------------------------------ *
* ------- export functions ----------------- *
* ------------------------------------------ */
export let toAbsolute = function(relativeArg:any, baseArg?:string):any {
if(typeof relativeArg === "string"){
return makeAbsolute(relativeArg,baseArg);
} else if(Array.isArray(relativeArg)){
@ -27,5 +33,3 @@ var absolute = function(relativeArg:any, baseArg?:string):any {
return false;
}
};
export = absolute;