added Smartpath class and path level array
This commit is contained in:
parent
c52c1902ee
commit
7916929550
19
dist/index.d.ts
vendored
19
dist/index.d.ts
vendored
@ -1,14 +1,5 @@
|
|||||||
import 'typings-global';
|
import check = require('./smartpath.check');
|
||||||
import SmartpathCheck = require('./smartpath.check');
|
import get = require('./smartpath.get');
|
||||||
import SmartpathGet = require('./smartpath.get');
|
import transform = require('./smartpath.transform');
|
||||||
import SmartpathTransform = require('./smartpath.transform');
|
export { check, get, transform };
|
||||||
/**
|
export * from './smartpath.classes.smartpath';
|
||||||
*
|
|
||||||
* @type {{getPath: (function(any): undefined)}}
|
|
||||||
*/
|
|
||||||
declare let smartpath: {
|
|
||||||
check: typeof SmartpathCheck;
|
|
||||||
get: typeof SmartpathGet;
|
|
||||||
transform: typeof SmartpathTransform;
|
|
||||||
};
|
|
||||||
export = smartpath;
|
|
||||||
|
26
dist/index.js
vendored
26
dist/index.js
vendored
@ -1,17 +1,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
function __export(m) {
|
||||||
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||||
|
}
|
||||||
// import modules
|
// import modules
|
||||||
const SmartpathCheck = require("./smartpath.check");
|
const check = require("./smartpath.check");
|
||||||
const SmartpathGet = require("./smartpath.get");
|
exports.check = check;
|
||||||
const SmartpathTransform = require("./smartpath.transform");
|
const get = require("./smartpath.get");
|
||||||
/**
|
exports.get = get;
|
||||||
*
|
const transform = require("./smartpath.transform");
|
||||||
* @type {{getPath: (function(any): undefined)}}
|
exports.transform = transform;
|
||||||
*/
|
__export(require("./smartpath.classes.smartpath"));
|
||||||
let smartpath = {
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsaUJBQWlCO0FBQ2pCLDJDQUEyQztBQU12QyxzQkFBSztBQUxULHVDQUF1QztBQU1uQyxrQkFBRztBQUxQLG1EQUFtRDtBQU0vQyw4QkFBUztBQUdiLG1EQUE2QyJ9
|
||||||
check: SmartpathCheck,
|
|
||||||
get: SmartpathGet,
|
|
||||||
transform: SmartpathTransform
|
|
||||||
};
|
|
||||||
module.exports = smartpath;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR3ZCLGlCQUFpQjtBQUNqQixvREFBb0Q7QUFDcEQsZ0RBQWdEO0FBQ2hELDREQUE0RDtBQUU1RDs7O0dBR0c7QUFDSCxJQUFJLFNBQVMsR0FBRztJQUNaLEtBQUssRUFBRSxjQUFjO0lBQ3JCLEdBQUcsRUFBRSxZQUFZO0lBQ2pCLFNBQVMsRUFBRSxrQkFBa0I7Q0FDaEMsQ0FBQTtBQUVELGlCQUFTLFNBQVMsQ0FBQSJ9
|
|
8
dist/smartpath.classes.smartpath.d.ts
vendored
Normal file
8
dist/smartpath.classes.smartpath.d.ts
vendored
Normal 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
12
dist/smartpath.classes.smartpath.js
vendored
Normal 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=
|
7
dist/smartpath.get.d.ts
vendored
7
dist/smartpath.get.d.ts
vendored
@ -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"
|
* 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 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
17
dist/smartpath.get.js
vendored
@ -1,5 +1,4 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
|
||||||
const plugins = require("./smartpath.plugins");
|
const plugins = require("./smartpath.plugins");
|
||||||
/**
|
/**
|
||||||
* returns the type of the given path. Can be "url" or "local"
|
* 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) {
|
exports.type = function (pathStringArg) {
|
||||||
let urlRegex = /http[s|\s]:\/\/.*/i;
|
let urlRegex = /http[s|\s]:\/\/.*/i;
|
||||||
if (urlRegex.exec(pathStringArg)) {
|
if (urlRegex.exec(pathStringArg)) {
|
||||||
return "url";
|
return 'url';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "local";
|
return 'local';
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
@ -22,4 +21,14 @@ exports.home = function (pathArgument) {
|
|||||||
return plugins.home();
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLmdldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0cGF0aC5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLCtDQUErQztBQUcvQzs7R0FFRztBQUNRLFFBQUEsSUFBSSxHQUFHLFVBQVUsYUFBcUI7S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QUMsT0FBTyxFQUFFLENBQUE7QUFDbkQsQ0FBQyxDQUFBIn0=
|
1
dist/smartpath.plugins.d.ts
vendored
1
dist/smartpath.plugins.d.ts
vendored
@ -1,4 +1,3 @@
|
|||||||
import 'typings-global';
|
import 'typings-global';
|
||||||
export import beautylog = require('beautylog');
|
|
||||||
export declare var home: any;
|
export declare var home: any;
|
||||||
export import path = require('path');
|
export import path = require('path');
|
||||||
|
3
dist/smartpath.plugins.js
vendored
3
dist/smartpath.plugins.js
vendored
@ -1,6 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
exports.beautylog = require("beautylog");
|
|
||||||
exports.home = require('home');
|
exports.home = require('home');
|
||||||
exports.path = require("path");
|
exports.path = require("path");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHBhdGgucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHlDQUErQztBQUNwQyxRQUFBLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7QUFDakMsK0JBQW9DIn0=
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHBhdGgucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ1osUUFBQSxJQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO0FBQ2pDLCtCQUFvQyJ9
|
4
dist/smartpath.transform.js
vendored
4
dist/smartpath.transform.js
vendored
@ -35,9 +35,9 @@ exports.toAbsolute = function (relativeArg, baseArg) {
|
|||||||
return absoluteArray;
|
return absoluteArray;
|
||||||
}
|
}
|
||||||
else {
|
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');
|
'Input is neither String nor Array');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnRyYW5zZm9ybS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0cGF0aC50cmFuc2Zvcm0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQ0FBK0M7QUFFL0M7O2dEQUVnRDtBQUVoRCxpQkFBaUI7QUFDakIsSUFBSSxZQUFZLEdBQUcsVUFBUyxZQUFvQixFQUFFLE9BQWdCO0lBQzlELElBQUksWUFBb0IsQ0FBQTtJQUN4QixJQUFJLGVBQWUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxZQUFZLENBQUMsQ0FBQTtJQUMzRCxFQUFFLENBQUMsQ0FBQyxPQUFPLElBQUksQ0FBQyxlQUFlLENBQUMsQ0FBQyxDQUFDO1FBQzlCLFlBQVksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLEVBQUMsWUFBWSxDQUFDLENBQUE7SUFDMUQsQ0FBQztJQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDLGVBQWUsQ0FBQyxDQUFDLENBQUM7UUFDekIsWUFBWSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFBO0lBQ3RELENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUN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xDQUFDO0lBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ3BDLElBQUksYUFBYSxHQUFHLFdBQVcsQ0FBQTtRQUMvQixJQUFJLGFBQWEsR0FBYSxFQUFFLENBQUE7UUFDaEMsR0FBRyxDQUFDLENBQUMsSUFBSSxHQUFHLElBQUksYUFBYSxDQUFDLENBQUMsQ0FBQztZQUM1QixhQUFhLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxhQUFhLENBQUMsR0FBRyxDQUFDLEVBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQTtRQUNoRSxDQUFDO1FBQ0QsTUFBTSxDQUFDLGFBQWEsQ0FBQTtJQUN4QixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsS0FBSyxDQUFDLDBEQUEwRDtZQUNwRSxtQ0FBbUMsQ0FBQyxDQUFBO1FBQ3hDLE1BQU0sQ0FBQyxLQUFLLENBQUE7SUFDaEIsQ0FBQztBQUNMLENBQUMsQ0FBQSJ9
|
@ -23,13 +23,13 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/smartpath",
|
"homepage": "https://github.com/pushrocks/smartpath",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^5.0.23",
|
|
||||||
"home": "^1.0.1",
|
"home": "^1.0.1",
|
||||||
"typings-global": "^1.0.14"
|
"typings-global": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.8",
|
"@types/should": "^8.1.30",
|
||||||
"should": "^11.1.0",
|
"npmts-g": "^5.2.10",
|
||||||
|
"should": "^11.1.1",
|
||||||
"typings-test": "^1.0.3"
|
"typings-test": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
test/test.d.ts
vendored
3
test/test.d.ts
vendored
@ -1,2 +1 @@
|
|||||||
import "typings-test";
|
import 'typings-test';
|
||||||
import "should";
|
|
||||||
|
104
test/test.js
104
test/test.js
@ -1,77 +1,79 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-test");
|
require("typings-test");
|
||||||
require("should");
|
const should = require("should");
|
||||||
let smartpath = require("../dist/index.js");
|
const smartpath = require("../dist/index.js");
|
||||||
describe("smartpath", function () {
|
describe('smartpath', function () {
|
||||||
describe(".check", function () {
|
describe('class Smartpath', function () {
|
||||||
let filePathString = "./somedir/somefile.json";
|
let mySmartpath;
|
||||||
let dirPathString = "./somedir/anotherdir";
|
it('should create a valid instance', function () {
|
||||||
let dirPathString2 = "./somedir/another.dir/";
|
mySmartpath = new smartpath.Smartpath('/some/path/to/some.file');
|
||||||
describe(".isFile", function () {
|
should(mySmartpath).be.instanceof(smartpath.Smartpath);
|
||||||
it("should be true for a file path", function () {
|
should(mySmartpath.pathLevelsBackwards).be.of.length(5);
|
||||||
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 () {
|
describe('.check', function () {
|
||||||
it("should be true for a directory path", function () {
|
let filePathString = './somedir/somefile.json';
|
||||||
smartpath.check.isDir(dirPathString)
|
let dirPathString = './somedir/anotherdir';
|
||||||
.should.be.true();
|
let dirPathString2 = './somedir/another.dir/';
|
||||||
smartpath.check.isDir(dirPathString2)
|
describe('.isFile', function () {
|
||||||
.should.be.true();
|
it('should be true for a file path', function () {
|
||||||
|
should(smartpath.check.isFile(filePathString)).be.true();
|
||||||
});
|
});
|
||||||
it("should be false for a file path", function () {
|
it('should be false for a directory path', function () {
|
||||||
smartpath.check.isDir(filePathString)
|
should(smartpath.check.isFile(dirPathString)).be.false();
|
||||||
.should.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('.transform', function () {
|
||||||
describe("toAbsolute()", function () {
|
describe('toAbsolute()', function () {
|
||||||
let baseString = "/basedir";
|
let baseString = '/basedir';
|
||||||
let relativeString = "somedir/somefile.txt";
|
let relativeString = 'somedir/somefile.txt';
|
||||||
let relativeString2 = "anotherdir/anotherfile.txt";
|
let relativeString2 = 'anotherdir/anotherfile.txt';
|
||||||
let relativeArray = [relativeString, relativeString, relativeString2];
|
let relativeArray = [relativeString, relativeString, relativeString2];
|
||||||
it("should make a string absolute", function () {
|
it('should make a string absolute', function () {
|
||||||
smartpath.transform.toAbsolute(relativeString).should.startWith("/");
|
should(smartpath.transform.toAbsolute(relativeString)).startWith('/');
|
||||||
smartpath.transform.toAbsolute(relativeString).should.endWith(relativeString);
|
should(smartpath.transform.toAbsolute(relativeString)).endWith(relativeString);
|
||||||
smartpath.transform.toAbsolute(relativeString, baseString).should.equal("/basedir/somedir/somefile.txt");
|
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);
|
let absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString);
|
||||||
absoluteArray[2].should.startWith("/");
|
should(absoluteArray[2]).startWith('/');
|
||||||
absoluteArray[2].should.endWith(relativeString2);
|
should(absoluteArray[2]).endWith(relativeString2);
|
||||||
});
|
});
|
||||||
it("should return false if neither String nor Array", function () {
|
it('should return false if neither String nor Array', function () {
|
||||||
smartpath.transform.toAbsolute(3).should.be.false();
|
should(smartpath.transform.toAbsolute(3)).be.false();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe(".get", function () {
|
describe('.get', function () {
|
||||||
describe(".type()", function () {
|
describe('.type()', function () {
|
||||||
it("should return 'url' for an URL", function () {
|
it("should return 'url' for an URL", function () {
|
||||||
smartpath.get.type("https://push.rocks/some/url").should.equal("url");
|
should(smartpath.get.type('https://push.rocks/some/url')).equal('url');
|
||||||
smartpath.get.type("https://push.rocks/some/url").should.not.equal("local");
|
should(smartpath.get.type('https://push.rocks/some/url')).not.equal('local');
|
||||||
});
|
});
|
||||||
it("should return 'path' for a Path", function () {
|
it("should return 'path' for a Path", function () {
|
||||||
smartpath.get.type("/some/absolute/path/").should.equal("local");
|
should(smartpath.get.type('/some/absolute/path/')).equal('local');
|
||||||
smartpath.get.type("./some/relative/path/").should.not.equal("url");
|
should(smartpath.get.type('./some/relative/path/')).not.equal('url');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe(".get()", function () {
|
describe('.get()', function () {
|
||||||
it("should a absolute path for an home relative URL", function () {
|
it('should a absolute path for an home relative URL', function () {
|
||||||
console.log(smartpath.get.home("~/test"));
|
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());
|
console.log(smartpath.get.home());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIj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sU0FBUyxDQUFDLEdBQUcsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxDQUFBO1lBQ3JDLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=
|
152
test/test.ts
152
test/test.ts
@ -1,77 +1,89 @@
|
|||||||
import "typings-test";
|
import 'typings-test'
|
||||||
import "should";
|
import * as should from 'should'
|
||||||
let smartpath = require("../dist/index.js");
|
import * as smartpath from '../dist/index.js'
|
||||||
|
|
||||||
describe("smartpath",function(){
|
describe('smartpath', function () {
|
||||||
describe(".check",function(){
|
describe('class Smartpath', function() {
|
||||||
let filePathString = "./somedir/somefile.json"
|
let mySmartpath: smartpath.Smartpath
|
||||||
let dirPathString = "./somedir/anotherdir"
|
it('should create a valid instance', function() {
|
||||||
let dirPathString2 = "./somedir/another.dir/"
|
mySmartpath = new smartpath.Smartpath('/some/path/to/some.file')
|
||||||
describe(".isFile",function(){
|
should(mySmartpath).be.instanceof(smartpath.Smartpath)
|
||||||
it("should be true for a file path",function(){
|
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)
|
smartpath.check.isFile(filePathString)
|
||||||
.should.be.true();
|
).be.true()
|
||||||
});
|
})
|
||||||
it("should be false for a directory path",function(){
|
it('should be false for a directory path', function () {
|
||||||
|
should(
|
||||||
smartpath.check.isFile(dirPathString)
|
smartpath.check.isFile(dirPathString)
|
||||||
.should.be.false();
|
).be.false()
|
||||||
|
should(
|
||||||
smartpath.check.isFile(dirPathString2)
|
smartpath.check.isFile(dirPathString2)
|
||||||
.should.be.false();
|
).be.false()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
describe(".isDir",function(){
|
describe('.isDir', function () {
|
||||||
it("should be true for a directory path",function(){
|
it('should be true for a directory path', function () {
|
||||||
smartpath.check.isDir(dirPathString)
|
should(smartpath.check.isDir(dirPathString)
|
||||||
.should.be.true();
|
).be.true()
|
||||||
smartpath.check.isDir(dirPathString2)
|
should(smartpath.check.isDir(dirPathString2)
|
||||||
.should.be.true();
|
).be.true()
|
||||||
});
|
})
|
||||||
it("should be false for a file path",function(){
|
it('should be false for a file path', function () {
|
||||||
|
should(
|
||||||
smartpath.check.isDir(filePathString)
|
smartpath.check.isDir(filePathString)
|
||||||
.should.be.false();
|
).be.false()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
describe(".transform",function(){
|
describe('.transform', function () {
|
||||||
describe("toAbsolute()",function(){
|
describe('toAbsolute()', function () {
|
||||||
let baseString = "/basedir";
|
let baseString = '/basedir'
|
||||||
let relativeString = "somedir/somefile.txt";
|
let relativeString = 'somedir/somefile.txt'
|
||||||
let relativeString2 = "anotherdir/anotherfile.txt";
|
let relativeString2 = 'anotherdir/anotherfile.txt'
|
||||||
let relativeArray = [relativeString,relativeString,relativeString2];
|
let relativeArray = [relativeString, relativeString, relativeString2]
|
||||||
it("should make a string absolute",function(){
|
it('should make a string absolute', function () {
|
||||||
smartpath.transform.toAbsolute(relativeString).should.startWith("/");
|
should(smartpath.transform.toAbsolute(relativeString)).startWith('/')
|
||||||
smartpath.transform.toAbsolute(relativeString).should.endWith(relativeString);
|
should(smartpath.transform.toAbsolute(relativeString)).endWith(relativeString)
|
||||||
smartpath.transform.toAbsolute(relativeString,baseString).should.equal("/basedir/somedir/somefile.txt");
|
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);
|
let absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString)
|
||||||
absoluteArray[2].should.startWith("/");
|
should(absoluteArray[2]).startWith('/')
|
||||||
absoluteArray[2].should.endWith(relativeString2);
|
should(absoluteArray[2]).endWith(relativeString2)
|
||||||
|
|
||||||
})
|
})
|
||||||
it("should return false if neither String nor Array",function(){
|
it('should return false if neither String nor Array', function () {
|
||||||
smartpath.transform.toAbsolute(3).should.be.false();
|
should(smartpath.transform.toAbsolute(3)).be.false()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
describe(".get",function(){
|
describe('.get', function () {
|
||||||
describe(".type()",function(){
|
describe('.type()', function () {
|
||||||
it("should return 'url' for an URL",function(){
|
it("should return 'url' for an URL", function () {
|
||||||
smartpath.get.type("https://push.rocks/some/url").should.equal("url");
|
should(smartpath.get.type('https://push.rocks/some/url')).equal('url')
|
||||||
smartpath.get.type("https://push.rocks/some/url").should.not.equal("local");
|
should(smartpath.get.type('https://push.rocks/some/url')).not.equal('local')
|
||||||
});
|
})
|
||||||
it("should return 'path' for a Path",function(){
|
it("should return 'path' for a Path", function () {
|
||||||
smartpath.get.type("/some/absolute/path/").should.equal("local");
|
should(smartpath.get.type('/some/absolute/path/')).equal('local')
|
||||||
smartpath.get.type("./some/relative/path/").should.not.equal("url");
|
should(smartpath.get.type('./some/relative/path/')).not.equal('url')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
describe(".get()",function(){
|
describe('.get()', function () {
|
||||||
it("should a absolute path for an home relative URL",function(){
|
it('should a absolute path for an home relative URL', function () {
|
||||||
console.log(smartpath.get.home("~/test"));
|
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());
|
console.log(smartpath.get.home())
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
24
ts/index.ts
24
ts/index.ts
@ -1,19 +1,13 @@
|
|||||||
import 'typings-global'
|
|
||||||
import plugins = require('./smartpath.plugins')
|
|
||||||
|
|
||||||
// import modules
|
// import modules
|
||||||
import SmartpathCheck = require('./smartpath.check')
|
import check = require('./smartpath.check')
|
||||||
import SmartpathGet = require('./smartpath.get')
|
import get = require('./smartpath.get')
|
||||||
import SmartpathTransform = require('./smartpath.transform')
|
import transform = require('./smartpath.transform')
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
export {
|
||||||
* @type {{getPath: (function(any): undefined)}}
|
check,
|
||||||
*/
|
get,
|
||||||
let smartpath = {
|
transform
|
||||||
check: SmartpathCheck,
|
|
||||||
get: SmartpathGet,
|
|
||||||
transform: SmartpathTransform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"
|
* 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
|
let urlRegex = /http[s|\s]:\/\/.*/i
|
||||||
if(urlRegex.exec(pathStringArg)){
|
if (urlRegex.exec(pathStringArg)) {
|
||||||
return "url";
|
return 'url'
|
||||||
} else {
|
} else {
|
||||||
return "local";
|
return 'local'
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export let home = function(pathArgument?:string){
|
export let home = function (pathArgument?: string) {
|
||||||
if(pathArgument){
|
if (pathArgument) {
|
||||||
return plugins.home.resolve(pathArgument);
|
return plugins.home.resolve(pathArgument)
|
||||||
} else {
|
} 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'
|
import 'typings-global'
|
||||||
export import beautylog = require ('beautylog')
|
|
||||||
export var home = require('home')
|
export var home = require('home')
|
||||||
export import path = require('path')
|
export import path = require('path')
|
||||||
|
@ -33,7 +33,7 @@ export let toAbsolute = function(relativeArg: string | string[], baseArg?: strin
|
|||||||
}
|
}
|
||||||
return absoluteArray
|
return absoluteArray
|
||||||
} else {
|
} 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')
|
'Input is neither String nor Array')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user