Compare commits
81 Commits
Author | SHA1 | Date | |
---|---|---|---|
ff1e6242a3 | |||
ae736d5dbb | |||
7686c417b1 | |||
65cb98d031 | |||
55fc30139f | |||
be85880e54 | |||
ebc523cb9f | |||
6fae04e92a | |||
de54eb828f | |||
bf6ed38083 | |||
b53d74cd55 | |||
7cc6127680 | |||
10bda971fb | |||
e578601b49 | |||
1558a9148b | |||
fad06e3c33 | |||
b51ccda39e | |||
071e17d8bf | |||
07e13ed9be | |||
e3f6c0a8a1 | |||
db7dc635f1 | |||
8bb10f45b3 | |||
68ccb0e708 | |||
fc51d498c7 | |||
6474016fc1 | |||
ea42dbd1c3 | |||
9e8ce8215c | |||
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 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
26
.gitignore
vendored
26
.gitignore
vendored
@@ -1,8 +1,20 @@
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
docs/
|
||||
ts/typings/
|
||||
ts/**/*.js
|
||||
ts/**/*.js.map
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
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
|
18
changelog.md
Normal file
18
changelog.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## [5.1.0] - 2025-01-28
|
||||
|
||||
### Added
|
||||
- New isomorphic path module at `/iso` export path for cross-platform path operations
|
||||
- `pathJoin()` function for joining paths across different platforms and environments
|
||||
- `fileUrlToPath()` function for converting file:// URLs to system paths
|
||||
- `pathToFileUrl()` function for converting system paths to file:// URLs
|
||||
- `dirname()` function for extracting directory from paths and URLs
|
||||
- Comprehensive test coverage for isomorphic path functions
|
||||
|
||||
### Changed
|
||||
- Build system now uses tsfolders for multi-folder compilation
|
||||
- Package exports now use modern exports field instead of main/typings
|
||||
|
||||
### Removed
|
||||
- Removed .gitlab-ci.yml file
|
14
dist/index.js
vendored
14
dist/index.js
vendored
@@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
var SmartpathTransform = require("./smartpath.transform");
|
||||
var SmartpathGet = require("./smartpath.get");
|
||||
/**
|
||||
*
|
||||
* @type {{getPath: (function(any): undefined)}}
|
||||
*/
|
||||
var smartpath = {
|
||||
transform: SmartpathTransform,
|
||||
get: SmartpathGet
|
||||
};
|
||||
module.exports = smartpath;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQSxJQUFPLGtCQUFrQixXQUFXLHVCQUF1QixDQUFDLENBQUM7QUFDN0QsSUFBTyxZQUFZLFdBQVcsaUJBQWlCLENBQUMsQ0FBQztBQUVqRDs7O0dBR0c7QUFDSCxJQUFJLFNBQVMsR0FBRztJQUNaLFNBQVMsRUFBRSxrQkFBa0I7SUFDN0IsR0FBRyxFQUFFLFlBQVk7Q0FFcEIsQ0FBQztBQUdGLGlCQUFTLFNBQVMsQ0FBQyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCJ0eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0cGF0aC5wbHVnaW5zXCIpO1xuaW1wb3J0IFNtYXJ0cGF0aFRyYW5zZm9ybSA9IHJlcXVpcmUoXCIuL3NtYXJ0cGF0aC50cmFuc2Zvcm1cIik7XG5pbXBvcnQgU21hcnRwYXRoR2V0ID0gcmVxdWlyZShcIi4vc21hcnRwYXRoLmdldFwiKTtcblxuLyoqXG4gKlxuICogQHR5cGUge3tnZXRQYXRoOiAoZnVuY3Rpb24oYW55KTogdW5kZWZpbmVkKX19XG4gKi9cbmxldCBzbWFydHBhdGggPSB7XG4gICAgdHJhbnNmb3JtOiBTbWFydHBhdGhUcmFuc2Zvcm0sXG4gICAgZ2V0OiBTbWFydHBhdGhHZXRcblxufTtcblxuXG5leHBvcnQgPSBzbWFydHBhdGg7XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
26
dist/smartpath.get.js
vendored
26
dist/smartpath.get.js
vendored
@@ -1,26 +0,0 @@
|
||||
"use strict";
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
var plugins = require("./smartpath.plugins");
|
||||
/**
|
||||
* returns the type of the given path. Can be "url" or "local"
|
||||
*/
|
||||
exports.type = function (pathStringArg) {
|
||||
var urlRegex = /http[s|\s]:\/\/.*/i;
|
||||
if (urlRegex.exec(pathStringArg)) {
|
||||
return "url";
|
||||
}
|
||||
else {
|
||||
return "local";
|
||||
}
|
||||
;
|
||||
};
|
||||
exports.home = function (pathArgument) {
|
||||
if (pathArgument) {
|
||||
return plugins.home.resolve(pathArgument);
|
||||
}
|
||||
else {
|
||||
return plugins.home();
|
||||
}
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBDQUEwQztBQUMxQyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRWhEOztHQUVHO0FBQ1EsWUFBSSxHQUFHLFVBQVMsYUFBb0I7SUFDM0MsSUFBSSxRQUFRLEdBQUcsb0JBQW9CLENBQUE7SUFDbkMsRUFBRSxDQUFBLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFBLENBQUM7UUFDN0IsTUFBTSxDQUFDLEtBQUssQ0FBQztJQUNqQixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsT0FBTyxDQUFDO0lBQ25CLENBQUM7SUFBQSxDQUFDO0FBQ04sQ0FBQyxDQUFDO0FBRVMsWUFBSSxHQUFHLFVBQVMsWUFBb0I7SUFDM0MsRUFBRSxDQUFBLENBQUMsWUFBWSxDQUFDLENBQUEsQ0FBQztRQUNiLE1BQU0sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUM5QyxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsT0FBTyxDQUFDLElBQUksRUFBRSxDQUFDO0lBQzFCLENBQUM7QUFDTCxDQUFDLENBQUMiLCJmaWxlIjoic21hcnRwYXRoLmdldC5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCJ0eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0cGF0aC5wbHVnaW5zXCIpO1xuXG4vKipcbiAqIHJldHVybnMgdGhlIHR5cGUgb2YgdGhlIGdpdmVuIHBhdGguIENhbiBiZSBcInVybFwiIG9yIFwibG9jYWxcIlxuICovXG5leHBvcnQgbGV0IHR5cGUgPSBmdW5jdGlvbihwYXRoU3RyaW5nQXJnOnN0cmluZyk6c3RyaW5nIHtcbiAgICBsZXQgdXJsUmVnZXggPSAvaHR0cFtzfFxcc106XFwvXFwvLiovaVxuICAgIGlmKHVybFJlZ2V4LmV4ZWMocGF0aFN0cmluZ0FyZykpe1xuICAgICAgICByZXR1cm4gXCJ1cmxcIjtcbiAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gXCJsb2NhbFwiO1xuICAgIH07XG59O1xuXG5leHBvcnQgbGV0IGhvbWUgPSBmdW5jdGlvbihwYXRoQXJndW1lbnQ/OnN0cmluZyl7XG4gICAgaWYocGF0aEFyZ3VtZW50KXtcbiAgICAgICAgcmV0dXJuIHBsdWdpbnMuaG9tZS5yZXNvbHZlKHBhdGhBcmd1bWVudCk7XG4gICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIHBsdWdpbnMuaG9tZSgpO1xuICAgIH1cbn07Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
|
7
dist/smartpath.plugins.js
vendored
7
dist/smartpath.plugins.js
vendored
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.home = require("home");
|
||||
exports.path = require("path");
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDakMsaUJBQVMsR0FBRyxPQUFPLENBQUUsV0FBVyxDQUFDLENBQUM7QUFDbEMsWUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztBQUN2QixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0cGF0aC5wbHVnaW5zLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxuZXhwb3J0IHZhciBiZWF1dHlsb2cgPSByZXF1aXJlIChcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCB2YXIgaG9tZSA9IHJlcXVpcmUoXCJob21lXCIpO1xuZXhwb3J0IHZhciBwYXRoID0gcmVxdWlyZShcInBhdGhcIik7XG5cbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
40
dist/smartpath.transform.js
vendored
40
dist/smartpath.transform.js
vendored
@@ -1,40 +0,0 @@
|
||||
"use strict";
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
var plugins = require("./smartpath.plugins");
|
||||
/* ------------------------------------------ *
|
||||
* ------------ helpers --------------------- *
|
||||
* ------------------------------------------ */
|
||||
var makeAbsolute = function (localPathArg, baseArg) {
|
||||
var absolutePath;
|
||||
if (baseArg) {
|
||||
absolutePath = plugins.path.join(baseArg, localPathArg);
|
||||
}
|
||||
else {
|
||||
absolutePath = plugins.path.resolve(localPathArg);
|
||||
}
|
||||
return absolutePath;
|
||||
};
|
||||
/* ------------------------------------------ *
|
||||
* ------- export functions ----------------- *
|
||||
* ------------------------------------------ */
|
||||
exports.toAbsolute = function (relativeArg, baseArg) {
|
||||
if (typeof relativeArg === "string") {
|
||||
return makeAbsolute(relativeArg, baseArg);
|
||||
}
|
||||
else if (Array.isArray(relativeArg)) {
|
||||
var relativeArray = relativeArg;
|
||||
var absoluteArray = [];
|
||||
for (var key in relativeArray) {
|
||||
absoluteArray.push(makeAbsolute(relativeArray[key], baseArg));
|
||||
}
|
||||
;
|
||||
return absoluteArray;
|
||||
}
|
||||
else {
|
||||
plugins.beautylog.error("smartpath.absolute() could not make sense of the input. " +
|
||||
"Input is neither String nor Array");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0cGF0aC50cmFuc2Zvcm0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBDQUEwQztBQUMxQyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRWhEOztnREFFZ0Q7QUFDaEQsSUFBSSxZQUFZLEdBQUcsVUFBUyxZQUFtQixFQUFFLE9BQWU7SUFDNUQsSUFBSSxZQUFtQixDQUFDO0lBQ3hCLEVBQUUsQ0FBQSxDQUFDLE9BQU8sQ0FBQyxDQUFBLENBQUM7UUFDUixZQUFZLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFDLFlBQVksQ0FBQyxDQUFDO0lBQzNELENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNILFlBQVksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUN2RCxDQUFDO0lBQ0QsTUFBTSxDQUFDLFlBQVksQ0FBQztBQUN4QixDQUFDLENBQUM7QUFFRjs7Z0RBRWdEO0FBQ3JDLGtCQUFVLEdBQUcsVUFBUyxXQUFlLEVBQUUsT0FBZTtJQUM3RCxFQUFFLENBQUEsQ0FBQyxPQUFPLFdBQVcsS0FBSyxRQUFRLENBQUMsQ0FBQSxDQUFDO1FBQ2hDLE1BQU0sQ0FBQyxZQUFZLENBQUMsV0FBVyxFQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzdDLENBQUM7SUFBQyxJQUFJLENBQUMsRUFBRSxDQUFBLENBQUMsS0FBSyxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFBLENBQUM7UUFDbEMsSUFBSSxhQUFhLEdBQUcsV0FBVyxDQUFBO1FBQy9CLElBQUksYUFBYSxHQUFZLEVBQUUsQ0FBQztRQUNoQyxHQUFHLENBQUMsQ0FBQyxJQUFJLEdBQUcsSUFBSSxhQUFhLENBQUMsQ0FBQSxDQUFDO1lBQzNCLGFBQWEsQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLGFBQWEsQ0FBQyxHQUFHLENBQUMsRUFBQyxPQUFPLENBQUMsQ0FBQyxDQUFDO1FBQ2pFLENBQUM7UUFBQSxDQUFDO1FBQ0YsTUFBTSxDQUFDLGFBQWEsQ0FBQztJQUN6QixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQywwREFBMEQ7WUFDOUUsbUNBQW1DLENBQUMsQ0FBQztRQUN6QyxNQUFNLENBQUMsS0FBSyxDQUFDO0lBQ2pCLENBQUM7QUFDTCxDQUFDLENBQUMiLCJmaWxlIjoic21hcnRwYXRoLnRyYW5zZm9ybS5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCJ0eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0cGF0aC5wbHVnaW5zXCIpO1xuXG4vKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKlxuICogLS0tLS0tLS0tLS0tIGhlbHBlcnMgLS0tLS0tLS0tLS0tLS0tLS0tLS0tICpcbiAqIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqL1xubGV0IG1ha2VBYnNvbHV0ZSA9IGZ1bmN0aW9uKGxvY2FsUGF0aEFyZzpzdHJpbmcsIGJhc2VBcmc/OnN0cmluZyk6c3RyaW5nIHtcbiAgICBsZXQgYWJzb2x1dGVQYXRoOnN0cmluZztcbiAgICBpZihiYXNlQXJnKXtcbiAgICAgICAgYWJzb2x1dGVQYXRoID0gcGx1Z2lucy5wYXRoLmpvaW4oYmFzZUFyZyxsb2NhbFBhdGhBcmcpO1xuICAgIH0gZWxzZSB7XG4gICAgICAgICBhYnNvbHV0ZVBhdGggPSBwbHVnaW5zLnBhdGgucmVzb2x2ZShsb2NhbFBhdGhBcmcpO1xuICAgIH1cbiAgICByZXR1cm4gYWJzb2x1dGVQYXRoO1xufTtcblxuLyogLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICpcbiAqIC0tLS0tLS0gZXhwb3J0IGZ1bmN0aW9ucyAtLS0tLS0tLS0tLS0tLS0tLSAqXG4gKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi9cbmV4cG9ydCBsZXQgdG9BYnNvbHV0ZSA9IGZ1bmN0aW9uKHJlbGF0aXZlQXJnOmFueSwgYmFzZUFyZz86c3RyaW5nKTphbnkge1xuICAgIGlmKHR5cGVvZiByZWxhdGl2ZUFyZyA9PT0gXCJzdHJpbmdcIil7XG4gICAgICAgIHJldHVybiBtYWtlQWJzb2x1dGUocmVsYXRpdmVBcmcsYmFzZUFyZyk7XG4gICAgfSBlbHNlIGlmKEFycmF5LmlzQXJyYXkocmVsYXRpdmVBcmcpKXtcbiAgICAgICAgbGV0IHJlbGF0aXZlQXJyYXkgPSByZWxhdGl2ZUFyZ1xuICAgICAgICBsZXQgYWJzb2x1dGVBcnJheTpzdHJpbmdbXSA9IFtdO1xuICAgICAgICBmb3IgKGxldCBrZXkgaW4gcmVsYXRpdmVBcnJheSl7XG4gICAgICAgICAgICBhYnNvbHV0ZUFycmF5LnB1c2gobWFrZUFic29sdXRlKHJlbGF0aXZlQXJyYXlba2V5XSxiYXNlQXJnKSk7XG4gICAgICAgIH07XG4gICAgICAgIHJldHVybiBhYnNvbHV0ZUFycmF5O1xuICAgIH0gZWxzZSB7XG4gICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLmVycm9yKFwic21hcnRwYXRoLmFic29sdXRlKCkgY291bGQgbm90IG1ha2Ugc2Vuc2Ugb2YgdGhlIGlucHV0LiBcIiArXG4gICAgICAgICAgICBcIklucHV0IGlzIG5laXRoZXIgU3RyaW5nIG5vciBBcnJheVwiKTtcbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cbn07Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
|
@@ -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
|
36
npmextra.json
Normal file
36
npmextra.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartpath",
|
||||
"description": "A library offering smart ways to handle file and directory paths.",
|
||||
"npmPackagename": "@push.rocks/smartpath",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"path handling",
|
||||
"file system",
|
||||
"directory manipulation",
|
||||
"file checks",
|
||||
"path transformation",
|
||||
"typescript",
|
||||
"node.js development",
|
||||
"URL handling",
|
||||
"absolute paths",
|
||||
"smart path resolution",
|
||||
"programming",
|
||||
"file management",
|
||||
"software development",
|
||||
"path utilities",
|
||||
"cross-platform path management"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"mode": "default",
|
||||
"coveralls": "true"
|
||||
}
|
68
package.json
68
package.json
@@ -1,32 +1,66 @@
|
||||
{
|
||||
"name": "smartpath",
|
||||
"version": "3.1.0",
|
||||
"description": "offers smart ways to handle paths",
|
||||
"main": "dist/index.js",
|
||||
"name": "@push.rocks/smartpath",
|
||||
"version": "5.1.0",
|
||||
"private": false,
|
||||
"description": "A library offering smart ways to handle file and directory paths.",
|
||||
"exports": {
|
||||
".": "./dist_ts/index.js",
|
||||
"./iso": "./dist_ts_iso/index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/ --verbose)",
|
||||
"build": "(tsbuild tsfolders)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pushrocks/smartpath.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartpath.git"
|
||||
},
|
||||
"keywords": [
|
||||
"json",
|
||||
"jade",
|
||||
"template"
|
||||
"path handling",
|
||||
"file system",
|
||||
"directory manipulation",
|
||||
"file checks",
|
||||
"path transformation",
|
||||
"typescript",
|
||||
"node.js development",
|
||||
"URL handling",
|
||||
"absolute paths",
|
||||
"smart path resolution",
|
||||
"programming",
|
||||
"file management",
|
||||
"software development",
|
||||
"path utilities",
|
||||
"cross-platform path management"
|
||||
],
|
||||
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/smartpath/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/smartpath",
|
||||
"dependencies": {
|
||||
"beautylog": "^3.1.2",
|
||||
"home": "^1.0.1"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/smartpath",
|
||||
"devDependencies": {
|
||||
"npmts": "^4.0.1",
|
||||
"should": "^8.3.0"
|
||||
}
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/tapbundle": "^5.0.23",
|
||||
"@types/node": "^20.12.7"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
|
||||
}
|
||||
|
10038
pnpm-lock.yaml
generated
Normal file
10038
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@@ -0,0 +1 @@
|
||||
no specific hints here, should be easy to understand from the files.
|
138
readme.md
Normal file
138
readme.md
Normal file
@@ -0,0 +1,138 @@
|
||||
# @push.rocks/smartpath
|
||||
|
||||
[@push.rocks/smartpath](https://github.com/pushrocks/smartpath) offers smart ways to handle paths.
|
||||
|
||||
## Install
|
||||
To install `@push.rocks/smartpath`, you'll need to run the following command using npm. Ensure you have Node.js and npm installed before you start.
|
||||
```bash
|
||||
npm install @push.rocks/smartpath --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
The `@push.rocks/smartpath` module provides a sophisticated yet straightforward approach to handle, manipulate, and evaluate file and directory paths within your TypeScript projects. By incorporating features like path normalization, transformation, and validation, `smartpath` facilitates powerful and efficient file system and URL path manipulation. This guide dives deep into the module's capabilities, showcasing a broad spectrum of use cases and demonstrating its versatility in handling paths.
|
||||
|
||||
### Getting Started
|
||||
To begin utilizing `smartpath` in your project, start by importing it in your TypeScript file:
|
||||
|
||||
```typescript
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
```
|
||||
|
||||
### Isomorphic Path Module
|
||||
For cross-platform path operations that work in any JavaScript environment (Node.js, browsers, Deno, etc.), use the isomorphic module:
|
||||
|
||||
```typescript
|
||||
import * as isoPath from '@push.rocks/smartpath/iso';
|
||||
|
||||
// Join paths with automatic platform detection
|
||||
const joinedPath = isoPath.pathJoin('/home/user', 'documents', 'file.txt');
|
||||
// Unix: /home/user/documents/file.txt
|
||||
// Windows: C:\Users\documents\file.txt
|
||||
|
||||
// Convert file:// URLs to system paths
|
||||
const systemPath = isoPath.fileUrlToPath('file:///home/user/file.txt');
|
||||
// Unix: /home/user/file.txt
|
||||
// Windows: C:\home\user\file.txt
|
||||
|
||||
// Convert system paths to file:// URLs
|
||||
const fileUrl = isoPath.pathToFileUrl('/home/user/file.txt');
|
||||
// Result: file:///home/user/file.txt
|
||||
|
||||
// Get directory from path or file URL
|
||||
const dir = isoPath.dirname('/home/user/documents/file.txt');
|
||||
// Result: /home/user/documents
|
||||
```
|
||||
|
||||
The isomorphic module automatically detects the path style (Windows vs POSIX) and handles:
|
||||
- file:// URL conversions
|
||||
- Mixed path separators
|
||||
- Cross-platform compatibility
|
||||
- Proper handling of Windows drive letters and UNC paths
|
||||
|
||||
### Creating a Smartpath Instance
|
||||
Instantiating a `Smartpath` object allows for the enrichment of path strings with additional context and manipulation capabilities:
|
||||
|
||||
```typescript
|
||||
const mySmartpath = new smartpath.Smartpath('/some/path/to/some.file');
|
||||
console.log(mySmartpath);
|
||||
```
|
||||
|
||||
### Path Validation
|
||||
Determining whether a path points to a file or directory is a common requirement. Here's how you can achieve this:
|
||||
|
||||
```typescript
|
||||
if (smartpath.check.isFile('./path/to/file.txt')) {
|
||||
console.log('This is a file.');
|
||||
}
|
||||
|
||||
if (smartpath.check.isDir('./path/to/directory')) {
|
||||
console.log('This is a directory.');
|
||||
}
|
||||
```
|
||||
|
||||
### Absolute Path Conversion
|
||||
Converting a relative path to an absolute one is a frequent operation, especially in dynamic file handling scenarios:
|
||||
|
||||
```typescript
|
||||
const absolutePath = smartpath.transform.makeAbsolute('./relative/path/to/file.txt');
|
||||
console.log(`Absolute path: ${absolutePath}`);
|
||||
```
|
||||
|
||||
### Handling Multiple Paths
|
||||
`smartpath` shines when dealing with multiple paths, offering efficient bulk operations:
|
||||
|
||||
```typescript
|
||||
const paths = ['./path/to/file1.txt', './another/path/to/file2.txt'];
|
||||
const absolutePaths = smartpath.transform.toAbsolute(paths);
|
||||
console.log(absolutePaths);
|
||||
```
|
||||
|
||||
### Understanding Path Types
|
||||
Identifying whether a path represents a local file system path or a URL is straightforward:
|
||||
|
||||
```typescript
|
||||
const pathType = smartpath.get.type('https://example.com/resource');
|
||||
console.log(`Path type: ${pathType}`); // 'url'
|
||||
```
|
||||
|
||||
### Home Directory Paths
|
||||
Easily manage paths relative to the user's home directory:
|
||||
|
||||
```typescript
|
||||
const homePath = smartpath.get.home('~/path/to/resource');
|
||||
console.log(`Home directory path: ${homePath}`);
|
||||
```
|
||||
|
||||
### Analyzing Path Components
|
||||
Breaking down a path into its components allows for detailed path analysis and manipulation:
|
||||
|
||||
```typescript
|
||||
const pathLevels = smartpath.get.pathLevels('/path/to/resource');
|
||||
console.log(pathLevels); // ['path', 'to', 'resource']
|
||||
```
|
||||
|
||||
### Path Manipulation and More
|
||||
Beyond the basics, `smartpath` offers a comprehensive set of tools for robust path manipulation, including normalizing paths across different operating systems, working with URL paths, and handling special path constructs like ".." and ".".
|
||||
|
||||
For more advanced use cases, such as transforming path lists, deriving relative paths, or integrating path handling into larger application workflows, `smartpath` provides both utility functions and object-oriented interfaces that streamline these operations.
|
||||
|
||||
By leveraging the full spectrum of `smartpath`'s features, developers can handle virtually any path-related task with ease, efficiency, and reliability. Whether you're building a complex file system utility, managing web application assets, or simply need reliable path manipulation in your TypeScript projects, `smartpath` offers the functionality and flexibility required to do the job right.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
145
test/test.iso.both.ts
Normal file
145
test/test.iso.both.ts
Normal file
@@ -0,0 +1,145 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartpath from '../ts_iso/index.js';
|
||||
|
||||
tap.test('pathJoin - should join path segments correctly', async () => {
|
||||
// Basic path joining
|
||||
expect(smartpath.pathJoin('path', 'to', 'file.txt')).toEqual('path/to/file.txt');
|
||||
expect(smartpath.pathJoin('/path', 'to', 'file.txt')).toEqual('/path/to/file.txt');
|
||||
|
||||
// Windows paths
|
||||
expect(smartpath.pathJoin('C:', 'Users', 'test')).toEqual('C:\\Users\\test');
|
||||
expect(smartpath.pathJoin('C:\\Users', 'test', 'file.txt')).toEqual('C:\\Users\\test\\file.txt');
|
||||
|
||||
// Empty segments
|
||||
expect(smartpath.pathJoin('path', '', 'file.txt')).toEqual('path/file.txt');
|
||||
expect(smartpath.pathJoin('', 'path', 'file.txt')).toEqual('path/file.txt');
|
||||
|
||||
// No segments
|
||||
expect(smartpath.pathJoin()).toEqual('');
|
||||
expect(smartpath.pathJoin('')).toEqual('');
|
||||
|
||||
// Single segment
|
||||
expect(smartpath.pathJoin('path')).toEqual('path');
|
||||
expect(smartpath.pathJoin('/path')).toEqual('/path');
|
||||
|
||||
// Multiple separators
|
||||
expect(smartpath.pathJoin('path/', '/to/', '/file.txt')).toEqual('path/to/file.txt');
|
||||
expect(smartpath.pathJoin('path\\\\', '\\\\to\\\\', '\\\\file.txt')).toEqual('path\\to\\file.txt');
|
||||
|
||||
// Root paths
|
||||
expect(smartpath.pathJoin('/')).toEqual('/');
|
||||
expect(smartpath.pathJoin('/', 'path')).toEqual('/path');
|
||||
});
|
||||
|
||||
tap.test('pathJoin - should handle file:// URLs', async () => {
|
||||
// Unix file URLs
|
||||
expect(smartpath.pathJoin('file:///home/user', 'documents', 'file.txt')).toEqual('/home/user/documents/file.txt');
|
||||
expect(smartpath.pathJoin('file:///home/user/', 'documents')).toEqual('/home/user/documents');
|
||||
|
||||
// Windows file URLs
|
||||
expect(smartpath.pathJoin('file:///C:/Users', 'test', 'file.txt')).toEqual('C:\\Users\\test\\file.txt');
|
||||
expect(smartpath.pathJoin('file:///D:/Projects/', 'app')).toEqual('D:\\Projects\\app');
|
||||
|
||||
// Mixed file URL and path
|
||||
expect(smartpath.pathJoin('file:///home/user', '../test')).toEqual('/home/user/../test');
|
||||
expect(smartpath.pathJoin('documents', 'file:///home/user/file.txt')).toEqual('documents/home/user/file.txt');
|
||||
});
|
||||
|
||||
tap.test('fileUrlToPath - should convert file URLs to paths', async () => {
|
||||
// Unix file URLs
|
||||
expect(smartpath.fileUrlToPath('file:///home/user/file.txt')).toEqual('/home/user/file.txt');
|
||||
expect(smartpath.fileUrlToPath('file:///home/user%20name/file.txt')).toEqual('/home/user name/file.txt');
|
||||
|
||||
// Windows file URLs
|
||||
expect(smartpath.fileUrlToPath('file:///C:/Users/test/file.txt')).toEqual('C:\\Users\\test\\file.txt');
|
||||
expect(smartpath.fileUrlToPath('file:///D:/My%20Documents/file.txt')).toEqual('D:\\My Documents\\file.txt');
|
||||
|
||||
// Not a file URL
|
||||
expect(smartpath.fileUrlToPath('/home/user/file.txt')).toEqual('/home/user/file.txt');
|
||||
expect(smartpath.fileUrlToPath('C:\\Users\\test\\file.txt')).toEqual('C:\\Users\\test\\file.txt');
|
||||
expect(smartpath.fileUrlToPath('https://example.com')).toEqual('https://example.com');
|
||||
});
|
||||
|
||||
tap.test('pathToFileUrl - should convert paths to file URLs', async () => {
|
||||
// Unix paths
|
||||
expect(smartpath.pathToFileUrl('/home/user/file.txt')).toEqual('file:///home/user/file.txt');
|
||||
expect(smartpath.pathToFileUrl('/home/user name/file.txt')).toEqual('file:///home/user%20name/file.txt');
|
||||
|
||||
// Windows paths
|
||||
expect(smartpath.pathToFileUrl('C:\\Users\\test\\file.txt')).toEqual('file:///C:/Users/test/file.txt');
|
||||
expect(smartpath.pathToFileUrl('D:\\My Documents\\file.txt')).toEqual('file:///D:/My%20Documents/file.txt');
|
||||
expect(smartpath.pathToFileUrl('C:/Users/test/file.txt')).toEqual('file:///C:/Users/test/file.txt');
|
||||
|
||||
// Already a file URL
|
||||
expect(smartpath.pathToFileUrl('file:///home/user/file.txt')).toEqual('file:///home/user/file.txt');
|
||||
|
||||
// Relative paths (can't make file URLs from these)
|
||||
expect(smartpath.pathToFileUrl('relative/path/file.txt')).toEqual('relative/path/file.txt');
|
||||
expect(smartpath.pathToFileUrl('./file.txt')).toEqual('./file.txt');
|
||||
|
||||
// Special characters
|
||||
expect(smartpath.pathToFileUrl('/path/with?query')).toEqual('file:///path/with%3Fquery');
|
||||
expect(smartpath.pathToFileUrl('/path/with#hash')).toEqual('file:///path/with%23hash');
|
||||
});
|
||||
|
||||
tap.test('dirname - should extract directory from paths and URLs', async () => {
|
||||
// Unix paths
|
||||
expect(smartpath.dirname('/home/user/file.txt')).toEqual('/home/user');
|
||||
expect(smartpath.dirname('/home/user/')).toEqual('/home');
|
||||
expect(smartpath.dirname('/file.txt')).toEqual('/');
|
||||
expect(smartpath.dirname('/')).toEqual('/');
|
||||
|
||||
// Windows paths
|
||||
expect(smartpath.dirname('C:\\Users\\test\\file.txt')).toEqual('C:\\Users\\test');
|
||||
expect(smartpath.dirname('C:\\file.txt')).toEqual('C:\\');
|
||||
expect(smartpath.dirname('C:\\')).toEqual('C:\\');
|
||||
|
||||
// File URLs
|
||||
expect(smartpath.dirname('file:///home/user/file.txt')).toEqual('/home/user');
|
||||
expect(smartpath.dirname('file:///C:/Users/test/file.txt')).toEqual('C:\\Users\\test');
|
||||
|
||||
// Relative paths
|
||||
expect(smartpath.dirname('relative/path/file.txt')).toEqual('relative/path');
|
||||
expect(smartpath.dirname('file.txt')).toEqual('.');
|
||||
expect(smartpath.dirname('')).toEqual('.');
|
||||
|
||||
// Mixed separators
|
||||
expect(smartpath.dirname('path\\to/file.txt')).toEqual('path\\to');
|
||||
expect(smartpath.dirname('path/to\\file.txt')).toEqual('path/to');
|
||||
});
|
||||
|
||||
tap.test('edge cases - should handle edge cases correctly', async () => {
|
||||
// Non-string values filtered out
|
||||
expect(smartpath.pathJoin('path', null as any, 'file.txt')).toEqual('path/file.txt');
|
||||
expect(smartpath.pathJoin('path', undefined as any, 'file.txt')).toEqual('path/file.txt');
|
||||
expect(smartpath.pathJoin('path', 123 as any, 'file.txt')).toEqual('path/file.txt');
|
||||
|
||||
// Very long paths
|
||||
const longSegment = 'a'.repeat(100);
|
||||
const result = smartpath.pathJoin(longSegment, longSegment, 'file.txt');
|
||||
expect(result).toEqual(`${longSegment}/${longSegment}/file.txt`);
|
||||
|
||||
// Unicode characters
|
||||
expect(smartpath.pathJoin('path', '文件夹', 'файл.txt')).toEqual('path/文件夹/файл.txt');
|
||||
expect(smartpath.fileUrlToPath('file:///home/用户/文件.txt')).toEqual('/home/用户/文件.txt');
|
||||
expect(smartpath.pathToFileUrl('/home/用户/文件.txt')).toEqual('file:///home/%E7%94%A8%E6%88%B7/%E6%96%87%E4%BB%B6.txt');
|
||||
|
||||
// Backslashes in Unix-style paths (should be preserved)
|
||||
expect(smartpath.pathJoin('/home/user', 'path\\with\\backslashes')).toEqual('/home/user/path\\with\\backslashes');
|
||||
});
|
||||
|
||||
tap.test('cross-platform behavior - should detect separators correctly', async () => {
|
||||
// Should detect Windows paths and use backslashes
|
||||
expect(smartpath.pathJoin('C:\\Users', 'test')).toEqual('C:\\Users\\test');
|
||||
expect(smartpath.pathJoin('D:', 'Projects', 'app')).toEqual('D:\\Projects\\app');
|
||||
|
||||
// Should detect Unix paths and use forward slashes
|
||||
expect(smartpath.pathJoin('/home', 'user')).toEqual('/home/user');
|
||||
expect(smartpath.pathJoin('/var', 'log', 'app.log')).toEqual('/var/log/app.log');
|
||||
|
||||
// Mixed paths - first segment determines separator
|
||||
expect(smartpath.pathJoin('C:\\Users', 'test/file.txt')).toEqual('C:\\Users\\test\\file.txt');
|
||||
expect(smartpath.pathJoin('/home', 'user\\documents')).toEqual('/home/user\\documents');
|
||||
});
|
||||
|
||||
await tap.start();
|
47
test/test.js
47
test/test.js
@@ -1,47 +0,0 @@
|
||||
/// <reference path="../ts/typings/main.d.ts" />
|
||||
var should = require("should");
|
||||
var smartpath = require("../dist/index.js");
|
||||
describe("smartpath", function () {
|
||||
describe(".transform", function () {
|
||||
describe("toAbsolute()", function () {
|
||||
var baseString = "/basedir";
|
||||
var relativeString = "somedir/somefile.txt";
|
||||
var relativeString2 = "anotherdir/anotherfile.txt";
|
||||
var 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 () {
|
||||
var 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=test.js.map
|
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC/B,IAAI,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAE5C,QAAQ,CAAC,WAAW,EAAC;IACjB,QAAQ,CAAC,YAAY,EAAC;QAClB,QAAQ,CAAC,cAAc,EAAC;YACpB,IAAI,UAAU,GAAG,UAAU,CAAC;YAC5B,IAAI,cAAc,GAAG,sBAAsB,CAAC;YAC5C,IAAI,eAAe,GAAG,4BAA4B,CAAC;YACnD,IAAI,aAAa,GAAG,CAAC,cAAc,EAAC,cAAc,EAAC,eAAe,CAAC,CAAC;YACpE,EAAE,CAAC,+BAA+B,EAAC;gBAC/B,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;gBACrE,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;gBAC9E,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,cAAc,EAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC5G,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,uEAAuE,EAAC;gBACvE,IAAI,aAAa,GAAG,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,aAAa,EAAC,UAAU,CAAC,CAAC;gBAC7E,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;gBACvC,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YAErD,CAAC,CAAC,CAAA;YACF,EAAE,CAAC,iDAAiD,EAAC;gBACjD,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;YACxD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,MAAM,EAAC;QACZ,QAAQ,CAAC,SAAS,EAAC;YACf,EAAE,CAAC,gCAAgC,EAAC;gBAChC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACtE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAChF,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,iCAAiC,EAAC;gBACjC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACjE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxE,CAAC,CAAC,CAAC;QACP,CAAC,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"}
|
110
test/test.ts
110
test/test.ts
@@ -1,48 +1,66 @@
|
||||
/// <reference path="../ts/typings/main.d.ts" />
|
||||
let should = require("should");
|
||||
let smartpath = require("../dist/index.js");
|
||||
import { tap, expect, expectAsync } from '@push.rocks/tapbundle';
|
||||
import * as smartpath from '../ts/index.js';
|
||||
|
||||
describe("smartpath",function(){
|
||||
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());
|
||||
});
|
||||
});
|
||||
});
|
||||
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.18',
|
||||
description: 'A library offering smart ways to handle file and directory paths.'
|
||||
}
|
21
ts/index.ts
21
ts/index.ts
@@ -1,17 +1,12 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
import plugins = require("./smartpath.plugins");
|
||||
import SmartpathTransform = require("./smartpath.transform");
|
||||
import SmartpathGet = require("./smartpath.get");
|
||||
import * as plugins from './smartpath.plugins.js';
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {{getPath: (function(any): undefined)}}
|
||||
*/
|
||||
let smartpath = {
|
||||
transform: SmartpathTransform,
|
||||
get: SmartpathGet
|
||||
// import modules
|
||||
import * as check from './smartpath.check.js';
|
||||
import * as get from './smartpath.get.js';
|
||||
import * as transform from './smartpath.transform.js';
|
||||
|
||||
};
|
||||
export { check, get, transform };
|
||||
|
||||
export const join = (...args: string[]) => plugins.path.join(...args);
|
||||
|
||||
export = smartpath;
|
||||
export * from './smartpath.classes.smartpath.js';
|
||||
|
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);
|
||||
}
|
||||
}
|
@@ -1,22 +1,53 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
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"
|
||||
* returns the type of the given path.
|
||||
* Can be "url" or "local"
|
||||
*/
|
||||
export let type = function(pathStringArg:string):string {
|
||||
let urlRegex = /http[s|\s]:\/\/.*/i
|
||||
if(urlRegex.exec(pathStringArg)){
|
||||
return "url";
|
||||
export const type = (pathStringArg: string): TPathType => {
|
||||
const urlRegex = /http[s|\s]:\/\/.*/i;
|
||||
if (urlRegex.exec(pathStringArg)) {
|
||||
return 'url';
|
||||
} else {
|
||||
return "local";
|
||||
};
|
||||
};
|
||||
|
||||
export let home = function(pathArgument?:string){
|
||||
if(pathArgument){
|
||||
return plugins.home.resolve(pathArgument);
|
||||
} else {
|
||||
return plugins.home();
|
||||
return 'local';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* gets the dirname from import.meta.url
|
||||
*/
|
||||
export const dirnameFromImportMetaUrl = (importMetaUrlArg: string) => {
|
||||
return plugins.path.dirname(plugins.url.fileURLToPath(importMetaUrlArg));
|
||||
};
|
||||
|
||||
export const dirname = (pathArg: string) => {
|
||||
return plugins.path.dirname(pathArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,5 +1,5 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
export var beautylog = require ("beautylog");
|
||||
export var home = require("home");
|
||||
export var path = require("path");
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as url from 'url';
|
||||
|
||||
export { os, path, url };
|
||||
|
@@ -1,35 +1,49 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
import plugins = require("./smartpath.plugins");
|
||||
import * as plugins from './smartpath.plugins.js';
|
||||
|
||||
/* ------------------------------------------ *
|
||||
* ------------ helpers --------------------- *
|
||||
* ------------------------------------------ */
|
||||
let makeAbsolute = function(localPathArg:string, baseArg?:string):string {
|
||||
let absolutePath:string;
|
||||
if(baseArg){
|
||||
absolutePath = plugins.path.join(baseArg,localPathArg);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* takes a path and makes it absolute
|
||||
* @param localPathArg
|
||||
* @param baseArg
|
||||
* @returns
|
||||
*/
|
||||
export const makeAbsolute = (localPathArg: string, baseArg?: string): string => {
|
||||
let absolutePath: string;
|
||||
let alreadyAbsolute = plugins.path.isAbsolute(localPathArg);
|
||||
if (!alreadyAbsolute && baseArg && !baseArg.startsWith('.')) {
|
||||
absolutePath = plugins.path.join(baseArg, localPathArg);
|
||||
} else if (!alreadyAbsolute) {
|
||||
if (baseArg) {
|
||||
plugins.path.join(baseArg, localPathArg);
|
||||
}
|
||||
absolutePath = plugins.path.resolve(localPathArg);
|
||||
} else {
|
||||
absolutePath = localPathArg;
|
||||
}
|
||||
return absolutePath;
|
||||
};
|
||||
|
||||
/* ------------------------------------------ *
|
||||
* ------- export functions ----------------- *
|
||||
* ------------------------------------------ */
|
||||
export let toAbsolute = function(relativeArg:any, baseArg?:string):any {
|
||||
if(typeof relativeArg === "string"){
|
||||
return makeAbsolute(relativeArg,baseArg);
|
||||
} else if(Array.isArray(relativeArg)){
|
||||
let relativeArray = relativeArg
|
||||
let absoluteArray:string[] = [];
|
||||
for (let key in relativeArray){
|
||||
absoluteArray.push(makeAbsolute(relativeArray[key],baseArg));
|
||||
};
|
||||
/*
|
||||
* like makeAbsolute, but takes different complex contructs like arrays and objects
|
||||
*/
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
};
|
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"mocha": "github:DefinitelyTyped/DefinitelyTyped/mocha/mocha.d.ts#d6dd320291705694ba8e1a79497a908e9f5e6617",
|
||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
||||
}
|
||||
}
|
191
ts_iso/index.ts
Normal file
191
ts_iso/index.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Cross-platform path.join function that works in any JavaScript environment
|
||||
* Handles regular paths and file:// URLs from import.meta.url
|
||||
* @param segments - Path segments to join
|
||||
* @returns Joined path string
|
||||
*/
|
||||
export function pathJoin(...segments: string[]): string {
|
||||
// Filter out empty strings and non-string values
|
||||
const validSegments = segments.filter(segment =>
|
||||
typeof segment === 'string' && segment.length > 0
|
||||
);
|
||||
|
||||
// If no valid segments, return empty string
|
||||
if (validSegments.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Convert file:// URLs to paths
|
||||
const processedSegments = validSegments.map(segment => {
|
||||
return fileUrlToPath(segment);
|
||||
});
|
||||
|
||||
// Detect if we're dealing with Windows-style paths
|
||||
const isWindowsPath = processedSegments.some(segment => {
|
||||
// Check for Windows drive letter
|
||||
if (/^[a-zA-Z]:/.test(segment)) return true;
|
||||
// Check if first segment has backslashes (indicating Windows)
|
||||
if (processedSegments[0] === segment && segment.includes('\\')) return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
// Choose separator and normalize function based on path style
|
||||
const separator = isWindowsPath ? '\\' : '/';
|
||||
|
||||
// Normalize segments based on path style
|
||||
const normalizedSegments = processedSegments.map((segment) => {
|
||||
if (isWindowsPath) {
|
||||
// On Windows, both / and \ are separators
|
||||
return segment.replace(/[\/\\]+/g, '\\');
|
||||
} else {
|
||||
// On POSIX, only / is a separator, \ is literal
|
||||
return segment.replace(/\/+/g, '/');
|
||||
}
|
||||
});
|
||||
|
||||
// Join segments and handle edge cases
|
||||
let result = '';
|
||||
|
||||
for (let i = 0; i < normalizedSegments.length; i++) {
|
||||
const segment = normalizedSegments[i];
|
||||
|
||||
if (i === 0) {
|
||||
result = segment;
|
||||
} else {
|
||||
// Remove leading separator from segment if result already ends with one
|
||||
let cleanSegment = segment;
|
||||
if (segment.startsWith(separator)) {
|
||||
cleanSegment = segment.slice(1);
|
||||
}
|
||||
|
||||
// Add separator if result doesn't end with one
|
||||
if (result && !result.endsWith(separator)) {
|
||||
result += separator;
|
||||
}
|
||||
|
||||
result += cleanSegment;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle edge cases
|
||||
if (result === '' && validSegments.some(s => s === '/' || s === '\\')) {
|
||||
result = separator;
|
||||
}
|
||||
|
||||
// Clean up multiple consecutive separators
|
||||
if (isWindowsPath) {
|
||||
result = result.replace(/\\+/g, '\\');
|
||||
// Special case for UNC paths
|
||||
if (result.startsWith('\\\\') && !result.startsWith('\\\\\\')) {
|
||||
// Keep double backslash for UNC paths
|
||||
} else if (result.match(/^\\[^\\]/)) {
|
||||
// Single leading backslash on Windows (unusual but valid)
|
||||
}
|
||||
} else {
|
||||
result = result.replace(/\/+/g, '/');
|
||||
// Preserve leading slash for absolute paths
|
||||
if (processedSegments[0].startsWith('/') && !result.startsWith('/')) {
|
||||
result = '/' + result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a file:// URL to a system path
|
||||
* @param fileUrl - A file:// URL (e.g., from import.meta.url)
|
||||
* @returns System path
|
||||
*/
|
||||
export function fileUrlToPath(fileUrl: string): string {
|
||||
if (!fileUrl.startsWith('file://')) {
|
||||
return fileUrl;
|
||||
}
|
||||
|
||||
// Remove file:// protocol
|
||||
let path = fileUrl.slice(7);
|
||||
|
||||
// Handle Windows file URLs: file:///C:/path -> C:\path
|
||||
if (/^\/[a-zA-Z]:/.test(path)) {
|
||||
path = path.slice(1);
|
||||
// Convert forward slashes to backslashes for Windows
|
||||
path = path.replace(/\//g, '\\');
|
||||
}
|
||||
|
||||
// Decode URL encoding
|
||||
path = decodeURIComponent(path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a system path to a file:// URL
|
||||
* @param path - System path
|
||||
* @returns file:// URL
|
||||
*/
|
||||
export function pathToFileUrl(path: string): string {
|
||||
if (path.startsWith('file://')) {
|
||||
return path;
|
||||
}
|
||||
|
||||
// Normalize slashes to forward slashes for URL
|
||||
let urlPath = path.replace(/\\/g, '/');
|
||||
|
||||
// Encode special characters
|
||||
urlPath = encodeURI(urlPath).replace(/[?#]/g, encodeURIComponent);
|
||||
|
||||
// Check if it's a Windows absolute path
|
||||
if (/^[a-zA-Z]:/.test(urlPath)) {
|
||||
return `file:///${urlPath}`;
|
||||
}
|
||||
|
||||
// Check if it's an absolute path
|
||||
if (urlPath.startsWith('/')) {
|
||||
return `file://${urlPath}`;
|
||||
}
|
||||
|
||||
// Relative path - just return as-is (can't make a file URL from relative path)
|
||||
return urlPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directory from a file URL or path
|
||||
* @param urlOrPath - File URL (like import.meta.url) or regular path
|
||||
* @returns Directory path
|
||||
*/
|
||||
export function dirname(urlOrPath: string): string {
|
||||
// Convert file URL to path if needed
|
||||
let path = fileUrlToPath(urlOrPath);
|
||||
|
||||
// Remove trailing slashes (but keep root slashes)
|
||||
if (path.length > 1 && (path.endsWith('/') || path.endsWith('\\'))) {
|
||||
// Special case: don't remove trailing slash for Windows drive root
|
||||
if (!(path.length === 3 && path[1] === ':')) {
|
||||
path = path.slice(0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
// Special case for Windows drive root (C:\ or C:)
|
||||
if (path.match(/^[a-zA-Z]:\\?$/)) {
|
||||
return path.endsWith('\\') ? path : path + '\\';
|
||||
}
|
||||
|
||||
// Find the last separator
|
||||
const lastSlash = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
|
||||
|
||||
if (lastSlash === -1) {
|
||||
return '.';
|
||||
}
|
||||
|
||||
// Special case for root
|
||||
if (lastSlash === 0) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
// Special case for Windows drive root (C:\)
|
||||
if (lastSlash === 2 && path[1] === ':') {
|
||||
return path.slice(0, 3);
|
||||
}
|
||||
|
||||
return path.slice(0, lastSlash);
|
||||
}
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user