Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
027b3fe9ad | |||
1b4681c065 | |||
96168fd870 | |||
e81c37e60a | |||
87454d41da | |||
97ae2d87b1 | |||
e23624a93f | |||
7183fcc00a | |||
9fad6100f0 | |||
d0e3065d12 | |||
5245e50f3d | |||
00bb39b8fe | |||
ddfae30a18 | |||
618b3da86e | |||
482bc6c18e | |||
ac988b9b09 | |||
0b6c83a806 | |||
37cbf0f8c8 | |||
29decabf91 | |||
afcb5d5b0c | |||
53905df003 | |||
09d424e972 | |||
f66864d0af | |||
930d90345a | |||
39835a4d27 | |||
13c001c48a | |||
7916929550 | |||
c52c1902ee | |||
06c60d42c1 |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,20 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
pages/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
141
.gitlab-ci.yml
Normal file
141
.gitlab-ci.yml
Normal file
@ -0,0 +1,141 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
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 --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
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:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
@ -1,4 +0,0 @@
|
||||
docs/
|
||||
coverage/
|
||||
ts/
|
||||
test/
|
15
.travis.yml
15
.travis.yml
@ -1,15 +0,0 @@
|
||||
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=
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"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", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
# smartpath
|
||||
offers smart ways to handle paths
|
||||
|
||||
## Status
|
||||
|
||||
## Documentation
|
14
dist/index.d.ts
vendored
14
dist/index.d.ts
vendored
@ -1,14 +0,0 @@
|
||||
import 'typings-global';
|
||||
import SmartpathCheck = require('./smartpath.check');
|
||||
import SmartpathGet = require('./smartpath.get');
|
||||
import SmartpathTransform = require('./smartpath.transform');
|
||||
/**
|
||||
*
|
||||
* @type {{getPath: (function(any): undefined)}}
|
||||
*/
|
||||
declare let smartpath: {
|
||||
check: typeof SmartpathCheck;
|
||||
get: typeof SmartpathGet;
|
||||
transform: typeof SmartpathTransform;
|
||||
};
|
||||
export = smartpath;
|
17
dist/index.js
vendored
17
dist/index.js
vendored
@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
// import modules
|
||||
const SmartpathCheck = require("./smartpath.check");
|
||||
const SmartpathGet = require("./smartpath.get");
|
||||
const SmartpathTransform = require("./smartpath.transform");
|
||||
/**
|
||||
*
|
||||
* @type {{getPath: (function(any): undefined)}}
|
||||
*/
|
||||
let smartpath = {
|
||||
check: SmartpathCheck,
|
||||
get: SmartpathGet,
|
||||
transform: SmartpathTransform
|
||||
};
|
||||
module.exports = smartpath;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR3ZCLGlCQUFpQjtBQUNqQixvREFBb0Q7QUFDcEQsZ0RBQWdEO0FBQ2hELDREQUE0RDtBQUU1RDs7O0dBR0c7QUFDSCxJQUFJLFNBQVMsR0FBRztJQUNaLEtBQUssRUFBRSxjQUFjO0lBQ3JCLEdBQUcsRUFBRSxZQUFZO0lBQ2pCLFNBQVMsRUFBRSxrQkFBa0I7Q0FDaEMsQ0FBQTtBQUVELGlCQUFTLFNBQVMsQ0FBQSJ9
|
3
dist/smartpath.check.d.ts
vendored
3
dist/smartpath.check.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
import 'typings-global';
|
||||
export declare let isDir: (pathArg: string) => boolean;
|
||||
export declare let isFile: (pathArg: any) => boolean;
|
9
dist/smartpath.check.js
vendored
9
dist/smartpath.check.js
vendored
@ -1,9 +0,0 @@
|
||||
"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;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLmNoZWNrLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRwYXRoLmNoZWNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFHWixRQUFBLEtBQUssR0FBRyxVQUFTLE9BQWU7SUFDdkMsTUFBTSxDQUFDLENBQUMsY0FBTSxDQUFDLE9BQU8sQ0FBQyxDQUFBO0FBQzNCLENBQUMsQ0FBQTtBQUVVLFFBQUEsTUFBTSxHQUFHLFVBQVMsT0FBTztJQUNoQyxNQUFNLENBQUMsY0FBYyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQSxDQUFDLDRDQUE0QztBQUNwRixDQUFDLENBQUEifQ==
|
6
dist/smartpath.get.d.ts
vendored
6
dist/smartpath.get.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
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;
|
25
dist/smartpath.get.js
vendored
25
dist/smartpath.get.js
vendored
@ -1,25 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
const plugins = require("./smartpath.plugins");
|
||||
/**
|
||||
* returns the type of the given path. Can be "url" or "local"
|
||||
*/
|
||||
exports.type = function (pathStringArg) {
|
||||
let 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLmdldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0cGF0aC5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUN4QiwrQ0FBZ0Q7QUFFaEQ7O0dBRUc7QUFDUSxRQUFBLElBQUksR0FBRyxVQUFTLGFBQW9CO0lBQzNDLElBQUksUUFBUSxHQUFHLG9CQUFvQixDQUFBO0lBQ25DLEVBQUUsQ0FBQSxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQSxDQUFDO1FBQzdCLE1BQU0sQ0FBQyxLQUFLLENBQUM7SUFDakIsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ0osTUFBTSxDQUFDLE9BQU8sQ0FBQztJQUNuQixDQUFDO0lBQUEsQ0FBQztBQUNOLENBQUMsQ0FBQztBQUVTLFFBQUEsSUFBSSxHQUFHLFVBQVMsWUFBb0I7SUFDM0MsRUFBRSxDQUFBLENBQUMsWUFBWSxDQUFDLENBQUEsQ0FBQztRQUNiLE1BQU0sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUM5QyxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsT0FBTyxDQUFDLElBQUksRUFBRSxDQUFDO0lBQzFCLENBQUM7QUFDTCxDQUFDLENBQUMifQ==
|
4
dist/smartpath.plugins.d.ts
vendored
4
dist/smartpath.plugins.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import 'typings-global';
|
||||
export import beautylog = require('beautylog');
|
||||
export declare var home: any;
|
||||
export import path = require('path');
|
6
dist/smartpath.plugins.js
vendored
6
dist/smartpath.plugins.js
vendored
@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.home = require('home');
|
||||
exports.path = require("path");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHBhdGgucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHlDQUErQztBQUNwQyxRQUFBLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7QUFDakMsK0JBQW9DIn0=
|
2
dist/smartpath.transform.d.ts
vendored
2
dist/smartpath.transform.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import 'typings-global';
|
||||
export declare let toAbsolute: (relativeArg: string | string[], baseArg?: string) => any;
|
43
dist/smartpath.transform.js
vendored
43
dist/smartpath.transform.js
vendored
@ -1,43 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
const plugins = require("./smartpath.plugins");
|
||||
/* ------------------------------------------ *
|
||||
* ------------ helpers --------------------- *
|
||||
* ------------------------------------------ */
|
||||
// checks a file
|
||||
let makeAbsolute = function (localPathArg, baseArg) {
|
||||
let absolutePath;
|
||||
let alreadyAbsolute = plugins.path.isAbsolute(localPathArg);
|
||||
if (baseArg && !alreadyAbsolute) {
|
||||
absolutePath = plugins.path.join(baseArg, localPathArg);
|
||||
}
|
||||
else if (!alreadyAbsolute) {
|
||||
absolutePath = plugins.path.resolve(localPathArg);
|
||||
}
|
||||
else {
|
||||
absolutePath = localPathArg;
|
||||
}
|
||||
return absolutePath;
|
||||
};
|
||||
/* ------------------------------------------ *
|
||||
* ------- export functions ----------------- *
|
||||
* ------------------------------------------ */
|
||||
exports.toAbsolute = function (relativeArg, baseArg) {
|
||||
if (typeof relativeArg === 'string') {
|
||||
return makeAbsolute(relativeArg, baseArg);
|
||||
}
|
||||
else if (Array.isArray(relativeArg)) {
|
||||
let relativeArray = relativeArg;
|
||||
let absoluteArray = [];
|
||||
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;
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnRyYW5zZm9ybS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY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UMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ3BDLElBQUksYUFBYSxHQUFHLFdBQVcsQ0FBQTtRQUMvQixJQUFJLGFBQWEsR0FBYSxFQUFFLENBQUE7UUFDaEMsR0FBRyxDQUFDLENBQUMsSUFBSSxHQUFHLElBQUksYUFBYSxDQUFDLENBQUMsQ0FBQztZQUM1QixhQUFhLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxhQUFhLENBQUMsR0FBRyxDQUFDLEVBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQTtRQUNoRSxDQUFDO1FBQ0QsTUFBTSxDQUFDLGFBQWEsQ0FBQTtJQUN4QixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQywwREFBMEQ7WUFDOUUsbUNBQW1DLENBQUMsQ0FBQTtRQUN4QyxNQUFNLENBQUMsS0FBSyxDQUFBO0lBQ2hCLENBQUM7QUFDTCxDQUFDLENBQUEifQ==
|
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Push.Rocks
|
||||
Copyright (c) 2015 Lossless GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
16
npmextra.json
Normal file
16
npmextra.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartpath",
|
||||
"description": "offers smart ways to handle paths",
|
||||
"npmPackagename": "@pushrocks/smartpath",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"mode": "default",
|
||||
"coveralls": "true"
|
||||
}
|
18276
package-lock.json
generated
Normal file
18276
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
package.json
43
package.json
@ -1,11 +1,14 @@
|
||||
{
|
||||
"name": "smartpath",
|
||||
"version": "3.2.4",
|
||||
"name": "@pushrocks/smartpath",
|
||||
"version": "5.0.5",
|
||||
"private": false,
|
||||
"description": "offers smart ways to handle paths",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -22,14 +25,26 @@
|
||||
"url": "https://github.com/pushrocks/smartpath/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/smartpath",
|
||||
"dependencies": {
|
||||
"beautylog": "^5.0.23",
|
||||
"home": "^1.0.1",
|
||||
"typings-global": "^1.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.8",
|
||||
"should": "^11.1.0",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.48",
|
||||
"@gitzone/tsrun": "^1.2.31",
|
||||
"@gitzone/tstest": "^1.0.67",
|
||||
"@pushrocks/tapbundle": "^5.0.2",
|
||||
"@types/node": "^17.0.21"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
45
readme.md
Normal file
45
readme.md
Normal file
@ -0,0 +1,45 @@
|
||||
# @pushrocks/smartpath
|
||||
offers smart ways to handle paths
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpath)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartpath)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartpath)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpath/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
|
||||
[](https://push.rocks)
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import "typings-test";
|
||||
import "should";
|
77
test/test.js
77
test/test.js
@ -1,77 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
require("should");
|
||||
let smartpath = require("../dist/index.js");
|
||||
describe("smartpath", function () {
|
||||
describe(".check", function () {
|
||||
let filePathString = "./somedir/somefile.json";
|
||||
let dirPathString = "./somedir/anotherdir";
|
||||
let dirPathString2 = "./somedir/another.dir/";
|
||||
describe(".isFile", function () {
|
||||
it("should be true for a file path", function () {
|
||||
smartpath.check.isFile(filePathString)
|
||||
.should.be.true();
|
||||
});
|
||||
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());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFzQjtBQUN0QixrQkFBZ0I7QUFDaEIsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBQUM7QUFFNUMsUUFBUSxDQUFDLFdBQVcsRUFBQztJQUNqQixRQUFRLENBQUMsUUFBUSxFQUFDO1FBQ2QsSUFBSSxjQUFjLEdBQUcseUJBQXlCLENBQUE7UUFDOUMsSUFBSSxhQUFhLEdBQUcsc0JBQXNCLENBQUE7UUFDMUMsSUFBSSxjQUFjLEdBQUcsd0JBQXdCLENBQUE7UUFDN0MsUUFBUSxDQUFDLFNBQVMsRUFBQztZQUNmLEVBQUUsQ0FBQyxnQ0FBZ0MsRUFBQztnQkFDaEMsU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CAAC,CAAC;QACH,QAAQ,CAAC,QAAQ,EAAC;YACd,EAAE,CAAC,iDAAiD,EAAC;gBACjD,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC9C,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"}
|
113
test/test.ts
113
test/test.ts
@ -1,77 +1,66 @@
|
||||
import "typings-test";
|
||||
import "should";
|
||||
let smartpath = require("../dist/index.js");
|
||||
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||
import * as smartpath from '../ts/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();
|
||||
let mySmartpath: smartpath.Smartpath;
|
||||
tap.test('expect create a valid instance', async () => {
|
||||
mySmartpath = new smartpath.Smartpath('/some/path/to/some.file');
|
||||
expect(mySmartpath).toBeInstanceOf(smartpath.Smartpath);
|
||||
expect(mySmartpath.pathLevelsBackwards.length === 5).toBeTrue();
|
||||
});
|
||||
it("should be false for a directory path",function(){
|
||||
smartpath.check.isFile(dirPathString)
|
||||
.should.be.false();
|
||||
smartpath.check.isFile(dirPathString2)
|
||||
.should.be.false();
|
||||
|
||||
let filePathString = './somedir/somefile.json';
|
||||
let dirPathString = './somedir/anotherdir';
|
||||
let dirPathString2 = './somedir/another.dir/';
|
||||
|
||||
tap.test('expect be true for a file path', async () => {
|
||||
expect(smartpath.check.isFile(filePathString)).toBeTrue();
|
||||
});
|
||||
tap.test('expect be false for a directory path', async () => {
|
||||
expect(smartpath.check.isFile(dirPathString)).toBeFalse();
|
||||
expect(smartpath.check.isFile(dirPathString2)).toBeFalse();
|
||||
});
|
||||
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();
|
||||
|
||||
tap.test('expect be true for a directory path', async () => {
|
||||
expect(smartpath.check.isDir(dirPathString)).toBeTrue();
|
||||
|
||||
expect(smartpath.check.isDir(dirPathString2)).toBeTrue();
|
||||
});
|
||||
it("should be false for a file path",function(){
|
||||
smartpath.check.isDir(filePathString)
|
||||
.should.be.false();
|
||||
|
||||
tap.test('expect be false for a file path', async () => {
|
||||
expect(smartpath.check.isDir(filePathString)).toBeFalse();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe(".transform",function(){
|
||||
describe("toAbsolute()",function(){
|
||||
let baseString = "/basedir";
|
||||
let relativeString = "somedir/somefile.txt";
|
||||
let relativeString2 = "anotherdir/anotherfile.txt";
|
||||
|
||||
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");
|
||||
tap.test('expect make a string absolute', async () => {
|
||||
expect(smartpath.transform.toAbsolute(relativeString)).toStartWith('/');
|
||||
expect(smartpath.transform.toAbsolute(relativeString)).toEndWith(relativeString);
|
||||
expect(smartpath.transform.toAbsolute(relativeString, baseString)).toEqual(
|
||||
'/basedir/somedir/somefile.txt'
|
||||
);
|
||||
});
|
||||
it("should make an array of relative Strings an Array of absolute Strings",function(){
|
||||
tap.test('expect make an array of relative Strings an Array of absolute Strings', async () => {
|
||||
let absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString);
|
||||
absoluteArray[2].should.startWith("/");
|
||||
absoluteArray[2].should.endWith(relativeString2);
|
||||
expect(absoluteArray[2]).toStartWith('/');
|
||||
expect(absoluteArray[2]).toEndWith(relativeString2);
|
||||
});
|
||||
|
||||
})
|
||||
it("should return false if neither String nor Array",function(){
|
||||
smartpath.transform.toAbsolute(3).should.be.false();
|
||||
tap.test("expect return 'url' for an URL", async () => {
|
||||
expect(smartpath.get.type('https://push.rocks/some/url')).toEqual('url');
|
||||
expect(smartpath.get.type('https://push.rocks/some/url')).not.toEqual('local');
|
||||
});
|
||||
tap.test("expect return 'path' for a Path", async () => {
|
||||
expect(smartpath.get.type('/some/absolute/path/')).toEqual('local');
|
||||
expect(smartpath.get.type('./some/relative/path/')).not.toEqual('url');
|
||||
});
|
||||
|
||||
tap.test('expect a absolute path for an home relative URL', async () => {
|
||||
console.log(smartpath.get.home('~/test'));
|
||||
});
|
||||
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(){
|
||||
tap.test('expect return the home directory path when no argument is specified', async () => {
|
||||
console.log(smartpath.get.home());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
21
ts/index.ts
21
ts/index.ts
@ -1,19 +1,8 @@
|
||||
import 'typings-global'
|
||||
import plugins = require('./smartpath.plugins')
|
||||
|
||||
// import modules
|
||||
import SmartpathCheck = require('./smartpath.check')
|
||||
import SmartpathGet = require('./smartpath.get')
|
||||
import SmartpathTransform = require('./smartpath.transform')
|
||||
import * as check from './smartpath.check.js';
|
||||
import * as get from './smartpath.get.js';
|
||||
import * as transform from './smartpath.transform.js';
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {{getPath: (function(any): undefined)}}
|
||||
*/
|
||||
let smartpath = {
|
||||
check: SmartpathCheck,
|
||||
get: SmartpathGet,
|
||||
transform: SmartpathTransform
|
||||
}
|
||||
export { check, get, transform };
|
||||
|
||||
export = smartpath
|
||||
export * from './smartpath.classes.smartpath.js';
|
||||
|
@ -1,10 +1,9 @@
|
||||
import 'typings-global'
|
||||
import plugins = require('./smartpath.plugins')
|
||||
import * as plugins from './smartpath.plugins.js';
|
||||
|
||||
export let isDir = function (pathArg: string) {
|
||||
return !isFile(pathArg)
|
||||
}
|
||||
return !isFile(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
|
||||
};
|
||||
|
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.js';
|
||||
import * as getMod from './smartpath.get.js';
|
||||
|
||||
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,48 @@
|
||||
import "typings-global";
|
||||
import plugins = require("./smartpath.plugins");
|
||||
import * as plugins from './smartpath.plugins.js';
|
||||
export type TPathType = 'url' | 'local';
|
||||
|
||||
/**
|
||||
* 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
|
||||
export const type = (pathStringArg: string): TPathType => {
|
||||
const urlRegex = /http[s|\s]:\/\/.*/i;
|
||||
if (urlRegex.exec(pathStringArg)) {
|
||||
return "url";
|
||||
return 'url';
|
||||
} else {
|
||||
return "local";
|
||||
};
|
||||
};
|
||||
|
||||
export let home = function(pathArgument?:string){
|
||||
if(pathArgument){
|
||||
return plugins.home.resolve(pathArgument);
|
||||
} else {
|
||||
return plugins.home();
|
||||
return 'local';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* gets the dirname from import.meta.url
|
||||
*/
|
||||
export const dirnameFromImportMetaUrl = (importMetaUrlArg: string) => {
|
||||
return plugins.path.dirname(plugins.url.fileURLToPath(importMetaUrlArg));
|
||||
};
|
||||
|
||||
/**
|
||||
* returns homedir as absolute path
|
||||
* @param pathArgument if a pathargument is given, ~ is being replaced with the homedir
|
||||
* @returns
|
||||
*/
|
||||
export const home = (pathArgument?: string) => {
|
||||
if (pathArgument) {
|
||||
return pathArgument.replace('~', plugins.os.homedir());
|
||||
} else {
|
||||
return plugins.os.homedir();
|
||||
}
|
||||
};
|
||||
|
||||
export type TSystemArg = 'dynamic' | 'windows' | 'linux' | 'osx';
|
||||
|
||||
export const pathLevels = (pathArg: string, systemArg: TSystemArg = 'dynamic') => {
|
||||
let pathLevelArray: string[];
|
||||
if (systemArg === 'dynamic') {
|
||||
pathLevelArray = pathArg.split(plugins.path.sep);
|
||||
}
|
||||
return pathLevelArray;
|
||||
};
|
||||
|
||||
export const pathLevelsBackwards = (pathArg: string, systemArg?: TSystemArg) => {
|
||||
return pathLevels(pathArg, systemArg).reverse();
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'typings-global'
|
||||
export import beautylog = require ('beautylog')
|
||||
export var home = require('home')
|
||||
export import path = require('path')
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as url from 'url';
|
||||
|
||||
export { os, path, url };
|
||||
|
@ -1,40 +1,41 @@
|
||||
import 'typings-global'
|
||||
import plugins = require('./smartpath.plugins')
|
||||
import * as plugins from './smartpath.plugins.js';
|
||||
|
||||
/* ------------------------------------------ *
|
||||
* ------------ helpers --------------------- *
|
||||
* ------------------------------------------ */
|
||||
|
||||
// checks a file
|
||||
let makeAbsolute = function(localPathArg: string, baseArg?: string): string {
|
||||
let absolutePath: string
|
||||
let alreadyAbsolute = plugins.path.isAbsolute(localPathArg)
|
||||
export const makeAbsolute = (localPathArg: string, baseArg?: string): string => {
|
||||
let absolutePath: string;
|
||||
let alreadyAbsolute = plugins.path.isAbsolute(localPathArg);
|
||||
if (baseArg && !alreadyAbsolute) {
|
||||
absolutePath = plugins.path.join(baseArg,localPathArg)
|
||||
absolutePath = plugins.path.join(baseArg, localPathArg);
|
||||
} else if (!alreadyAbsolute) {
|
||||
absolutePath = plugins.path.resolve(localPathArg)
|
||||
absolutePath = plugins.path.resolve(localPathArg);
|
||||
} else {
|
||||
absolutePath = localPathArg
|
||||
}
|
||||
return absolutePath
|
||||
absolutePath = localPathArg;
|
||||
}
|
||||
return absolutePath;
|
||||
};
|
||||
|
||||
/* ------------------------------------------ *
|
||||
* ------- export functions ----------------- *
|
||||
* ------------------------------------------ */
|
||||
export let toAbsolute = function(relativeArg: string | string[], baseArg?: string): any {
|
||||
export const toAbsolute = (relativeArg: string | string[], baseArg?: string): string | string[] => {
|
||||
if (typeof relativeArg === 'string') {
|
||||
return makeAbsolute(relativeArg,baseArg)
|
||||
return makeAbsolute(relativeArg, baseArg);
|
||||
} else if (Array.isArray(relativeArg)) {
|
||||
let relativeArray = relativeArg
|
||||
let absoluteArray: string[] = []
|
||||
let relativeArray = relativeArg;
|
||||
let absoluteArray: string[] = [];
|
||||
for (let key in relativeArray) {
|
||||
absoluteArray.push(makeAbsolute(relativeArray[key],baseArg))
|
||||
absoluteArray.push(makeAbsolute(relativeArray[key], baseArg));
|
||||
}
|
||||
return absoluteArray
|
||||
return absoluteArray;
|
||||
} else {
|
||||
plugins.beautylog.error('smartpath.absolute() could not make sense of the input. ' +
|
||||
'Input is neither String nor Array')
|
||||
return false
|
||||
}
|
||||
console.error(
|
||||
'smartpath.absolute() could not make sense of the input. ' +
|
||||
'Input is neither String nor Array'
|
||||
);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
"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