Compare commits
71 Commits
Author | SHA1 | Date | |
---|---|---|---|
b02ab97d4f | |||
ecfefc250c | |||
dde9948404 | |||
d041d8de68 | |||
f03b3df55b | |||
ca387124ee | |||
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 | |||
38668239d4 | |||
3d0257768d | |||
e09ce0edc0 | |||
3d4c2e64b4 | |||
139478965b | |||
1e545a2cfb | |||
10b593b480 | |||
839a86ccf1 | |||
06ebd44189 | |||
3d5aa9fda7 | |||
cc5f57da44 | |||
2866a76abc | |||
a8f93682fc | |||
2833666d14 | |||
0ca312bd02 | |||
a8f53ae2ae | |||
5b7f104c88 | |||
f2423f7c61 | |||
57680424c4 | |||
04b942092c | |||
209ff095a4 | |||
fb62b0aac7 | |||
736eefa91e | |||
8fc994737b | |||
32e478ef4e | |||
451e2e241f | |||
202914b19b | |||
373a4eed94 | |||
9a9f28bdff | |||
2bd242ac57 | |||
b113dcfbe0 | |||
dc6636d552 | |||
72c70c481a | |||
8986953592 | |||
8a2afe1a81 | |||
48f44ee937 |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,20 @@
|
|||||||
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
.settings/
|
|
||||||
.idea/
|
# 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
|
19
.travis.yml
19
.travis.yml
@ -1,19 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
before_install:
|
|
||||||
- nvm install stable
|
|
||||||
- node -v
|
|
||||||
- npm -v
|
|
||||||
- npm install -g gulp
|
|
||||||
- npm install gulp
|
|
||||||
- npm install gulp-typescript
|
|
||||||
deploy:
|
|
||||||
provider: npm
|
|
||||||
email: npm@smart-coordination.com
|
|
||||||
api_key:
|
|
||||||
secure: hfuRCg2RSNTvSe49w+rqx/fPt2OILDTjdYkga5BnGr0Rja5yL/2SpVNOP62lYNQBB61TfqfT8F4gQsQyAuygzhNT1ijZ4qCvSdqHqXki/0hzTVZAvfF2aoLxUnuCMAYawUyx5nibJKCmGXvH9MbMrEwV5Gh0uSf0HRmskp/GKuXw5epnMkOT2SEr9Mw7Hpu3VKLEALoKOI2hYBRv555sRFkI3Cd9v1n0384HEjCbQEwXhPwwki2XL2SXzGP8IOccE3xLK9zsQO2RDCqaKpIsK682ZtrvyqxmAJaivtO6VImkpBXcKniYOqJR6sWrsw5345er/iSSr30fgjw4I6LNyUcmF59Uw/dPAElvLN6jU6zxg/+GHM7xqz/J/HV3rlE4d20/9ZJB9IIm2761c3T7DraBMbA7ehj1lolTvCq1vx8oGbNEhkTVBj06V3ltdMPHMiNbeG2Tqs50h/lOgRy5+oqZ8ULWayWX1KXloM3LlddXJnnB31LzHbZUZw7m+q8QnfBlPCWuLd1JfluFrszr1YAR6YPciL9grBNV7beG+8wbh2G0gfMdCHZOzhDmoEHgt/y8liV0QdsFH6QLlEwt8UMPeZ8IO0sNYx5A2ffznZIzy9xEDmMySwl8J3/EdQxhS6FGrm000lu4BH+c2dVlCn/5va9fJLD+m6seSN8Yy40=
|
|
||||||
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
19
index.js
19
index.js
@ -1,19 +0,0 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
|
||||||
var path = require("path");
|
|
||||||
var bl = require("beautylog");
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @type {{getPath: (function(any): undefined)}}
|
|
||||||
*/
|
|
||||||
var smartpath = {
|
|
||||||
getAbsPath: function (varPath, logBool) {
|
|
||||||
if (logBool === void 0) { logBool = false; }
|
|
||||||
var absPath = path.resolve(varPath);
|
|
||||||
if (logBool == true) {
|
|
||||||
bl.log('varPath is' + varPath);
|
|
||||||
bl.log('absPath is' + absPath);
|
|
||||||
}
|
|
||||||
return absPath;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = smartpath;
|
|
@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
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
|
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
|
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": "push.rocks",
|
||||||
|
"gitrepo": "smartpath",
|
||||||
|
"description": "offers smart ways to handle paths",
|
||||||
|
"npmPackagename": "@push.rocks/smartpath",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18757
package-lock.json
generated
Normal file
18757
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
@ -1,10 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "smartpath",
|
"name": "@push.rocks/smartpath",
|
||||||
"version": "1.0.2",
|
"version": "5.0.7",
|
||||||
|
"private": false,
|
||||||
"description": "offers smart ways to handle paths",
|
"description": "offers smart ways to handle paths",
|
||||||
"main": "index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "cd ts/compile && gulp"
|
"test": "(tstest test)",
|
||||||
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -15,11 +19,32 @@
|
|||||||
"jade",
|
"jade",
|
||||||
"template"
|
"template"
|
||||||
],
|
],
|
||||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"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": {}
|
"devDependencies": {
|
||||||
|
"@gitzone/tsbuild": "^2.1.56",
|
||||||
|
"@gitzone/tsrun": "^1.2.31",
|
||||||
|
"@gitzone/tstest": "^1.0.69",
|
||||||
|
"@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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
3429
pnpm-lock.yaml
generated
Normal file
3429
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
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)
|
66
test/test.ts
Normal file
66
test/test.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||||
|
import * as smartpath from '../ts/index.js';
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('expect be true for a directory path', async () => {
|
||||||
|
expect(smartpath.check.isDir(dirPathString)).toBeTrue();
|
||||||
|
|
||||||
|
expect(smartpath.check.isDir(dirPathString2)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('expect be false for a file path', async () => {
|
||||||
|
expect(smartpath.check.isDir(filePathString)).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
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)).toStartWith('/');
|
||||||
|
expect(smartpath.transform.toAbsolute(relativeString)).toEndWith(relativeString);
|
||||||
|
expect(smartpath.transform.toAbsolute(relativeString, baseString)).toEqual(
|
||||||
|
'/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]).toStartWith('/');
|
||||||
|
expect(absoluteArray[2]).toEndWith(relativeString2);
|
||||||
|
});
|
||||||
|
|
||||||
|
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'));
|
||||||
|
});
|
||||||
|
tap.test('expect return the home directory path when no argument is specified', async () => {
|
||||||
|
console.log(smartpath.get.home());
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smartpath',
|
||||||
|
version: '5.0.7',
|
||||||
|
description: 'offers smart ways to handle paths'
|
||||||
|
}
|
@ -1,2 +0,0 @@
|
|||||||
nvm use v0.12.7
|
|
||||||
gulp
|
|
@ -1,16 +0,0 @@
|
|||||||
// import gulp
|
|
||||||
var gulp = require("gulp"),
|
|
||||||
gulpTypescript = require("gulp-typescript");
|
|
||||||
|
|
||||||
gulp.task('compileTS', function() {
|
|
||||||
var stream = gulp.src('../index.ts')
|
|
||||||
.pipe(gulpTypescript({
|
|
||||||
out: "index.js"
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest("../../"));
|
|
||||||
return stream;
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('default',['compileTS'], function() {
|
|
||||||
console.log('Typescript compiled');
|
|
||||||
});
|
|
@ -1,2 +0,0 @@
|
|||||||
# How to compile.
|
|
||||||
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.
|
|
26
ts/index.ts
26
ts/index.ts
@ -1,22 +1,8 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
// import modules
|
||||||
|
import * as check from './smartpath.check.js';
|
||||||
|
import * as get from './smartpath.get.js';
|
||||||
|
import * as transform from './smartpath.transform.js';
|
||||||
|
|
||||||
var path = require("path");
|
export { check, get, transform };
|
||||||
var bl = require("beautylog");
|
|
||||||
|
|
||||||
/**
|
export * from './smartpath.classes.smartpath.js';
|
||||||
*
|
|
||||||
* @type {{getPath: (function(any): undefined)}}
|
|
||||||
*/
|
|
||||||
var smartpath:any = {
|
|
||||||
getAbsPath: function(varPath,logBool = false) {
|
|
||||||
var absPath = path.resolve(varPath);
|
|
||||||
if (logBool == true) {
|
|
||||||
bl.log('varPath is' + varPath);
|
|
||||||
bl.log('absPath is' + absPath);
|
|
||||||
}
|
|
||||||
return absPath;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = smartpath;
|
|
||||||
|
9
ts/smartpath.check.ts
Normal file
9
ts/smartpath.check.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import * as plugins from './smartpath.plugins.js';
|
||||||
|
|
||||||
|
export let isDir = function (pathArg: string) {
|
||||||
|
return !isFile(pathArg);
|
||||||
|
};
|
||||||
|
|
||||||
|
export let isFile = function (pathArg) {
|
||||||
|
return /\.[a-zA-Z]*$/.test(pathArg); // checks if there is a .anything at the end
|
||||||
|
};
|
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);
|
||||||
|
}
|
||||||
|
}
|
48
ts/smartpath.get.ts
Normal file
48
ts/smartpath.get.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
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 const type = (pathStringArg: string): TPathType => {
|
||||||
|
const urlRegex = /http[s|\s]:\/\/.*/i;
|
||||||
|
if (urlRegex.exec(pathStringArg)) {
|
||||||
|
return 'url';
|
||||||
|
} else {
|
||||||
|
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();
|
||||||
|
};
|
5
ts/smartpath.plugins.ts
Normal file
5
ts/smartpath.plugins.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import * as os from 'os';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as url from 'url';
|
||||||
|
|
||||||
|
export { os, path, url };
|
41
ts/smartpath.transform.ts
Normal file
41
ts/smartpath.transform.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import * as plugins from './smartpath.plugins.js';
|
||||||
|
|
||||||
|
/* ------------------------------------------ *
|
||||||
|
* ------------ helpers --------------------- *
|
||||||
|
* ------------------------------------------ */
|
||||||
|
|
||||||
|
// checks a file
|
||||||
|
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);
|
||||||
|
} else if (!alreadyAbsolute) {
|
||||||
|
absolutePath = plugins.path.resolve(localPathArg);
|
||||||
|
} else {
|
||||||
|
absolutePath = localPathArg;
|
||||||
|
}
|
||||||
|
return absolutePath;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------ *
|
||||||
|
* ------- export functions ----------------- *
|
||||||
|
* ------------------------------------------ */
|
||||||
|
export const toAbsolute = (relativeArg: string | string[], baseArg?: string): string | string[] => {
|
||||||
|
if (typeof relativeArg === 'string') {
|
||||||
|
return makeAbsolute(relativeArg, baseArg);
|
||||||
|
} else if (Array.isArray(relativeArg)) {
|
||||||
|
let relativeArray = relativeArg;
|
||||||
|
let absoluteArray: string[] = [];
|
||||||
|
for (let key in relativeArray) {
|
||||||
|
absoluteArray.push(makeAbsolute(relativeArray[key], baseArg));
|
||||||
|
}
|
||||||
|
return absoluteArray;
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
'smartpath.absolute() could not make sense of the input. ' +
|
||||||
|
'Input is neither String nor Array'
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
12
ts/tsd.json
12
ts/tsd.json
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "v4",
|
|
||||||
"repo": "borisyankov/DefinitelyTyped",
|
|
||||||
"ref": "master",
|
|
||||||
"path": "typings",
|
|
||||||
"bundle": "typings/tsd.d.ts",
|
|
||||||
"installed": {
|
|
||||||
"node/node.d.ts": {
|
|
||||||
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
2079
ts/typings/node/node.d.ts
vendored
2079
ts/typings/node/node.d.ts
vendored
File diff suppressed because it is too large
Load Diff
1
ts/typings/tsd.d.ts
vendored
1
ts/typings/tsd.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
/// <reference path="node/node.d.ts" />
|
|
Reference in New Issue
Block a user