Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
cc5f57da44 | |||
2866a76abc | |||
a8f93682fc | |||
2833666d14 | |||
0ca312bd02 | |||
a8f53ae2ae | |||
5b7f104c88 | |||
f2423f7c61 | |||
57680424c4 | |||
04b942092c | |||
209ff095a4 | |||
fb62b0aac7 | |||
736eefa91e | |||
8fc994737b | |||
32e478ef4e | |||
451e2e241f | |||
202914b19b | |||
373a4eed94 | |||
9a9f28bdff | |||
2bd242ac57 | |||
b113dcfbe0 | |||
dc6636d552 | |||
72c70c481a | |||
8986953592 | |||
8a2afe1a81 | |||
48f44ee937 |
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
.idea/
|
||||
docs/
|
||||
ts/typings/
|
||||
ts/**/*.js
|
||||
ts/**/*.js.map
|
||||
coverage/
|
4
.npmignore
Normal file
4
.npmignore
Normal file
@ -0,0 +1,4 @@
|
||||
docs/
|
||||
coverage/
|
||||
ts/
|
||||
test/
|
14
.travis.yml
14
.travis.yml
@ -1,16 +1,12 @@
|
||||
language: node_js
|
||||
before_install:
|
||||
- nvm install stable
|
||||
- node -v
|
||||
- npm -v
|
||||
- npm install -g gulp
|
||||
- npm install gulp
|
||||
- npm install gulp-typescript
|
||||
node_js:
|
||||
- 4
|
||||
- stable
|
||||
deploy:
|
||||
provider: npm
|
||||
email: npm@smart-coordination.com
|
||||
email: npm@lossless.digital
|
||||
api_key:
|
||||
secure: hfuRCg2RSNTvSe49w+rqx/fPt2OILDTjdYkga5BnGr0Rja5yL/2SpVNOP62lYNQBB61TfqfT8F4gQsQyAuygzhNT1ijZ4qCvSdqHqXki/0hzTVZAvfF2aoLxUnuCMAYawUyx5nibJKCmGXvH9MbMrEwV5Gh0uSf0HRmskp/GKuXw5epnMkOT2SEr9Mw7Hpu3VKLEALoKOI2hYBRv555sRFkI3Cd9v1n0384HEjCbQEwXhPwwki2XL2SXzGP8IOccE3x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p9ACP105qtUD9/1TCWtQUbYoL00QhFmlKzWwg=
|
||||
on:
|
||||
tags: true
|
||||
repo: pushrocks/smartpath
|
||||
|
@ -1,2 +1,6 @@
|
||||
# smartpath
|
||||
offers smart ways to handle paths
|
||||
|
||||
## Status
|
||||
|
||||
## Documentation
|
||||
|
16
dist/index.js
vendored
Normal file
16
dist/index.js
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
var SmartpathCheck = require("./smartpath.check");
|
||||
var SmartpathGet = require("./smartpath.get");
|
||||
var SmartpathTransform = require("./smartpath.transform");
|
||||
/**
|
||||
*
|
||||
* @type {{getPath: (function(any): undefined)}}
|
||||
*/
|
||||
var smartpath = {
|
||||
check: SmartpathCheck,
|
||||
get: SmartpathGet,
|
||||
transform: SmartpathTransform
|
||||
};
|
||||
module.exports = smartpath;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQSxJQUFPLGNBQWMsV0FBVyxtQkFBbUIsQ0FBQyxDQUFDO0FBQ3JELElBQU8sWUFBWSxXQUFXLGlCQUFpQixDQUFDLENBQUM7QUFDakQsSUFBTyxrQkFBa0IsV0FBVyx1QkFBdUIsQ0FBQyxDQUFDO0FBRTdEOzs7R0FHRztBQUNILElBQUksU0FBUyxHQUFHO0lBQ1osS0FBSyxFQUFFLGNBQWM7SUFDckIsR0FBRyxFQUFFLFlBQVk7SUFDakIsU0FBUyxFQUFFLGtCQUFrQjtDQUNoQyxDQUFDO0FBR0YsaUJBQVMsU0FBUyxDQUFDIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cInR5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmltcG9ydCBwbHVnaW5zID0gcmVxdWlyZShcIi4vc21hcnRwYXRoLnBsdWdpbnNcIik7XG5pbXBvcnQgU21hcnRwYXRoQ2hlY2sgPSByZXF1aXJlKFwiLi9zbWFydHBhdGguY2hlY2tcIik7XG5pbXBvcnQgU21hcnRwYXRoR2V0ID0gcmVxdWlyZShcIi4vc21hcnRwYXRoLmdldFwiKTtcbmltcG9ydCBTbWFydHBhdGhUcmFuc2Zvcm0gPSByZXF1aXJlKFwiLi9zbWFydHBhdGgudHJhbnNmb3JtXCIpO1xuXG4vKipcbiAqXG4gKiBAdHlwZSB7e2dldFBhdGg6IChmdW5jdGlvbihhbnkpOiB1bmRlZmluZWQpfX1cbiAqL1xubGV0IHNtYXJ0cGF0aCA9IHtcbiAgICBjaGVjazogU21hcnRwYXRoQ2hlY2ssXG4gICAgZ2V0OiBTbWFydHBhdGhHZXQsXG4gICAgdHJhbnNmb3JtOiBTbWFydHBhdGhUcmFuc2Zvcm1cbn07XG5cblxuZXhwb3J0ID0gc21hcnRwYXRoO1xuIl0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
|
9
dist/smartpath.check.js
vendored
Normal file
9
dist/smartpath.check.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
exports.isDir = function (pathArg) {
|
||||
return !exports.isFile(pathArg);
|
||||
};
|
||||
exports.isFile = function (pathArg) {
|
||||
return /\.[a-zA-Z]*$/.test(pathArg); // checks if there is a .anything at the end
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5jaGVjay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBRVcsYUFBSyxHQUFHLFVBQVMsT0FBYztJQUN0QyxNQUFNLENBQUMsQ0FBQyxjQUFNLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDNUIsQ0FBQyxDQUFBO0FBRVUsY0FBTSxHQUFHLFVBQVMsT0FBTztJQUNoQyxNQUFNLENBQUMsY0FBYyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLDRDQUE0QztBQUNyRixDQUFDLENBQUEiLCJmaWxlIjoic21hcnRwYXRoLmNoZWNrLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHBsdWdpbnMgPSByZXF1aXJlKFwiLi9zbWFydHBhdGgucGx1Z2luc1wiKTtcblxuZXhwb3J0IGxldCBpc0RpciA9IGZ1bmN0aW9uKHBhdGhBcmc6c3RyaW5nKXtcbiAgICByZXR1cm4gIWlzRmlsZShwYXRoQXJnKTtcbn1cblxuZXhwb3J0IGxldCBpc0ZpbGUgPSBmdW5jdGlvbihwYXRoQXJnKXtcbiAgICByZXR1cm4gL1xcLlthLXpBLVpdKiQvLnRlc3QocGF0aEFyZyk7IC8vIGNoZWNrcyBpZiB0aGVyZSBpcyBhIC5hbnl0aGluZyBhdCB0aGUgZW5kXG59Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
|
26
dist/smartpath.get.js
vendored
Normal file
26
dist/smartpath.get.js
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
var plugins = require("./smartpath.plugins");
|
||||
/**
|
||||
* returns the type of the given path. Can be "url" or "local"
|
||||
*/
|
||||
exports.type = function (pathStringArg) {
|
||||
var urlRegex = /http[s|\s]:\/\/.*/i;
|
||||
if (urlRegex.exec(pathStringArg)) {
|
||||
return "url";
|
||||
}
|
||||
else {
|
||||
return "local";
|
||||
}
|
||||
;
|
||||
};
|
||||
exports.home = function (pathArgument) {
|
||||
if (pathArgument) {
|
||||
return plugins.home.resolve(pathArgument);
|
||||
}
|
||||
else {
|
||||
return plugins.home();
|
||||
}
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBDQUEwQztBQUMxQy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gICBsZXQgdXJsUmVnZXggPSAvaHR0cFtzfFxcc106XFwvXFwvLiovaVxuICAgIGlmKHVybFJlZ2V4LmV4ZWMocGF0aFN0cmluZ0FyZykpe1xuICAgICAgICByZXR1cm4gXCJ1cmxcIjtcbiAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gXCJsb2NhbFwiO1xuICAgIH07XG59O1xuXG5leHBvcnQgbGV0IGhvbWUgPSBmdW5jdGlvbihwYXRoQXJndW1lbnQ/OnN0cmluZyl7XG4gICAgaWYocGF0aEFyZ3VtZW50KXtcbiAgICAgICAgcmV0dXJuIHBsdWdpbnMuaG9tZS5yZXNvbHZlKHBhdGhBcmd1bWVudCk7XG4gICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIHBsdWdpbnMuaG9tZSgpO1xuICAgIH1cbn07Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
|
7
dist/smartpath.plugins.js
vendored
Normal file
7
dist/smartpath.plugins.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.home = require("home");
|
||||
exports.path = require("path");
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDakMsaUJBQVMsR0FBRyxPQUFPLENBQUUsV0FBVyxDQUFDLENBQUM7QUFDbEMsWUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztBQUN2QixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0cGF0aC5wbHVnaW5zLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxuZXhwb3J0IHZhciBiZWF1dHlsb2cgPSByZXF1aXJlIChcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCB2YXIgaG9tZSA9IHJlcXVpcmUoXCJob21lXCIpO1xuZXhwb3J0IHZhciBwYXRoID0gcmVxdWlyZShcInBhdGhcIik7XG5cbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
40
dist/smartpath.transform.js
vendored
Normal file
40
dist/smartpath.transform.js
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
/// <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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC50cmFuc2Zvcm0udHMiXSwib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5laXRoZXIgU3RyaW5nIG5vciBBcnJheVwiKTtcbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cbn07Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
|
19
index.js
19
index.js
@ -1,19 +0,0 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var path = require("path");
|
||||
var bl = require("beautylog");
|
||||
/**
|
||||
*
|
||||
* @type {{getPath: (function(any): undefined)}}
|
||||
*/
|
||||
var smartpath = {
|
||||
getAbsPath: function (varPath, logBool) {
|
||||
if (logBool === void 0) { logBool = false; }
|
||||
var absPath = path.resolve(varPath);
|
||||
if (logBool == true) {
|
||||
bl.log('varPath is' + varPath);
|
||||
bl.log('absPath is' + absPath);
|
||||
}
|
||||
return absPath;
|
||||
}
|
||||
};
|
||||
module.exports = smartpath;
|
4
npmts.json
Normal file
4
npmts.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"mode": "default",
|
||||
"coveralls": "true"
|
||||
}
|
17
package.json
17
package.json
@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "smartpath",
|
||||
"version": "1.0.2",
|
||||
"version": "3.1.5",
|
||||
"description": "offers smart ways to handle paths",
|
||||
"main": "index.js",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "cd ts/compile && gulp"
|
||||
"test": "(npmts)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -15,11 +15,18 @@
|
||||
"jade",
|
||||
"template"
|
||||
],
|
||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/smartpath/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/smartpath",
|
||||
"dependencies": {}
|
||||
"dependencies": {
|
||||
"beautylog": "^4.1.2",
|
||||
"home": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts": "^5.0.4",
|
||||
"should": "^8.3.1"
|
||||
}
|
||||
}
|
||||
|
77
test/test.js
Normal file
77
test/test.js
Normal file
File diff suppressed because one or more lines are too long
1
test/test.js.map
Normal file
1
test/test.js.map
Normal file
@ -0,0 +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,QAAQ,CAAC,cAAc,EAAC;YACpB,IAAI,UAAU,GAAG,UAAU,CAAC;YAC5B,IAAI,cAAc,GAAG,sBAAsB,CAAC;YAC5C,IAAI,eAAe,GAAG,4BAA4B,CAAC;YACnD,IAAI,aAAa,GAAG,CAAC,cAAc,EAAC,cAAc,EAAC,eAAe,CAAC,CAAC;YACpE,EAAE,CAAC,+BAA+B,EAAC;gBAC/B,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;gBACrE,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;gBAC9E,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,cAAc,EAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC5G,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,uEAAuE,EAAC;gBACvE,IAAI,aAAa,GAAG,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,aAAa,EAAC,UAAU,CAAC,CAAC;gBAC7E,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC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AAE,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
77
test/test.ts
Normal file
77
test/test.ts
Normal file
@ -0,0 +1,77 @@
|
||||
/// <reference path="../ts/typings/main.d.ts" />
|
||||
let should = 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();
|
||||
});
|
||||
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);
|
||||
|
||||
})
|
||||
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());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,2 +0,0 @@
|
||||
nvm use v0.12.7
|
||||
gulp
|
@ -1,16 +0,0 @@
|
||||
// import gulp
|
||||
var gulp = require("gulp"),
|
||||
gulpTypescript = require("gulp-typescript");
|
||||
|
||||
gulp.task('compileTS', function() {
|
||||
var stream = gulp.src('../index.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "index.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('default',['compileTS'], function() {
|
||||
console.log('Typescript compiled');
|
||||
});
|
@ -1,2 +0,0 @@
|
||||
# How to compile.
|
||||
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.
|
24
ts/index.ts
24
ts/index.ts
@ -1,22 +1,18 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
|
||||
var path = require("path");
|
||||
var bl = require("beautylog");
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
import plugins = require("./smartpath.plugins");
|
||||
import SmartpathCheck = require("./smartpath.check");
|
||||
import SmartpathGet = require("./smartpath.get");
|
||||
import SmartpathTransform = require("./smartpath.transform");
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {{getPath: (function(any): undefined)}}
|
||||
*/
|
||||
var smartpath:any = {
|
||||
getAbsPath: function(varPath,logBool = false) {
|
||||
var absPath = path.resolve(varPath);
|
||||
if (logBool == true) {
|
||||
bl.log('varPath is' + varPath);
|
||||
bl.log('absPath is' + absPath);
|
||||
}
|
||||
return absPath;
|
||||
}
|
||||
let smartpath = {
|
||||
check: SmartpathCheck,
|
||||
get: SmartpathGet,
|
||||
transform: SmartpathTransform
|
||||
};
|
||||
|
||||
|
||||
module.exports = smartpath;
|
||||
export = smartpath;
|
||||
|
9
ts/smartpath.check.ts
Normal file
9
ts/smartpath.check.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import plugins = require("./smartpath.plugins");
|
||||
|
||||
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
|
||||
}
|
22
ts/smartpath.get.ts
Normal file
22
ts/smartpath.get.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
import plugins = require("./smartpath.plugins");
|
||||
|
||||
/**
|
||||
* returns the type of the given path. Can be "url" or "local"
|
||||
*/
|
||||
export let type = function(pathStringArg:string):string {
|
||||
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();
|
||||
}
|
||||
};
|
5
ts/smartpath.plugins.ts
Normal file
5
ts/smartpath.plugins.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
export var beautylog = require ("beautylog");
|
||||
export var home = require("home");
|
||||
export var path = require("path");
|
||||
|
35
ts/smartpath.transform.ts
Normal file
35
ts/smartpath.transform.ts
Normal file
@ -0,0 +1,35 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
import plugins = require("./smartpath.plugins");
|
||||
|
||||
/* ------------------------------------------ *
|
||||
* ------------ helpers --------------------- *
|
||||
* ------------------------------------------ */
|
||||
let makeAbsolute = function(localPathArg:string, baseArg?:string):string {
|
||||
let absolutePath:string;
|
||||
if(baseArg){
|
||||
absolutePath = plugins.path.join(baseArg,localPathArg);
|
||||
} else {
|
||||
absolutePath = plugins.path.resolve(localPathArg);
|
||||
}
|
||||
return absolutePath;
|
||||
};
|
||||
|
||||
/* ------------------------------------------ *
|
||||
* ------- export functions ----------------- *
|
||||
* ------------------------------------------ */
|
||||
export let toAbsolute = function(relativeArg:any, 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 {
|
||||
plugins.beautylog.error("smartpath.absolute() could not make sense of the input. " +
|
||||
"Input is neither String nor Array");
|
||||
return false;
|
||||
}
|
||||
};
|
12
ts/tsd.json
12
ts/tsd.json
@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": "v4",
|
||||
"repo": "borisyankov/DefinitelyTyped",
|
||||
"ref": "master",
|
||||
"path": "typings",
|
||||
"bundle": "typings/tsd.d.ts",
|
||||
"installed": {
|
||||
"node/node.d.ts": {
|
||||
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
||||
}
|
||||
}
|
||||
}
|
6
ts/typings.json
Normal file
6
ts/typings.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"mocha": "github:DefinitelyTyped/DefinitelyTyped/mocha/mocha.d.ts#d6dd320291705694ba8e1a79497a908e9f5e6617",
|
||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
||||
}
|
||||
}
|
2079
ts/typings/node/node.d.ts
vendored
2079
ts/typings/node/node.d.ts
vendored
File diff suppressed because it is too large
Load Diff
1
ts/typings/tsd.d.ts
vendored
1
ts/typings/tsd.d.ts
vendored
@ -1 +0,0 @@
|
||||
/// <reference path="node/node.d.ts" />
|
Reference in New Issue
Block a user