Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
4424973a12 | |||
22bc646de6 | |||
bd3ad78624 |
26
.gitignore
vendored
26
.gitignore
vendored
@ -1,20 +1,8 @@
|
|||||||
.nogit/
|
|
||||||
|
|
||||||
# artifacts
|
|
||||||
coverage/
|
|
||||||
public/
|
|
||||||
pages/
|
|
||||||
|
|
||||||
# installs
|
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.settings/
|
||||||
# caches
|
.idea/
|
||||||
.yarn/
|
docs/
|
||||||
.cache/
|
ts/typings/
|
||||||
.rpt2_cache
|
ts/**/*.js
|
||||||
|
ts/**/*.js.map
|
||||||
# builds
|
coverage/
|
||||||
dist/
|
|
||||||
dist_*/
|
|
||||||
|
|
||||||
# custom
|
|
111
.gitlab-ci.yml
111
.gitlab-ci.yml
@ -1,127 +1,40 @@
|
|||||||
# gitzone ci_default
|
image: hosttoday/ht-docker-node:latest
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- page
|
||||||
|
|
||||||
# ====================
|
testLTS:
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
audit:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci test lts
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci test stable
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci publish
|
||||||
- npmci npm publish
|
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g tslint typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: page
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- mkdir public
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci npmpage
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command tsdoc
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
only:
|
||||||
|
- tags
|
4
.npmignore
Normal file
4
.npmignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
docs/
|
||||||
|
coverage/
|
||||||
|
ts/
|
||||||
|
test/
|
15
.travis.yml
Normal file
15
.travis.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- 4
|
||||||
|
- stable
|
||||||
|
deploy:
|
||||||
|
provider: npm
|
||||||
|
email: npm@lossless.digital
|
||||||
|
api_key:
|
||||||
|
secure: C21gKjjg4W61RQlDo9vCjXjJ5NRvEoLuKe8IcKrTXEnn5R3ewnHfpgAQtXuBLvYuP6mIS6N2UxhcIo3BpsII1oOC4iJ4i3wqf6CH9hkmD1ejJe7qRiMKxltN0/4DHioySuolfcimKnOKSMGNQpOnze9lxqNi/qjUIgdsEY7soJRLIR9JQmhBBcRHoSzhxm6AnDmgEO75QsDIyhDH4wkWkOCOhRhjSfFNI6rm/om0XBRYkCKeNfz+Oqosnr8EkMVzsiRebLLXwZxzyCGSVFYQobtLxVqZDK5fvcz/GPyCbpDG/pZq5lxEkFYRiq+OmlIQn9Hz4C0i8VlXevS0ZatwS9iCGmG0/4ayUc2ksasY8o+bUfPJju0vKsCJJhtIj1e4GEj0ubisKirBOb5Oj8tMdf9RGLeNztFKRZEaM/ZoJ0gN//R9p4vWUZGMqJeIWh4I0hXA5Lv2OTUSl2h9bJ+Z678cb1k40w8bEVOij9GnUGQHybNwXV+8LZckap29/XDxguxtnYnuoX7L/dUfjkhK6JQRS9c7NDWOSzsnsy5kx0jHNaHac7vxMzmbdSRK71rNkzudtu2ECxONDc8aUNJLmUfL1tgYWt9/t9ramBqtmpp3w0S+s82PDHtoxAn02lWi2pz8pSp9ACP105qtUD9/1TCWtQUbYoL00QhFmlKzWwg=
|
||||||
|
on:
|
||||||
|
tags: true
|
||||||
|
repo: pushrocks/smartpath
|
||||||
|
notifications:
|
||||||
|
slack:
|
||||||
|
secure: f5Uss0z9RPl/QcA/DroB8loyE93aOYI6bqCkrsiUscmZtlv/TVQtT4dxqGA6uvcG6iTQDBi3Ul88dQxWkRm4IqbhY35/iMaV2dHW4FVYMAh8GQMbsfL2sALCcufxD9blw47awv3iFcwhV1EeyesscjgL0JIjduk96v/7G/6QIO2838M1lzlgtj+kRUkim8qkaEs1je3gRrhMUIjLuAdscMXyUKYFMjWo9ACSjVUl30R/ZNemb18itIja6i92GotreBgcfEMczvy58ovDC7xdJUsY8LjMI01DwY+WPRnI0tAhsuI8moBwwcdM4e3bAjKjucQRjO33O5bMWRZ6QCiYd0DnCEFyCPQLJ4GSy/tkD00n8ijLHAOSV3AH1zNbdK1EAdSPQXDvlI36KJn/2hyQLoitGHVUPr76ujJWP82ypO2tgIp3XQU0dJVCxDuHnwJO2+hjdI+gCPqxNTpjeujHx3UdkTGNRjuuf9dlZ/D08fApjYxy2fxItTqo3QjP/nrqvBXUOPP8yPHpjIT4H2t5Pr4SJjBGI6X4qhKyFj6s9rA/Xu1rL+45zu1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ=
|
29
.vscode/launch.json
vendored
29
.vscode/launch.json
vendored
@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "current file",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"json.schemas": [
|
|
||||||
{
|
|
||||||
"fileMatch": ["/npmextra.json"],
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"npmci": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for npmci"
|
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for gitzone",
|
|
||||||
"properties": {
|
|
||||||
"projectType": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["website", "element", "service", "npm"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Lossless GmbH
|
Copyright (c) 2015 Push.Rocks
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# smartpath
|
||||||
|
offers smart ways to handle paths
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
## Documentation
|
13
dist/index.d.ts
vendored
Normal file
13
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
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;
|
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLC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G59O1xyXG5cclxuXHJcbmV4cG9ydCA9IHNtYXJ0cGF0aDtcclxuIl19
|
3
dist/smartpath.check.d.ts
vendored
Normal file
3
dist/smartpath.check.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export declare let isDir: (pathArg: string) => boolean;
|
||||||
|
export declare let isFile: (pathArg: any) => boolean;
|
10
dist/smartpath.check.js
vendored
Normal file
10
dist/smartpath.check.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5jaGVjay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBR2IsYUFBSyxHQUFHLFVBQVMsT0FBYztJQUN0QyxNQUFNLENBQUMsQ0FBQyxjQUFNLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDNUIsQ0FBQyxDQUFBO0FBRVUsY0FBTSxHQUFHLFVBQVMsT0FBTztJQUNoQyxNQUFNLENBQUMsY0FBYyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLDRDQUE0QztBQUNyRixDQUFDLENBQUEiLCJmaWxlIjoic21hcnRwYXRoLmNoZWNrLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcclxuaW1wb3J0ICogYXMgcGx1Z2lucyBmcm9tIFwiLi9zbWFydHBhdGgucGx1Z2luc1wiO1xyXG5cclxuZXhwb3J0IGxldCBpc0RpciA9IGZ1bmN0aW9uKHBhdGhBcmc6c3RyaW5nKXtcclxuICAgIHJldHVybiAhaXNGaWxlKHBhdGhBcmcpO1xyXG59XHJcblxyXG5leHBvcnQgbGV0IGlzRmlsZSA9IGZ1bmN0aW9uKHBhdGhBcmcpe1xyXG4gICAgcmV0dXJuIC9cXC5bYS16QS1aXSokLy50ZXN0KHBhdGhBcmcpOyAvLyBjaGVja3MgaWYgdGhlcmUgaXMgYSAuYW55dGhpbmcgYXQgdGhlIGVuZFxyXG59Il19
|
6
dist/smartpath.get.d.ts
vendored
Normal file
6
dist/smartpath.get.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import "typings-global";
|
||||||
|
/**
|
||||||
|
* returns the type of the given path. Can be "url" or "local"
|
||||||
|
*/
|
||||||
|
export declare let type: (pathStringArg: string) => string;
|
||||||
|
export declare let home: (pathArgument?: string) => any;
|
26
dist/smartpath.get.js
vendored
Normal file
26
dist/smartpath.get.js
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5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4cG9ydCBsZXQgdHlwZSA9IGZ1bmN0aW9uKHBhdGhTdHJpbmdBcmc6c3RyaW5nKTpzdHJpbmcge1xyXG4gICAgbGV0IHVybFJlZ2V4ID0gL2h0dHBbc3xcXHNdOlxcL1xcLy4qL2lcclxuICAgIGlmKHVybFJlZ2V4LmV4ZWMocGF0aFN0cmluZ0FyZykpe1xyXG4gICAgICAgIHJldHVybiBcInVybFwiO1xyXG4gICAgfSBlbHNlIHtcclxuICAgICAgICByZXR1cm4gXCJsb2NhbFwiO1xyXG4gICAgfTtcclxufTtcclxuXHJcbmV4cG9ydCBsZXQgaG9tZSA9IGZ1bmN0aW9uKHBhdGhBcmd1bWVudD86c3RyaW5nKXtcclxuICAgIGlmKHBhdGhBcmd1bWVudCl7XHJcbiAgICAgICAgcmV0dXJuIHBsdWdpbnMuaG9tZS5yZXNvbHZlKHBhdGhBcmd1bWVudCk7XHJcbiAgICB9IGVsc2Uge1xyXG4gICAgICAgIHJldHVybiBwbHVnaW5zLmhvbWUoKTtcclxuICAgIH1cclxufTsiXX0=
|
4
dist/smartpath.plugins.d.ts
vendored
Normal file
4
dist/smartpath.plugins.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export declare var beautylog: any;
|
||||||
|
export declare var home: any;
|
||||||
|
export declare var path: any;
|
7
dist/smartpath.plugins.js
vendored
Normal file
7
dist/smartpath.plugins.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
exports.beautylog = require("beautylog");
|
||||||
|
exports.home = require("home");
|
||||||
|
exports.path = require("path");
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDYixpQkFBUyxHQUFHLE9BQU8sQ0FBRSxXQUFXLENBQUMsQ0FBQztBQUNsQyxZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLFlBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUMiLCJmaWxlIjoic21hcnRwYXRoLnBsdWdpbnMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiO1xyXG5leHBvcnQgdmFyIGJlYXV0eWxvZyA9IHJlcXVpcmUgKFwiYmVhdXR5bG9nXCIpO1xyXG5leHBvcnQgdmFyIGhvbWUgPSByZXF1aXJlKFwiaG9tZVwiKTtcclxuZXhwb3J0IHZhciBwYXRoID0gcmVxdWlyZShcInBhdGhcIik7XHJcblxyXG4iXX0=
|
2
dist/smartpath.transform.d.ts
vendored
Normal file
2
dist/smartpath.transform.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export declare let toAbsolute: (relativeArg: any, baseArg?: string) => any;
|
40
dist/smartpath.transform.js
vendored
Normal file
40
dist/smartpath.transform.js
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC50cmFuc2Zvcm0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxxQkFBcUIsQ0FBQyxDQUFBO0FBRS9DOztnREFFZ0Q7QUFDaEQsSUFBSSxZQUFZLEdBQUcsVUFBUyxZQUFtQixFQUFFLE9BQWU7SUFDNUQsSUFBSSxZQUFtQixDQUFDO0lBQ3hCLEVBQUUsQ0FBQSxDQUFDLE9BQU8sQ0FBQyxDQUFBLENBQUM7UUFDUixZQUFZLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFDLFlBQVksQ0FBQyxDQUFDO0lBQzNELENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNILFlBQVksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUN2RCxDQUFDO0lBQ0QsTUFBTSxDQUFDLFlBQVksQ0FBQztBQUN4QixDQUFDLENBQUM7QUFFRjs7Z0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zZSBpZihBcnJheS5pc0FycmF5KHJlbGF0aXZlQXJnKSl7XHJcbiAgICAgICAgbGV0IHJlbGF0aXZlQXJyYXkgPSByZWxhdGl2ZUFyZ1xyXG4gICAgICAgIGxldCBhYnNvbHV0ZUFycmF5OnN0cmluZ1tdID0gW107XHJcbiAgICAgICAgZm9yIChsZXQga2V5IGluIHJlbGF0aXZlQXJyYXkpe1xyXG4gICAgICAgICAgICBhYnNvbHV0ZUFycmF5LnB1c2gobWFrZUFic29sdXRlKHJlbGF0aXZlQXJyYXlba2V5XSxiYXNlQXJnKSk7XHJcbiAgICAgICAgfTtcclxuICAgICAgICByZXR1cm4gYWJzb2x1dGVBcnJheTtcclxuICAgIH0gZWxzZSB7XHJcbiAgICAgICAgcGx1Z2lucy5iZWF1dHlsb2cuZXJyb3IoXCJzbWFydHBhdGguYWJzb2x1dGUoKSBjb3VsZCBub3QgbWFrZSBzZW5zZSBvZiB0aGUgaW5wdXQuIFwiICtcclxuICAgICAgICAgICAgXCJJbnB1dCBpcyBuZWl0aGVyIFN0cmluZyBub3IgQXJyYXlcIik7XHJcbiAgICAgICAgcmV0dXJuIGZhbHNlO1xyXG4gICAgfVxyXG59OyJdfQ==
|
@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"npmci": {
|
|
||||||
"npmGlobalTools": [
|
|
||||||
"@gitzone/npmts"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"projectType": "npm",
|
|
||||||
"module": {
|
|
||||||
"githost": "gitlab.com",
|
|
||||||
"gitscope": "pushrocks",
|
|
||||||
"gitrepo": "smartpath",
|
|
||||||
"shortDescription": "offers smart ways to handle paths",
|
|
||||||
"npmPackagename": "@pushrocks/smartpath",
|
|
||||||
"license": "MIT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
4
npmts.json
Normal file
4
npmts.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"mode": "default",
|
||||||
|
"coveralls": "true"
|
||||||
|
}
|
1526
package-lock.json
generated
1526
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
40
package.json
40
package.json
@ -1,13 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpath",
|
"name": "smartpath",
|
||||||
"version": "4.0.2",
|
"version": "3.2.2",
|
||||||
"private": false,
|
|
||||||
"description": "offers smart ways to handle paths",
|
"description": "offers smart ways to handle paths",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test)",
|
"test": "(npmts)"
|
||||||
"build": "(tsbuild)"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,24 +22,14 @@
|
|||||||
"url": "https://github.com/pushrocks/smartpath/issues"
|
"url": "https://github.com/pushrocks/smartpath/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/smartpath",
|
"homepage": "https://github.com/pushrocks/smartpath",
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
"devDependencies": {
|
"beautylog": "^5.0.8",
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"home": "^1.0.1",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"typings-global": "^1.0.3"
|
||||||
"@gitzone/tstest": "^1.0.28",
|
|
||||||
"@pushrocks/tapbundle": "^3.2.0",
|
|
||||||
"@types/node": "^10.5.2"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"devDependencies": {
|
||||||
"ts/**/*",
|
"npmts": "^5.1.19",
|
||||||
"ts_web/**/*",
|
"should": "^9.0.0",
|
||||||
"dist/**/*",
|
"typings-test": "^1.0.1"
|
||||||
"dist_*/**/*",
|
}
|
||||||
"dist_ts/**/*",
|
|
||||||
"dist_ts_web/**/*",
|
|
||||||
"assets/**/*",
|
|
||||||
"cli.js",
|
|
||||||
"npmextra.json",
|
|
||||||
"readme.md"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "typings-test";
|
78
test/test.js
Normal file
78
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,U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C,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,qEAAqE,EAAC;gBACrE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
135
test/test.ts
135
test/test.ts
@ -1,66 +1,77 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import "typings-test"
|
||||||
import * as smartpath from '../ts/index';
|
let should = require("should");
|
||||||
|
let smartpath = require("../dist/index.js");
|
||||||
|
|
||||||
let mySmartpath: smartpath.Smartpath;
|
describe("smartpath",function(){
|
||||||
tap.test('expect create a valid instance', async () => {
|
describe(".check",function(){
|
||||||
mySmartpath = new smartpath.Smartpath('/some/path/to/some.file');
|
let filePathString = "./somedir/somefile.json"
|
||||||
expect(mySmartpath).to.be.instanceof(smartpath.Smartpath);
|
let dirPathString = "./somedir/anotherdir"
|
||||||
expect(mySmartpath.pathLevelsBackwards).to.be.of.length(5);
|
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);
|
||||||
|
|
||||||
let filePathString = './somedir/somefile.json';
|
})
|
||||||
let dirPathString = './somedir/anotherdir';
|
it("should return false if neither String nor Array",function(){
|
||||||
let dirPathString2 = './somedir/another.dir/';
|
smartpath.transform.toAbsolute(3).should.be.false();
|
||||||
|
});
|
||||||
tap.test('expect be true for a file path', async () => {
|
});
|
||||||
expect(smartpath.check.isFile(filePathString)).to.be.true;
|
});
|
||||||
});
|
describe(".get",function(){
|
||||||
tap.test('expect be false for a directory path', async () => {
|
describe(".type()",function(){
|
||||||
expect(smartpath.check.isFile(dirPathString)).to.be.false;
|
it("should return 'url' for an URL",function(){
|
||||||
expect(smartpath.check.isFile(dirPathString2)).to.be.false;
|
smartpath.get.type("https://push.rocks/some/url").should.equal("url");
|
||||||
});
|
smartpath.get.type("https://push.rocks/some/url").should.not.equal("local");
|
||||||
|
});
|
||||||
tap.test('expect be true for a directory path', async () => {
|
it("should return 'path' for a Path",function(){
|
||||||
expect(smartpath.check.isDir(dirPathString)).to.be.true;
|
smartpath.get.type("/some/absolute/path/").should.equal("local");
|
||||||
|
smartpath.get.type("./some/relative/path/").should.not.equal("url");
|
||||||
expect(smartpath.check.isDir(dirPathString2)).to.be.true;
|
});
|
||||||
});
|
});
|
||||||
|
describe(".get()",function(){
|
||||||
tap.test('expect be false for a file path', async () => {
|
it("should a absolute path for an home relative URL",function(){
|
||||||
expect(smartpath.check.isDir(filePathString)).to.be.false;
|
console.log(smartpath.get.home("~/test"));
|
||||||
});
|
});
|
||||||
|
it("should return the home directory path when no argument is specified",function(){
|
||||||
let baseString = '/basedir';
|
|
||||||
let relativeString = 'somedir/somefile.txt';
|
|
||||||
let relativeString2 = 'anotherdir/anotherfile.txt';
|
|
||||||
let relativeArray = [relativeString, relativeString, relativeString2];
|
|
||||||
tap.test('expect make a string absolute', async () => {
|
|
||||||
expect(smartpath.transform.toAbsolute(relativeString)).startWith('/');
|
|
||||||
expect(smartpath.transform.toAbsolute(relativeString)).endWith(relativeString);
|
|
||||||
expect(smartpath.transform.toAbsolute(relativeString, baseString)).equal(
|
|
||||||
'/basedir/somedir/somefile.txt'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
tap.test('expect make an array of relative Strings an Array of absolute Strings', async () => {
|
|
||||||
let absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString);
|
|
||||||
expect(absoluteArray[2]).to.startWith('/');
|
|
||||||
expect(absoluteArray[2]).endWith(relativeString2);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test("expect return 'url' for an URL", async () => {
|
|
||||||
expect(smartpath.get.type('https://push.rocks/some/url')).equal('url');
|
|
||||||
expect(smartpath.get.type('https://push.rocks/some/url')).not.equal('local');
|
|
||||||
});
|
|
||||||
tap.test("expect return 'path' for a Path", async () => {
|
|
||||||
expect(smartpath.get.type('/some/absolute/path/')).equal('local');
|
|
||||||
expect(smartpath.get.type('./some/relative/path/')).not.equal('url');
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('expect a absolute path for an home relative URL', async () => {
|
|
||||||
console.log(smartpath.get.home('~/test'));
|
|
||||||
});
|
|
||||||
tap.test('expect return the home directory path when no argument is specified', async () => {
|
|
||||||
console.log(smartpath.get.home());
|
console.log(smartpath.get.home());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
|
||||||
|
22
ts/index.ts
22
ts/index.ts
@ -1,8 +1,18 @@
|
|||||||
// import modules
|
/// <reference path="typings/main.d.ts" />
|
||||||
import * as check from './smartpath.check';
|
import plugins = require("./smartpath.plugins");
|
||||||
import * as get from './smartpath.get';
|
import SmartpathCheck = require("./smartpath.check");
|
||||||
import * as transform from './smartpath.transform';
|
import SmartpathGet = require("./smartpath.get");
|
||||||
|
import SmartpathTransform = require("./smartpath.transform");
|
||||||
|
|
||||||
export { check, get, transform };
|
/**
|
||||||
|
*
|
||||||
|
* @type {{getPath: (function(any): undefined)}}
|
||||||
|
*/
|
||||||
|
let smartpath = {
|
||||||
|
check: SmartpathCheck,
|
||||||
|
get: SmartpathGet,
|
||||||
|
transform: SmartpathTransform
|
||||||
|
};
|
||||||
|
|
||||||
export * from './smartpath.classes.smartpath';
|
|
||||||
|
export = smartpath;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import plugins = require('./smartpath.plugins');
|
import "typings-global";
|
||||||
|
import * as plugins from "./smartpath.plugins";
|
||||||
|
|
||||||
export let isDir = function(pathArg: string) {
|
export let isDir = function(pathArg:string){
|
||||||
return !isFile(pathArg);
|
return !isFile(pathArg);
|
||||||
};
|
}
|
||||||
|
|
||||||
export let isFile = function(pathArg) {
|
export let isFile = function(pathArg){
|
||||||
return /\.[a-zA-Z]*$/.test(pathArg); // checks if there is a .anything at the end
|
return /\.[a-zA-Z]*$/.test(pathArg); // checks if there is a .anything at the end
|
||||||
};
|
}
|
@ -1,15 +0,0 @@
|
|||||||
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,36 +1,22 @@
|
|||||||
import plugins = require('./smartpath.plugins');
|
import "typings-global";
|
||||||
export type TPathType = 'url' | 'local';
|
import * as plugins from "./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"
|
||||||
*/
|
*/
|
||||||
export let type = function(pathStringArg: string): TPathType {
|
export let type = function(pathStringArg:string):string {
|
||||||
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 pathArgument.replace('~', plugins.os.homedir());
|
return plugins.home.resolve(pathArgument);
|
||||||
} else {
|
} else {
|
||||||
return plugins.os.homedir();
|
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,5 @@
|
|||||||
import * as os from 'os';
|
import "typings-global";
|
||||||
import * as path from 'path';
|
export var beautylog = require ("beautylog");
|
||||||
|
export var home = require("home");
|
||||||
|
export var path = require("path");
|
||||||
|
|
||||||
export { os, path };
|
|
||||||
|
@ -1,19 +1,15 @@
|
|||||||
import plugins = require('./smartpath.plugins');
|
import "typings-global";
|
||||||
|
import * as plugins from "./smartpath.plugins";
|
||||||
|
|
||||||
/* ------------------------------------------ *
|
/* ------------------------------------------ *
|
||||||
* ------------ helpers --------------------- *
|
* ------------ helpers --------------------- *
|
||||||
* ------------------------------------------ */
|
* ------------------------------------------ */
|
||||||
|
let makeAbsolute = function(localPathArg:string, baseArg?:string):string {
|
||||||
// checks a file
|
let absolutePath:string;
|
||||||
let makeAbsolute = function(localPathArg: string, baseArg?: string): string {
|
if(baseArg){
|
||||||
let absolutePath: string;
|
absolutePath = plugins.path.join(baseArg,localPathArg);
|
||||||
let alreadyAbsolute = plugins.path.isAbsolute(localPathArg);
|
|
||||||
if (baseArg && !alreadyAbsolute) {
|
|
||||||
absolutePath = plugins.path.join(baseArg, localPathArg);
|
|
||||||
} else if (!alreadyAbsolute) {
|
|
||||||
absolutePath = plugins.path.resolve(localPathArg);
|
|
||||||
} else {
|
} else {
|
||||||
absolutePath = localPathArg;
|
absolutePath = plugins.path.resolve(localPathArg);
|
||||||
}
|
}
|
||||||
return absolutePath;
|
return absolutePath;
|
||||||
};
|
};
|
||||||
@ -21,21 +17,19 @@ let makeAbsolute = function(localPathArg: string, baseArg?: string): string {
|
|||||||
/* ------------------------------------------ *
|
/* ------------------------------------------ *
|
||||||
* ------- export functions ----------------- *
|
* ------- export functions ----------------- *
|
||||||
* ------------------------------------------ */
|
* ------------------------------------------ */
|
||||||
export let toAbsolute = function(relativeArg: string | string[], baseArg?: string): any {
|
export let toAbsolute = function(relativeArg:any, baseArg?:string):any {
|
||||||
if (typeof relativeArg === 'string') {
|
if(typeof relativeArg === "string"){
|
||||||
return makeAbsolute(relativeArg, baseArg);
|
return makeAbsolute(relativeArg,baseArg);
|
||||||
} else if (Array.isArray(relativeArg)) {
|
} else if(Array.isArray(relativeArg)){
|
||||||
let relativeArray = relativeArg;
|
let relativeArray = relativeArg
|
||||||
let absoluteArray: string[] = [];
|
let absoluteArray:string[] = [];
|
||||||
for (let key in relativeArray) {
|
for (let key in relativeArray){
|
||||||
absoluteArray.push(makeAbsolute(relativeArray[key], baseArg));
|
absoluteArray.push(makeAbsolute(relativeArray[key],baseArg));
|
||||||
}
|
};
|
||||||
return absoluteArray;
|
return absoluteArray;
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
plugins.beautylog.error("smartpath.absolute() could not make sense of the input. " +
|
||||||
'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;
|
||||||
}
|
}
|
||||||
};
|
};
|
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"
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user