Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
13c001c48a | |||
7916929550 | |||
c52c1902ee | |||
06c60d42c1 | |||
38668239d4 | |||
3d0257768d |
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,8 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.settings/
|
coverage/
|
||||||
.idea/
|
pages/
|
||||||
docs/
|
public/
|
||||||
ts/typings/
|
|
||||||
ts/**/*.js
|
|
||||||
ts/**/*.js.map
|
|
||||||
coverage/
|
|
||||||
|
33
.gitlab-ci.yml
Normal file
33
.gitlab-ci.yml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
image: hosttoday/ht-docker-node:npmts
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
- release
|
||||||
|
testLEGACY:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test legacy
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
testLTS:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test lts
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testSTABLE:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test stable
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
environment: npm_registry
|
||||||
|
script:
|
||||||
|
- npmci publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
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=
|
|
19
dist/index.d.ts
vendored
19
dist/index.d.ts
vendored
@ -1,14 +1,5 @@
|
|||||||
import "typings-global";
|
import check = require('./smartpath.check');
|
||||||
import SmartpathCheck = require("./smartpath.check");
|
import get = require('./smartpath.get');
|
||||||
import SmartpathGet = require("./smartpath.get");
|
import transform = require('./smartpath.transform');
|
||||||
import SmartpathTransform = require("./smartpath.transform");
|
export { check, get, transform };
|
||||||
/**
|
export * from './smartpath.classes.smartpath';
|
||||||
*
|
|
||||||
* @type {{getPath: (function(any): undefined)}}
|
|
||||||
*/
|
|
||||||
declare let smartpath: {
|
|
||||||
check: typeof SmartpathCheck;
|
|
||||||
get: typeof SmartpathGet;
|
|
||||||
transform: typeof SmartpathTransform;
|
|
||||||
};
|
|
||||||
export = smartpath;
|
|
||||||
|
28
dist/index.js
vendored
28
dist/index.js
vendored
@ -1,17 +1,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
function __export(m) {
|
||||||
var SmartpathCheck = require("./smartpath.check");
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||||
var SmartpathGet = require("./smartpath.get");
|
}
|
||||||
var SmartpathTransform = require("./smartpath.transform");
|
// import modules
|
||||||
/**
|
const check = require("./smartpath.check");
|
||||||
*
|
exports.check = check;
|
||||||
* @type {{getPath: (function(any): undefined)}}
|
const get = require("./smartpath.get");
|
||||||
*/
|
exports.get = get;
|
||||||
var smartpath = {
|
const transform = require("./smartpath.transform");
|
||||||
check: SmartpathCheck,
|
exports.transform = transform;
|
||||||
get: SmartpathGet,
|
__export(require("./smartpath.classes.smartpath"));
|
||||||
transform: SmartpathTransform
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsaUJBQWlCO0FBQ2pCLDJDQUEyQztBQU12QyxzQkFBSztBQUxULHVDQUF1QztBQU1uQyxrQkFBRztBQUxQLG1EQUFtRDtBQU0vQyw4QkFBUztBQUdiLG1EQUE2QyJ9
|
||||||
};
|
|
||||||
module.exports = smartpath;
|
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFFeEIsSUFBTyxjQUFjLFdBQVcsbUJBQW1CLENBQUMsQ0FBQztBQUNyRCxJQUFPLFlBQVksV0FBVyxpQkFBaUIsQ0FBQyxDQUFDO0FBQ2pELElBQU8sa0JBQWtCLFdBQVcsdUJBQXVCLENBQUMsQ0FBQztBQUU3RDs7O0dBR0c7QUFDSCxJQUFJLFNBQVMsR0FBRztJQUNaLEtBQUssRUFBRSxjQUFjO0lBQ3JCLEdBQUcsRUFBRSxZQUFZO0lBQ2pCLFNBQVMsRUFBRSxrQkFBa0I7Q0FDaEMsQ0FBQztBQUdGLGlCQUFTLFNBQVMsQ0FBQyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0cGF0aC5wbHVnaW5zXCIpO1xuaW1wb3J0IFNtYXJ0cGF0aENoZWNrID0gcmVxdWlyZShcIi4vc21hcnRwYXRoLmNoZWNrXCIpO1xuaW1wb3J0IFNtYXJ0cGF0aEdldCA9IHJlcXVpcmUoXCIuL3NtYXJ0cGF0aC5nZXRcIik7XG5pbXBvcnQgU21hcnRwYXRoVHJhbnNmb3JtID0gcmVxdWlyZShcIi4vc21hcnRwYXRoLnRyYW5zZm9ybVwiKTtcblxuLyoqXG4gKlxuICogQHR5cGUge3tnZXRQYXRoOiAoZnVuY3Rpb24oYW55KTogdW5kZWZpbmVkKX19XG4gKi9cbmxldCBzbWFydHBhdGggPSB7XG4gICAgY2hlY2s6IFNtYXJ0cGF0aENoZWNrLFxuICAgIGdldDogU21hcnRwYXRoR2V0LFxuICAgIHRyYW5zZm9ybTogU21hcnRwYXRoVHJhbnNmb3JtXG59O1xuXG5cbmV4cG9ydCA9IHNtYXJ0cGF0aDtcbiJdfQ==
|
|
2
dist/smartpath.check.d.ts
vendored
2
dist/smartpath.check.d.ts
vendored
@ -1,3 +1,3 @@
|
|||||||
import "typings-global";
|
import 'typings-global';
|
||||||
export declare let isDir: (pathArg: string) => boolean;
|
export declare let isDir: (pathArg: string) => boolean;
|
||||||
export declare let isFile: (pathArg: any) => boolean;
|
export declare let isFile: (pathArg: any) => boolean;
|
||||||
|
3
dist/smartpath.check.js
vendored
3
dist/smartpath.check.js
vendored
@ -6,5 +6,4 @@ exports.isDir = function (pathArg) {
|
|||||||
exports.isFile = function (pathArg) {
|
exports.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
|
||||||
};
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLmNoZWNrLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRwYXRoLmNoZWNrL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Rpb24ocGF0aEFyZyl7XG4gICAgcmV0dXJuIC9cXC5bYS16QS1aXSokLy50ZXN0KHBhdGhBcmcpOyAvLyBjaGVja3MgaWYgdGhlcmUgaXMgYSAuYW55dGhpbmcgYXQgdGhlIGVuZFxufSJdfQ==
|
|
8
dist/smartpath.classes.smartpath.d.ts
vendored
Normal file
8
dist/smartpath.classes.smartpath.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import * as getMod from './smartpath.get';
|
||||||
|
export declare class Smartpath {
|
||||||
|
originalPath: string;
|
||||||
|
type: getMod.TPathType;
|
||||||
|
pathLevels: string[];
|
||||||
|
pathLevelsBackwards: string[];
|
||||||
|
constructor(pathArg: string);
|
||||||
|
}
|
12
dist/smartpath.classes.smartpath.js
vendored
Normal file
12
dist/smartpath.classes.smartpath.js
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
"use strict";
|
||||||
|
const getMod = require("./smartpath.get");
|
||||||
|
class Smartpath {
|
||||||
|
constructor(pathArg) {
|
||||||
|
this.originalPath = pathArg;
|
||||||
|
this.type = getMod.type(this.originalPath);
|
||||||
|
this.pathLevels = getMod.pathLevels(this.originalPath);
|
||||||
|
this.pathLevelsBackwards = getMod.pathLevelsBackwards(this.originalPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.Smartpath = Smartpath;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLmNsYXNzZXMuc21hcnRwYXRoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRwYXRoLmNsYXNzZXMuc21hcnRwYXRoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFDQSwwQ0FBeUM7QUFFekM7SUFLSSxZQUFZLE9BQWU7UUFDdkIsSUFBSSxDQUFDLFlBQVksR0FBRyxPQUFPLENBQUE7UUFDM0IsSUFBSSxDQUFDLElBQUksR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUMxQyxJQUFJLENBQUMsVUFBVSxHQUFHLE1BQU0sQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFBO1FBQ3RELElBQUksQ0FBQyxtQkFBbUIsR0FBRyxNQUFNLENBQUMsbUJBQW1CLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFBO0lBQzVFLENBQUM7Q0FDSjtBQVhELDhCQVdDIn0=
|
7
dist/smartpath.get.d.ts
vendored
7
dist/smartpath.get.d.ts
vendored
@ -1,6 +1,9 @@
|
|||||||
import "typings-global";
|
export declare type TPathType = 'url' | 'local';
|
||||||
/**
|
/**
|
||||||
* returns the type of the given path. Can be "url" or "local"
|
* returns the type of the given path. Can be "url" or "local"
|
||||||
*/
|
*/
|
||||||
export declare let type: (pathStringArg: string) => string;
|
export declare let type: (pathStringArg: string) => TPathType;
|
||||||
export declare let home: (pathArgument?: string) => any;
|
export declare let home: (pathArgument?: string) => any;
|
||||||
|
export declare type TSystemArg = 'dynamic' | 'windows' | 'linux' | 'osx';
|
||||||
|
export declare let pathLevels: (pathArg: string, systemArg?: TSystemArg) => string[];
|
||||||
|
export declare let pathLevelsBackwards: (pathArg: string, systemArg?: TSystemArg) => string[];
|
||||||
|
22
dist/smartpath.get.js
vendored
22
dist/smartpath.get.js
vendored
@ -1,16 +1,15 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
const plugins = require("./smartpath.plugins");
|
||||||
var plugins = require("./smartpath.plugins");
|
|
||||||
/**
|
/**
|
||||||
* returns the type of the given path. Can be "url" or "local"
|
* returns the type of the given path. Can be "url" or "local"
|
||||||
*/
|
*/
|
||||||
exports.type = function (pathStringArg) {
|
exports.type = function (pathStringArg) {
|
||||||
var urlRegex = /http[s|\s]:\/\/.*/i;
|
let urlRegex = /http[s|\s]:\/\/.*/i;
|
||||||
if (urlRegex.exec(pathStringArg)) {
|
if (urlRegex.exec(pathStringArg)) {
|
||||||
return "url";
|
return 'url';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "local";
|
return 'local';
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
@ -22,5 +21,14 @@ exports.home = function (pathArgument) {
|
|||||||
return plugins.home();
|
return plugins.home();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
exports.pathLevels = (pathArg, systemArg = 'dynamic') => {
|
||||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRWhEOztHQUVHO0FBQ1EsWUFBSSxHQUFHLFVBQVMsYUFBb0I7SUFDM0MsSUFBSSxRQUFRLEdBQUcsb0JBQW9CLENBQUE7SUFDbkMsRUFBRSxDQUFBLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFBLENBQUM7UUFDN0IsTUFBTSxDQUFDLEtBQUssQ0FBQztJQUNqQixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsT0FBTyxDQUFDO0lBQ25CLENBQUM7SUFBQSxDQUFDO0FBQ04sQ0FBQyxDQUFDO0FBRVMsWUFBSSxHQUFHLFVBQVMsWUFBb0I7SUFDM0MsRUFBRSxDQUFBLENBQUMsWUFBWSxDQUFDLENBQUEsQ0FBQztRQUNiLE1BQU0sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUM5QyxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsT0FBTyxDQUFDLElBQUksRUFBRSxDQUFDO0lBQzFCLENBQUM7QUFDTCxDQUFDLENBQUMiLCJmaWxlIjoic21hcnRwYXRoLmdldC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0cGF0aC5wbHVnaW5zXCIpO1xuXG4vKipcbiAqIHJldHVybnMgdGhlIHR5cGUgb2YgdGhlIGdpdmVuIHBhdGguIENhbiBiZSBcInVybFwiIG9yIFwibG9jYWxcIlxuICovXG5leHBvcnQgbGV0IHR5cGUgPSBmdW5jdGlvbihwYXRoU3RyaW5nQXJnOnN0cmluZyk6c3RyaW5nIHtcbiAgICBsZXQgdXJsUmVnZXggPSAvaHR0cFtzfFxcc106XFwvXFwvLiovaVxuICAgIGlmKHVybFJlZ2V4LmV4ZWMocGF0aFN0cmluZ0FyZykpe1xuICAgICAgICByZXR1cm4gXCJ1cmxcIjtcbiAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gXCJsb2NhbFwiO1xuICAgIH07XG59O1xuXG5leHBvcnQgbGV0IGhvbWUgPSBmdW5jdGlvbihwYXRoQXJndW1lbnQ/OnN0cmluZyl7XG4gICAgaWYocGF0aEFyZ3VtZW50KXtcbiAgICAgICAgcmV0dXJuIHBsdWdpbnMuaG9tZS5yZXNvbHZlKHBhdGhBcmd1bWVudCk7XG4gICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIHBsdWdpbnMuaG9tZSgpO1xuICAgIH1cbn07Il19
|
let pathLevelArray;
|
||||||
|
if (systemArg === 'dynamic') {
|
||||||
|
pathLevelArray = pathArg.split(plugins.path.sep);
|
||||||
|
}
|
||||||
|
return pathLevelArray;
|
||||||
|
};
|
||||||
|
exports.pathLevelsBackwards = (pathArg, systemArg) => {
|
||||||
|
return exports.pathLevels(pathArg, systemArg).reverse();
|
||||||
|
};
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S0FBSyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUE7SUFDcEQsQ0FBQztJQUNELE1BQU0sQ0FBQyxjQUFjLENBQUE7QUFDekIsQ0FBQyxDQUFBO0FBRVUsUUFBQSxtQkFBbUIsR0FBRyxDQUFDLE9BQWUsRUFBRSxTQUFzQjtJQUNyRSxNQUFNLENBQUMsa0JBQVUsQ0FBQyxPQUFPLEVBQUUsU0FBUyxDQUFDLENBQUMsT0FBTyxFQUFFLENBQUE7QUFDbkQsQ0FBQyxDQUFBIn0=
|
5
dist/smartpath.plugins.d.ts
vendored
5
dist/smartpath.plugins.d.ts
vendored
@ -1,4 +1,3 @@
|
|||||||
import "typings-global";
|
import 'typings-global';
|
||||||
export import beautylog = require("beautylog");
|
|
||||||
export declare var home: any;
|
export declare var home: any;
|
||||||
export import path = require("path");
|
export import path = require('path');
|
||||||
|
6
dist/smartpath.plugins.js
vendored
6
dist/smartpath.plugins.js
vendored
@ -1,7 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
exports.beautylog = require("beautylog");
|
exports.home = require('home');
|
||||||
exports.home = require("home");
|
|
||||||
exports.path = require("path");
|
exports.path = require("path");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwYXRoLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHBhdGgucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ1osUUFBQSxJQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO0FBQ2pDLCtCQUFvQyJ9
|
||||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFZLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLFlBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7QUFDcEIsWUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0cGF0aC5wbHVnaW5zLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcbmV4cG9ydCBpbXBvcnQgYmVhdXR5bG9nID0gcmVxdWlyZSAoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgdmFyIGhvbWUgPSByZXF1aXJlKFwiaG9tZVwiKTtcbmV4cG9ydCBpbXBvcnQgcGF0aCA9IHJlcXVpcmUoXCJwYXRoXCIpO1xuXG4iXX0=
|
|
4
dist/smartpath.transform.d.ts
vendored
4
dist/smartpath.transform.d.ts
vendored
@ -1,2 +1,2 @@
|
|||||||
import "typings-global";
|
import 'typings-global';
|
||||||
export declare let toAbsolute: (relativeArg: any, baseArg?: string) => any;
|
export declare let toAbsolute: (relativeArg: string | string[], baseArg?: string) => any;
|
||||||
|
31
dist/smartpath.transform.js
vendored
31
dist/smartpath.transform.js
vendored
@ -1,40 +1,43 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
var plugins = require("./smartpath.plugins");
|
const plugins = require("./smartpath.plugins");
|
||||||
/* ------------------------------------------ *
|
/* ------------------------------------------ *
|
||||||
* ------------ helpers --------------------- *
|
* ------------ helpers --------------------- *
|
||||||
* ------------------------------------------ */
|
* ------------------------------------------ */
|
||||||
var makeAbsolute = function (localPathArg, baseArg) {
|
// checks a file
|
||||||
var absolutePath;
|
let makeAbsolute = function (localPathArg, baseArg) {
|
||||||
if (baseArg) {
|
let absolutePath;
|
||||||
|
let alreadyAbsolute = plugins.path.isAbsolute(localPathArg);
|
||||||
|
if (baseArg && !alreadyAbsolute) {
|
||||||
absolutePath = plugins.path.join(baseArg, localPathArg);
|
absolutePath = plugins.path.join(baseArg, localPathArg);
|
||||||
}
|
}
|
||||||
else {
|
else if (!alreadyAbsolute) {
|
||||||
absolutePath = plugins.path.resolve(localPathArg);
|
absolutePath = plugins.path.resolve(localPathArg);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
absolutePath = localPathArg;
|
||||||
|
}
|
||||||
return absolutePath;
|
return absolutePath;
|
||||||
};
|
};
|
||||||
/* ------------------------------------------ *
|
/* ------------------------------------------ *
|
||||||
* ------- export functions ----------------- *
|
* ------- export functions ----------------- *
|
||||||
* ------------------------------------------ */
|
* ------------------------------------------ */
|
||||||
exports.toAbsolute = function (relativeArg, baseArg) {
|
exports.toAbsolute = function (relativeArg, baseArg) {
|
||||||
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)) {
|
||||||
var relativeArray = relativeArg;
|
let relativeArray = relativeArg;
|
||||||
var absoluteArray = [];
|
let absoluteArray = [];
|
||||||
for (var 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 {
|
||||||
plugins.beautylog.error("smartpath.absolute() could not make sense of the input. " +
|
console.error('smartpath.absolute() could not make sense of the input. ' +
|
||||||
"Input is neither String nor Array");
|
'Input is neither String nor Array');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJza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0tLS0tLS0tLS0tLS0tLS0tLS0gKi9cbmV4cG9ydCBsZXQgdG9BYnNvbHV0ZSA9IGZ1bmN0aW9uKHJlbGF0aXZlQXJnOmFueSwgYmFzZUFyZz86c3RyaW5nKTphbnkge1xuICAgIGlmKHR5cGVvZiByZWxhdGl2ZUFyZyA9PT0gXCJzdHJpbmdcIil7XG4gICAgICAgIHJldHVybiBtYWtlQWJzb2x1dGUocmVsYXRpdmVBcmcsYmFzZUFyZyk7XG4gICAgfSBlbHNlIGlmKEFycmF5LmlzQXJyYXkocmVsYXRpdmVBcmcpKXtcbiAgICAgICAgbGV0IHJlbGF0aXZlQXJyYXkgPSByZWxhdGl2ZUFyZ1xuICAgICAgICBsZXQgYWJzb2x1dGVBcnJheTpzdHJpbmdbXSA9IFtdO1xuICAgICAgICBmb3IgKGxldCBrZXkgaW4gcmVsYXRpdmVBcnJheSl7XG4gICAgICAgICAgICBhYnNvbHV0ZUFycmF5LnB1c2gobWFrZUFic29sdXRlKHJlbGF0aXZlQXJyYXlba2V5XSxiYXNlQXJnKSk7XG4gICAgICAgIH07XG4gICAgICAgIHJldHVybiBhYnNvbHV0ZUFycmF5O1xuICAgIH0gZWxzZSB7XG4gICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLmVycm9yKFwic21hcnRwYXRoLmFic29sdXRlKCkgY291bGQgbm90IG1ha2Ugc2Vuc2Ugb2YgdGhlIGlucHV0LiBcIiArXG4gICAgICAgICAgICBcIklucHV0IGlzIG5laXRoZXIgU3RyaW5nIG5vciBBcnJheVwiKTtcbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cbn07Il19
|
|
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smartpath",
|
"name": "smartpath",
|
||||||
"version": "3.2.3",
|
"version": "3.2.6",
|
||||||
"description": "offers smart ways to handle paths",
|
"description": "offers smart ways to handle paths",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@ -23,13 +23,13 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/smartpath",
|
"homepage": "https://github.com/pushrocks/smartpath",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^5.0.10",
|
|
||||||
"home": "^1.0.1",
|
"home": "^1.0.1",
|
||||||
"typings-global": "^1.0.3"
|
"typings-global": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.6",
|
"@types/should": "^8.1.30",
|
||||||
"should": "^9.0.2",
|
"npmts-g": "^5.2.10",
|
||||||
"typings-test": "^1.0.1"
|
"should": "^11.1.1",
|
||||||
|
"typings-test": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
test/test.d.ts
vendored
3
test/test.d.ts
vendored
@ -1,2 +1 @@
|
|||||||
import "typings-test";
|
import 'typings-test';
|
||||||
import "should";
|
|
||||||
|
107
test/test.js
107
test/test.js
File diff suppressed because one or more lines are too long
160
test/test.ts
160
test/test.ts
@ -1,77 +1,89 @@
|
|||||||
import "typings-test";
|
import 'typings-test'
|
||||||
import "should";
|
import * as should from 'should'
|
||||||
let smartpath = require("../dist/index.js");
|
import * as smartpath from '../dist/index.js'
|
||||||
|
|
||||||
describe("smartpath",function(){
|
describe('smartpath', function () {
|
||||||
describe(".check",function(){
|
describe('class Smartpath', function() {
|
||||||
let filePathString = "./somedir/somefile.json"
|
let mySmartpath: smartpath.Smartpath
|
||||||
let dirPathString = "./somedir/anotherdir"
|
it('should create a valid instance', function() {
|
||||||
let dirPathString2 = "./somedir/another.dir/"
|
mySmartpath = new smartpath.Smartpath('/some/path/to/some.file')
|
||||||
describe(".isFile",function(){
|
should(mySmartpath).be.instanceof(smartpath.Smartpath)
|
||||||
it("should be true for a file path",function(){
|
should(mySmartpath.pathLevelsBackwards).be.of.length(5)
|
||||||
smartpath.check.isFile(filePathString)
|
})
|
||||||
.should.be.true();
|
})
|
||||||
});
|
describe('.check', function () {
|
||||||
it("should be false for a directory path",function(){
|
let filePathString = './somedir/somefile.json'
|
||||||
smartpath.check.isFile(dirPathString)
|
let dirPathString = './somedir/anotherdir'
|
||||||
.should.be.false();
|
let dirPathString2 = './somedir/another.dir/'
|
||||||
smartpath.check.isFile(dirPathString2)
|
describe('.isFile', function () {
|
||||||
.should.be.false();
|
it('should be true for a file path', function () {
|
||||||
});
|
should(
|
||||||
});
|
smartpath.check.isFile(filePathString)
|
||||||
describe(".isDir",function(){
|
).be.true()
|
||||||
it("should be true for a directory path",function(){
|
})
|
||||||
smartpath.check.isDir(dirPathString)
|
it('should be false for a directory path', function () {
|
||||||
.should.be.true();
|
should(
|
||||||
smartpath.check.isDir(dirPathString2)
|
smartpath.check.isFile(dirPathString)
|
||||||
.should.be.true();
|
).be.false()
|
||||||
});
|
should(
|
||||||
it("should be false for a file path",function(){
|
smartpath.check.isFile(dirPathString2)
|
||||||
smartpath.check.isDir(filePathString)
|
).be.false()
|
||||||
.should.be.false();
|
})
|
||||||
});
|
})
|
||||||
});
|
describe('.isDir', function () {
|
||||||
});
|
it('should be true for a directory path', function () {
|
||||||
describe(".transform",function(){
|
should(smartpath.check.isDir(dirPathString)
|
||||||
describe("toAbsolute()",function(){
|
).be.true()
|
||||||
let baseString = "/basedir";
|
should(smartpath.check.isDir(dirPathString2)
|
||||||
let relativeString = "somedir/somefile.txt";
|
).be.true()
|
||||||
let relativeString2 = "anotherdir/anotherfile.txt";
|
})
|
||||||
let relativeArray = [relativeString,relativeString,relativeString2];
|
it('should be false for a file path', function () {
|
||||||
it("should make a string absolute",function(){
|
should(
|
||||||
smartpath.transform.toAbsolute(relativeString).should.startWith("/");
|
smartpath.check.isDir(filePathString)
|
||||||
smartpath.transform.toAbsolute(relativeString).should.endWith(relativeString);
|
).be.false()
|
||||||
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);
|
describe('.transform', function () {
|
||||||
absoluteArray[2].should.startWith("/");
|
describe('toAbsolute()', function () {
|
||||||
absoluteArray[2].should.endWith(relativeString2);
|
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 () {
|
||||||
|
should(smartpath.transform.toAbsolute(relativeString)).startWith('/')
|
||||||
|
should(smartpath.transform.toAbsolute(relativeString)).endWith(relativeString)
|
||||||
|
should(smartpath.transform.toAbsolute(relativeString, baseString)).equal('/basedir/somedir/somefile.txt')
|
||||||
|
})
|
||||||
|
it('should make an array of relative Strings an Array of absolute Strings', function () {
|
||||||
|
let absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString)
|
||||||
|
should(absoluteArray[2]).startWith('/')
|
||||||
|
should(absoluteArray[2]).endWith(relativeString2)
|
||||||
|
|
||||||
})
|
})
|
||||||
it("should return false if neither String nor Array",function(){
|
it('should return false if neither String nor Array', function () {
|
||||||
smartpath.transform.toAbsolute(3).should.be.false();
|
should(smartpath.transform.toAbsolute(3)).be.false()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
describe(".get",function(){
|
describe('.get', function () {
|
||||||
describe(".type()",function(){
|
describe('.type()', function () {
|
||||||
it("should return 'url' for an URL",function(){
|
it("should return 'url' for an URL", function () {
|
||||||
smartpath.get.type("https://push.rocks/some/url").should.equal("url");
|
should(smartpath.get.type('https://push.rocks/some/url')).equal('url')
|
||||||
smartpath.get.type("https://push.rocks/some/url").should.not.equal("local");
|
should(smartpath.get.type('https://push.rocks/some/url')).not.equal('local')
|
||||||
});
|
})
|
||||||
it("should return 'path' for a Path",function(){
|
it("should return 'path' for a Path", function () {
|
||||||
smartpath.get.type("/some/absolute/path/").should.equal("local");
|
should(smartpath.get.type('/some/absolute/path/')).equal('local')
|
||||||
smartpath.get.type("./some/relative/path/").should.not.equal("url");
|
should(smartpath.get.type('./some/relative/path/')).not.equal('url')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
describe(".get()",function(){
|
describe('.get()', function () {
|
||||||
it("should a absolute path for an home relative URL",function(){
|
it('should a absolute path for an home relative URL', function () {
|
||||||
console.log(smartpath.get.home("~/test"));
|
console.log(smartpath.get.home('~/test'))
|
||||||
});
|
})
|
||||||
it("should return the home directory path when no argument is specified",function(){
|
it('should return the home directory path when no argument is specified', function () {
|
||||||
console.log(smartpath.get.home());
|
console.log(smartpath.get.home())
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
27
ts/index.ts
27
ts/index.ts
@ -1,18 +1,13 @@
|
|||||||
import "typings-global";
|
// import modules
|
||||||
import plugins = require("./smartpath.plugins");
|
import check = require('./smartpath.check')
|
||||||
import SmartpathCheck = require("./smartpath.check");
|
import get = require('./smartpath.get')
|
||||||
import SmartpathGet = require("./smartpath.get");
|
import transform = require('./smartpath.transform')
|
||||||
import SmartpathTransform = require("./smartpath.transform");
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @type {{getPath: (function(any): undefined)}}
|
|
||||||
*/
|
|
||||||
let smartpath = {
|
|
||||||
check: SmartpathCheck,
|
|
||||||
get: SmartpathGet,
|
|
||||||
transform: SmartpathTransform
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
export = smartpath;
|
export {
|
||||||
|
check,
|
||||||
|
get,
|
||||||
|
transform
|
||||||
|
}
|
||||||
|
|
||||||
|
export * from './smartpath.classes.smartpath'
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import "typings-global";
|
import 'typings-global'
|
||||||
import plugins = require("./smartpath.plugins");
|
import plugins = require('./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
|
||||||
}
|
}
|
||||||
|
15
ts/smartpath.classes.smartpath.ts
Normal file
15
ts/smartpath.classes.smartpath.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import * as plugins from './smartpath.plugins'
|
||||||
|
import * as getMod from './smartpath.get'
|
||||||
|
|
||||||
|
export class Smartpath {
|
||||||
|
originalPath: string
|
||||||
|
type: getMod.TPathType
|
||||||
|
pathLevels: string[]
|
||||||
|
pathLevelsBackwards: string[]
|
||||||
|
constructor(pathArg: string) {
|
||||||
|
this.originalPath = pathArg
|
||||||
|
this.type = getMod.type(this.originalPath)
|
||||||
|
this.pathLevels = getMod.pathLevels(this.originalPath)
|
||||||
|
this.pathLevelsBackwards = getMod.pathLevelsBackwards(this.originalPath)
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,36 @@
|
|||||||
import "typings-global";
|
import plugins = require('./smartpath.plugins')
|
||||||
import plugins = require("./smartpath.plugins");
|
export type TPathType = 'url' | 'local'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the type of the given path. Can be "url" or "local"
|
* returns the type of the given path. Can be "url" or "local"
|
||||||
*/
|
*/
|
||||||
export let type = function(pathStringArg:string):string {
|
export let type = function (pathStringArg: string): TPathType {
|
||||||
let urlRegex = /http[s|\s]:\/\/.*/i
|
let urlRegex = /http[s|\s]:\/\/.*/i
|
||||||
if(urlRegex.exec(pathStringArg)){
|
if (urlRegex.exec(pathStringArg)) {
|
||||||
return "url";
|
return 'url'
|
||||||
} else {
|
} else {
|
||||||
return "local";
|
return 'local'
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export let home = function(pathArgument?:string){
|
export let home = function (pathArgument?: string) {
|
||||||
if(pathArgument){
|
if (pathArgument) {
|
||||||
return plugins.home.resolve(pathArgument);
|
return plugins.home.resolve(pathArgument)
|
||||||
} else {
|
} else {
|
||||||
return plugins.home();
|
return plugins.home()
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export type TSystemArg = 'dynamic' | 'windows' | 'linux' | 'osx'
|
||||||
|
|
||||||
|
export let pathLevels = (pathArg: string, systemArg: TSystemArg = 'dynamic') => {
|
||||||
|
let pathLevelArray: string[]
|
||||||
|
if (systemArg === 'dynamic') {
|
||||||
|
pathLevelArray = pathArg.split(plugins.path.sep)
|
||||||
|
}
|
||||||
|
return pathLevelArray
|
||||||
|
}
|
||||||
|
|
||||||
|
export let pathLevelsBackwards = (pathArg: string, systemArg?: TSystemArg) => {
|
||||||
|
return pathLevels(pathArg, systemArg).reverse()
|
||||||
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import "typings-global";
|
import 'typings-global'
|
||||||
export import beautylog = require ("beautylog");
|
export var home = require('home')
|
||||||
export var home = require("home");
|
export import path = require('path')
|
||||||
export import path = require("path");
|
|
||||||
|
|
||||||
|
@ -1,35 +1,40 @@
|
|||||||
import "typings-global";
|
import 'typings-global'
|
||||||
import plugins = require("./smartpath.plugins");
|
import plugins = require('./smartpath.plugins')
|
||||||
|
|
||||||
/* ------------------------------------------ *
|
/* ------------------------------------------ *
|
||||||
* ------------ helpers --------------------- *
|
* ------------ helpers --------------------- *
|
||||||
* ------------------------------------------ */
|
* ------------------------------------------ */
|
||||||
let makeAbsolute = function(localPathArg:string, baseArg?:string):string {
|
|
||||||
let absolutePath:string;
|
// checks a file
|
||||||
if(baseArg){
|
let makeAbsolute = function(localPathArg: string, baseArg?: string): string {
|
||||||
absolutePath = plugins.path.join(baseArg,localPathArg);
|
let absolutePath: string
|
||||||
|
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 = plugins.path.resolve(localPathArg);
|
absolutePath = localPathArg
|
||||||
}
|
}
|
||||||
return absolutePath;
|
return absolutePath
|
||||||
};
|
}
|
||||||
|
|
||||||
/* ------------------------------------------ *
|
/* ------------------------------------------ *
|
||||||
* ------- export functions ----------------- *
|
* ------- export functions ----------------- *
|
||||||
* ------------------------------------------ */
|
* ------------------------------------------ */
|
||||||
export let toAbsolute = function(relativeArg:any, baseArg?:string):any {
|
export let toAbsolute = function(relativeArg: string | string[], 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 {
|
||||||
plugins.beautylog.error("smartpath.absolute() could not make sense of the input. " +
|
console.error('smartpath.absolute() could not make sense of the input. ' +
|
||||||
"Input is neither String nor Array");
|
'Input is neither String nor Array')
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "tslint-config-standard"
|
||||||
|
}
|
Reference in New Issue
Block a user