Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e0bd5cd6c | |||
| 1f3e170a88 | |||
| 6a7570de7b | |||
| 579e25fe5a | |||
| 871a22a801 | |||
| aacb4a6873 | |||
| 0ef1af7b86 | |||
| 2af0329918 | |||
| b65a460ef2 | |||
| 3f5b0ebe1e | |||
| 6f2cedc1dd | |||
| 2c29ae3bf0 | |||
| b26b8ed4a6 | |||
| 0e6877d2d1 | |||
| 8a0c3fe906 | |||
| ae861fa271 | |||
| 3e78466e5f | |||
| eea19bcd89 | |||
| 1fc95fcf0e | |||
| 14ba4465d9 | |||
| 707e31d517 | |||
| 64d85e711a | |||
| 34a5cc9862 | |||
| d43d1ba212 | |||
| 65e771f1ba | |||
| 5825a602ed | |||
| 5e961f7a5b | |||
| 36bcb9265a | |||
| 53bf2f3569 | |||
| 523ab7ee77 | |||
| d60cc5430f | |||
| c0035bb4f3 | |||
| 976f81420f | |||
| 1be144d099 | |||
| 9d4b7a5292 | |||
| 563d6f0ac3 | |||
| 4da0aeb871 | |||
| 931defe98a | |||
| 1e6077ce34 | |||
| 8b1769d65e | |||
| 48878c0b38 |
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
|
||||||
137
.gitlab-ci.yml
137
.gitlab-ci.yml
@@ -1,137 +0,0 @@
|
|||||||
# 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
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# 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
|
|
||||||
|
|
||||||
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 lts
|
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command tsdoc
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
||||||
4
.snyk
4
.snyk
@@ -1,4 +0,0 @@
|
|||||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
|
||||||
version: v1.13.5
|
|
||||||
ignore: {}
|
|
||||||
patch: {}
|
|
||||||
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
96
changelog.md
Normal file
96
changelog.md
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-09-12 - 4.1.0 - feat(core)
|
||||||
|
Introduce native implementations for Base64, random generation and normalization; remove runtime plugin dependencies; update tests, docs and package metadata
|
||||||
|
|
||||||
|
- Implemented a cross-platform universal Base64 encoder/decoder and replaced usage of external js-base64 with the internal implementation
|
||||||
|
- Added a custom, cross-platform random string generator (uses crypto.getRandomValues when available) and removed dependency on randomatic / crypto-random-string
|
||||||
|
- Replaced strip-indent usage with an internal stripIndent implementation in normalize utilities
|
||||||
|
- Switched domain parsing to use the standard URL class instead of external url.parse
|
||||||
|
- Simplified ts/smartstring.plugins.ts to only export @push.rocks/isounique and removed several plugin re-exports (js-base64, strip-indent, randomatic, url, smartenv)
|
||||||
|
- Updated test imports to use @git.zone/tstest/tapbundle
|
||||||
|
- Expanded and updated README with full usage, examples and API reference
|
||||||
|
- Updated package.json: trimmed dependencies, bumped @git.zone/tstest version, added packageManager (pnpm) entry and adjusted files/browserslist
|
||||||
|
- Added .claude/settings.local.json
|
||||||
|
|
||||||
|
## 2024-05-29 - 4.0.15 - maintenance
|
||||||
|
Package metadata and TypeScript configuration updates.
|
||||||
|
|
||||||
|
- Updated package description.
|
||||||
|
- TypeScript configuration (tsconfig) adjustments.
|
||||||
|
- npmextra.json updated (githost entries).
|
||||||
|
|
||||||
|
## 2024-03-03 - 4.0.14 → 4.0.1 - maintenance & core fixes
|
||||||
|
Routine core fixes, small updates and version bumps across the 4.0.x series.
|
||||||
|
|
||||||
|
- Multiple "fix(core): update" commits addressing internal/core issues.
|
||||||
|
- Several version-only releases (patch bumps and releases with minimal change notes).
|
||||||
|
|
||||||
|
## 2022-03-18 - 4.0.2 → 3.0.26 - release consolidation
|
||||||
|
Consolidated releases and small fixes spanning late 2020–early 2022.
|
||||||
|
|
||||||
|
- Several patch releases with minor fixes and version bumps.
|
||||||
|
- Routine maintenance and stability improvements.
|
||||||
|
|
||||||
|
## 2018-11-28 - 3.0.4 → 3.0.0 - CI & dependency fixes
|
||||||
|
Improvements to build/CI and dependency cleanups for the 3.0.x line.
|
||||||
|
|
||||||
|
- fix(dependencies and structure): updated dependencies and project structure (3.0.4).
|
||||||
|
- fix(ci): reduced build dependencies and fixed build steps (3.0.3, 3.0.2).
|
||||||
|
- fix(dependencies): updated test framework and removed obsolete dependency on typings-global (3.0.1, 3.0.0).
|
||||||
|
- Numerous small fixes and version bump releases across 3.0.x.
|
||||||
|
|
||||||
|
## 2018-07-21 - 2.0.28 - BREAKING CHANGE: package scope
|
||||||
|
Breaking change: package scope changed.
|
||||||
|
|
||||||
|
- Changed package scope to @pushrocks (BREAKING CHANGE).
|
||||||
|
|
||||||
|
## 2017-10-26 - 2.0.27 → 2.0.25 - code quality & npm metadata
|
||||||
|
Small refactors and npm metadata additions.
|
||||||
|
|
||||||
|
- Refactor to use const (2.0.27).
|
||||||
|
- Added npmextra.json (2.0.26).
|
||||||
|
- Added create module (2.0.25).
|
||||||
|
|
||||||
|
## 2016-10-31 - 2.0.19 → 2.0.17 - Base64 & exports
|
||||||
|
Added Base64 handling and improved exports.
|
||||||
|
|
||||||
|
- Added Base64 handling and exposed base64 functions separate from class (2.0.17–2.0.19).
|
||||||
|
- Small export fixes.
|
||||||
|
|
||||||
|
## 2016-07-17 - 2.0.14 → 2.0.12 - ES6, indent/deindent, tests
|
||||||
|
Feature enhancements around string indentation and ES6 migration.
|
||||||
|
|
||||||
|
- Switched codebase to ES6 (2.0.14).
|
||||||
|
- Implemented deindent and working indent module; added tests (2.0.12).
|
||||||
|
- Prep work for indent functionality and recompiled builds (2.0.11, 2.0.10).
|
||||||
|
|
||||||
|
## 2016-06-21 - 2.0.9 → 2.0.6 - domain handling improvements
|
||||||
|
Domain parsing and regex improvements.
|
||||||
|
|
||||||
|
- Fixed Domain regex to include '-' and '_' and improved fullName handling (2.0.9, 2.0.8).
|
||||||
|
- Now evaluates Domains without protocol specified (2.0.6).
|
||||||
|
|
||||||
|
## 2016-05-25 - 2.0.4 → 2.0.0 - core features & CI/docs
|
||||||
|
Major 2.0.0 work and related improvements.
|
||||||
|
|
||||||
|
- Now computes zoneName and detects protocol (2.0.0).
|
||||||
|
- Added authors note, improved README and CI (AppVeyor, GitLab CI) across several commits.
|
||||||
|
- Multiple small fixes, dependency updates and YML/CI tweaks (2.0.4, 2.0.3, 2.0.2, 2.0.1).
|
||||||
|
|
||||||
|
## 2016-05-16 - 1.0.3 → 1.0.1 - parser & typings fixes
|
||||||
|
Parser improvements and TypeScript declaration fixes.
|
||||||
|
|
||||||
|
- Correctly parsing a Domain and structure updates (1.0.3).
|
||||||
|
- Fixes for typings and declaration issues (1.0.2, 1.0.1).
|
||||||
|
|
||||||
|
## 2016-04-15 - 1.0.0 → 0.0.3 - initial stable release
|
||||||
|
Initial stable release artifacts.
|
||||||
|
|
||||||
|
- Added TypeScript regex section and performed first 1.0.0 release (1.0.0).
|
||||||
|
- Prior 0.0.x preparatory releases.
|
||||||
|
|
||||||
|
## 2016-02-23 - 0.0.0 → initial - project initialization
|
||||||
|
Project initialization and first commits.
|
||||||
|
|
||||||
|
- Initial commit and early CI/travis updates.
|
||||||
@@ -11,12 +11,29 @@
|
|||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartstring",
|
"gitrepo": "smartstring",
|
||||||
"shortDescription": "handle strings in smart ways. TypeScript ready.",
|
"description": "A library for handling strings in smart ways, including manipulation and encoding, with TypeScript support.",
|
||||||
"npmPackagename": "@pushrocks/smartstring",
|
"npmPackagename": "@push.rocks/smartstring",
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
}
|
"keywords": [
|
||||||
|
"string manipulation",
|
||||||
|
"encode",
|
||||||
|
"decode",
|
||||||
|
"base64",
|
||||||
|
"indentation",
|
||||||
|
"normalization",
|
||||||
|
"regex",
|
||||||
|
"random string",
|
||||||
|
"cryptographic string",
|
||||||
|
"domain parsing",
|
||||||
|
"git repository parsing",
|
||||||
|
"docker environment parsing"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
11049
package-lock.json
generated
11049
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
50
package.json
50
package.json
@@ -1,45 +1,48 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstring",
|
"name": "@push.rocks/smartstring",
|
||||||
"version": "3.0.23",
|
"version": "4.1.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "handle strings in smart ways. TypeScript ready.",
|
"description": "A library for handling strings in smart ways, including manipulation and encoding, with TypeScript support.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://gitlab.com/pushrocks/smartstring.git"
|
"url": "https://code.foss.global/push.rocks/smartstring.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
"string manipulation",
|
||||||
|
"encode",
|
||||||
|
"decode",
|
||||||
|
"base64",
|
||||||
|
"indentation",
|
||||||
|
"normalization",
|
||||||
"regex",
|
"regex",
|
||||||
"string"
|
"random string",
|
||||||
|
"cryptographic string",
|
||||||
|
"domain parsing",
|
||||||
|
"git repository parsing",
|
||||||
|
"docker environment parsing"
|
||||||
],
|
],
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/smartstring/issues"
|
"url": "https://gitlab.com/push.rocks/smartstring/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
"homepage": "https://code.foss.global/push.rocks/smartstring",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@git.zone/tsbuild": "^2.1.72",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@git.zone/tsrun": "^1.2.42",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@git.zone/tstest": "^2.3.7",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@types/node": "^20.11.24"
|
||||||
"@types/node": "^14.14.17",
|
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartenv": "^4.0.16",
|
"@push.rocks/isounique": "^1.0.5"
|
||||||
"crypto-random-string": "^3.3.0",
|
|
||||||
"js-base64": "^2.5.1",
|
|
||||||
"normalize-newline": "^3.0.0",
|
|
||||||
"randomatic": "^3.1.1",
|
|
||||||
"strip-indent": "^3.0.0",
|
|
||||||
"url": "^0.11.0"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@@ -55,5 +58,6 @@
|
|||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
]
|
],
|
||||||
|
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"
|
||||||
}
|
}
|
||||||
|
|||||||
8271
pnpm-lock.yaml
generated
Normal file
8271
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 @@
|
|||||||
|
|
||||||
422
readme.md
422
readme.md
@@ -1,77 +1,379 @@
|
|||||||
# @pushrocks/smartstring
|
# @push.rocks/smartstring
|
||||||
handle strings in smart ways. TypeScript ready.
|
|
||||||
|
|
||||||
## Availabililty and Links
|
🎯 **Smart string manipulation for TypeScript** - Your comprehensive toolkit for handling strings, domains, Git URLs, and encodings with elegance and precision.
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartstring)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartstring)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartstring)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstring/)
|
|
||||||
|
|
||||||
## Status for master
|
## Why smartstring?
|
||||||
|
|
||||||
Status Category | Status Badge
|
When working with strings in modern JavaScript/TypeScript applications, you often need more than just basic manipulation. You need to:
|
||||||
-- | --
|
- Parse and validate domains and URLs
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
- Handle Git repository URLs across different formats
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
- Encode/decode Base64 for data transmission
|
||||||
npm | [](https://lossless.cloud)
|
- Normalize indentation in code generators
|
||||||
Snyk | [](https://lossless.cloud)
|
- Create cryptographically secure random strings
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
- Validate string encodings
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
- Parse Docker environment variables
|
||||||
Code Style | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
**smartstring** unifies all these capabilities in a single, tree-shakeable, TypeScript-native package with zero setup overhead.
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
## Install
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
```bash
|
||||||
|
npm install @push.rocks/smartstring --save
|
||||||
|
```
|
||||||
|
|
||||||
|
Or using pnpm (recommended):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm add @push.rocks/smartstring
|
||||||
|
```
|
||||||
|
|
||||||
|
## Features at a Glance
|
||||||
|
|
||||||
|
✅ **Domain parsing** - Extract protocols, subdomains, domains, and TLDs
|
||||||
|
✅ **Git URL handling** - Parse and convert between SSH and HTTPS formats
|
||||||
|
✅ **Base64 encoding** - Standard and URL-safe Base64 operations
|
||||||
|
✅ **Smart indentation** - Indent, outdent, and normalize multi-line strings
|
||||||
|
✅ **Random strings** - Pattern-based and cryptographically secure generation
|
||||||
|
✅ **String normalization** - Clean and standardize whitespace
|
||||||
|
✅ **Type checking** - Validate UTF-8 and Base64 encodings
|
||||||
|
✅ **Docker env parsing** - Transform Docker environment arrays to objects
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
### 🌐 Domain Parsing
|
||||||
|
|
||||||
```javascript
|
Extract detailed information from any URL or domain string:
|
||||||
import * as smartstring from 'smartstring';
|
|
||||||
|
|
||||||
// classes
|
```typescript
|
||||||
|
import { Domain } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
// smartstring.Domain class
|
const domain = new Domain('https://subdomain.example.com:3000/path');
|
||||||
let myDomain = new smartstring.Domain('https://sub.main.tld');
|
|
||||||
myDomain.level1; // "tld"
|
|
||||||
myDomain.level2; // "main"
|
|
||||||
// level3 , level 4 and so on...
|
|
||||||
myDomain.zoneName; // "main.tld"
|
|
||||||
myDOmain.protocol; // "https"
|
|
||||||
|
|
||||||
// smartstring.GitRepo class
|
console.log(domain.protocol); // 'https'
|
||||||
let myGitRepo = new smartstring.GitRepo('git@github.com:someorg/somerepo.git'); // takes https and git and npm repo URL versions
|
console.log(domain.hostname); // 'subdomain.example.com'
|
||||||
myGitRepo.host; // "github.com"
|
console.log(domain.port); // '3000'
|
||||||
myGitRepo.user; // "someorg"
|
console.log(domain.pathname); // '/path'
|
||||||
myGitRepo.repo; // "somerepo"
|
console.log(domain.fullUrl); // 'https://subdomain.example.com:3000/path'
|
||||||
myGitRepo.accessToken; // accessToken if specified with https
|
|
||||||
myGitRepo.sshUrl; // "git@github.com:someorg/somerepo.git" (computed also from https)
|
|
||||||
myGitRepo.httpsUrl; // "https://github.com/someorg/somerepo.git" (computed also from ssh)
|
|
||||||
|
|
||||||
//smartstring.Base64
|
// Domain level extraction
|
||||||
let myBase64 = new smartstring.Base64('somestring', 'string'); // first arg is the string, second is string type (can be string, base64, base64uri)
|
console.log(domain.level1); // 'com' - TLD
|
||||||
myBase64.simpleString; // 'somestring'
|
console.log(domain.level2); // 'example' - Domain
|
||||||
myBase64.base64String; // base64 representation of 'somestring'
|
console.log(domain.level3); // 'subdomain' - Subdomain
|
||||||
myBase64.base64UriString; // base64uri representation of 'sometring'
|
console.log(domain.zoneName); // 'example.com' - Full domain without subdomain
|
||||||
|
console.log(domain.subdomain); // 'subdomain'
|
||||||
// methods
|
|
||||||
smartstring.base64.encode('somestring'); // encodes 'somestring' to base64
|
|
||||||
smartstring.base64.encodeUri('sometring'); // encodes 'somestring' to base64uri
|
|
||||||
smartstring.base64.decode(); // decodes base64 and base64uri to simple string respresentation
|
|
||||||
|
|
||||||
smartstring.indent.indent('somestringanotherstring', 4); // indents a string by 4
|
|
||||||
smartstring.indent.indent('somestringanotherstring', '>>>> '); // indents a string with a prefix
|
|
||||||
smartstring.indent.normalize(' somestring anotherstring', '>>>> '); // looks for the least amount of indention and removes superflouous space
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contribution
|
### 🔧 Git Repository URLs
|
||||||
|
|
||||||
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). :)
|
Parse and convert Git repository URLs between SSH and HTTPS formats:
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
```typescript
|
||||||
|
import { GitRepo } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
// Parse SSH format
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
const repo = new GitRepo('git@github.com:user/awesome-project.git');
|
||||||
|
console.log(repo.host); // 'github.com'
|
||||||
|
console.log(repo.user); // 'user'
|
||||||
|
console.log(repo.repo); // 'awesome-project'
|
||||||
|
console.log(repo.httpsUrl); // 'https://github.com/user/awesome-project.git'
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
// Parse HTTPS format
|
||||||
|
const httpsRepo = new GitRepo('https://gitlab.com/team/project.git');
|
||||||
|
console.log(httpsRepo.sshUrl); // 'git@gitlab.com:team/project.git'
|
||||||
|
console.log(httpsRepo.httpsUrl); // 'https://gitlab.com/team/project.git'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔐 Base64 Encoding
|
||||||
|
|
||||||
|
Handle Base64 encoding with both standard and URL-safe variants:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Base64, base64 } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
// Using the Base64 class
|
||||||
|
const encoded = new Base64('Hello World! 👋', 'string');
|
||||||
|
console.log(encoded.base64String); // Standard Base64
|
||||||
|
console.log(encoded.base64UriString); // URL-safe Base64
|
||||||
|
console.log(encoded.simpleString); // Decoded string
|
||||||
|
|
||||||
|
// Using utility functions
|
||||||
|
const quickEncode = base64.encode('Secret message');
|
||||||
|
const quickDecode = base64.decode(quickEncode);
|
||||||
|
|
||||||
|
// Validate Base64 strings
|
||||||
|
console.log(base64.isBase64('SGVsbG8=')); // true
|
||||||
|
console.log(base64.isBase64('Not Base64!')); // false
|
||||||
|
|
||||||
|
// URL-safe Base64 operations
|
||||||
|
const urlSafeEncoded = base64.encodeUri('https://example.com/path?param=value');
|
||||||
|
const urlSafeDecoded = base64.decodeUri(urlSafeEncoded);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 📐 Smart Indentation
|
||||||
|
|
||||||
|
Manage indentation in multi-line strings with precision:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { indent } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
// Indent with spaces
|
||||||
|
const indented = indent.indent('Line 1\nLine 2\nLine 3', 4);
|
||||||
|
// Result:
|
||||||
|
// Line 1
|
||||||
|
// Line 2
|
||||||
|
// Line 3
|
||||||
|
|
||||||
|
// Indent with custom prefix
|
||||||
|
const prefixed = indent.indentWithPrefix('Item 1\nItem 2', '> ');
|
||||||
|
// Result:
|
||||||
|
// > Item 1
|
||||||
|
// > Item 2
|
||||||
|
|
||||||
|
// Add prefix to first line only
|
||||||
|
const firstLinePrefixed = indent.addPrefix('Chapter\nContent here', '# ');
|
||||||
|
// Result:
|
||||||
|
// # Chapter
|
||||||
|
// Content here
|
||||||
|
|
||||||
|
// Normalize irregular indentation
|
||||||
|
const messy = `
|
||||||
|
function hello() {
|
||||||
|
console.log('Hi');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const clean = indent.normalize(messy);
|
||||||
|
// Result: Properly aligned with minimum indentation preserved
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🎲 Random String Generation
|
||||||
|
|
||||||
|
Create random strings with specific patterns or cryptographic security:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { create } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
// Pattern-based random strings
|
||||||
|
// A = uppercase, a = lowercase, 0 = number, ! = special, * = any
|
||||||
|
const password = create.createRandomString('Aa0!', 16);
|
||||||
|
// Example: "Kg7$Lp2@Qm9#Xn4!"
|
||||||
|
|
||||||
|
const alphanumeric = create.createRandomString('Aa0', 10);
|
||||||
|
// Example: "K7gLp2Qm9X"
|
||||||
|
|
||||||
|
const numbers = create.createRandomString('0', 6);
|
||||||
|
// Example: "472819"
|
||||||
|
|
||||||
|
// Cryptographically secure random strings
|
||||||
|
const cryptoId = create.createCryptoRandomString();
|
||||||
|
// Example: "f7b2d8e0-3c4a-4b9c-8d2e-1f0a7b9c8d7e"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🧹 String Normalization
|
||||||
|
|
||||||
|
Clean and standardize strings for consistent formatting:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { normalize } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
const messyString = `
|
||||||
|
This text has
|
||||||
|
inconsistent indentation
|
||||||
|
and too much whitespace
|
||||||
|
|
||||||
|
|
||||||
|
between lines...
|
||||||
|
`;
|
||||||
|
|
||||||
|
const cleaned = normalize.standard(messyString);
|
||||||
|
// Result: Properly formatted with consistent spacing
|
||||||
|
|
||||||
|
// Custom normalization
|
||||||
|
const customNormalized = normalize.normal(messyString);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔍 String Type Validation
|
||||||
|
|
||||||
|
Check string encodings and types:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { type } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
// Check if string is valid UTF-8
|
||||||
|
const isValidUtf8 = type.isUtf8('Hello 世界');
|
||||||
|
console.log(isValidUtf8); // true
|
||||||
|
|
||||||
|
// Check if string is Base64
|
||||||
|
const isBase64String = type.isBase64('SGVsbG8gV29ybGQ=');
|
||||||
|
console.log(isBase64String); // true
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🐳 Docker Environment Variables
|
||||||
|
|
||||||
|
Parse Docker-style environment variable arrays:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { docker } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
const envArray = [
|
||||||
|
'NODE_ENV=production',
|
||||||
|
'PORT=3000',
|
||||||
|
'DATABASE_URL=postgresql://localhost:5432/mydb',
|
||||||
|
'API_KEY=secret123'
|
||||||
|
];
|
||||||
|
|
||||||
|
const envObject = docker.makeEnvObject(envArray);
|
||||||
|
|
||||||
|
console.log(envObject.NODE_ENV); // 'production'
|
||||||
|
console.log(envObject.PORT); // '3000'
|
||||||
|
console.log(envObject.DATABASE_URL); // 'postgresql://localhost:5432/mydb'
|
||||||
|
console.log(envObject.API_KEY); // 'secret123'
|
||||||
|
|
||||||
|
// Use in Docker-related configurations
|
||||||
|
// Perfect for parsing process.env or Docker Compose outputs
|
||||||
|
```
|
||||||
|
|
||||||
|
## API Reference
|
||||||
|
|
||||||
|
### Classes
|
||||||
|
|
||||||
|
- **`Domain`** - URL/domain parser with component extraction
|
||||||
|
- **`GitRepo`** - Git repository URL parser and converter
|
||||||
|
- **`Base64`** - Base64 encoder/decoder with multiple formats
|
||||||
|
|
||||||
|
### Modules
|
||||||
|
|
||||||
|
- **`create`** - Random string generation
|
||||||
|
- `createRandomString(pattern, length, options)` - Pattern-based generation
|
||||||
|
- `createCryptoRandomString()` - Cryptographically secure strings
|
||||||
|
|
||||||
|
- **`indent`** - Indentation management
|
||||||
|
- `indent(text, spaces)` - Add spaces to each line
|
||||||
|
- `indentWithPrefix(text, prefix)` - Add custom prefix to each line
|
||||||
|
- `normalize(text)` - Fix inconsistent indentation
|
||||||
|
- `addPrefix(text, prefix)` - Add prefix to first line only
|
||||||
|
|
||||||
|
- **`normalize`** - String normalization
|
||||||
|
- `standard(text)` - Apply standard normalization
|
||||||
|
- `normal(text)` - Basic normalization
|
||||||
|
|
||||||
|
- **`type`** - String type checking
|
||||||
|
- `isUtf8(text)` - Validate UTF-8 encoding
|
||||||
|
- `isBase64(text)` - Validate Base64 format
|
||||||
|
|
||||||
|
- **`base64`** - Base64 utilities
|
||||||
|
- `encode(text)` - Standard Base64 encoding
|
||||||
|
- `decode(text)` - Standard Base64 decoding
|
||||||
|
- `encodeUri(text)` - URL-safe Base64 encoding
|
||||||
|
- `decodeUri(text)` - URL-safe Base64 decoding
|
||||||
|
- `isBase64(text)` - Check if string is valid Base64
|
||||||
|
|
||||||
|
- **`docker`** - Docker utilities
|
||||||
|
- `makeEnvObject(envArray)` - Convert env array to object
|
||||||
|
|
||||||
|
## Real-World Examples
|
||||||
|
|
||||||
|
### Building a URL Shortener
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Domain, create, base64 } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
function createShortUrl(longUrl: string): string {
|
||||||
|
const domain = new Domain(longUrl);
|
||||||
|
const shortCode = create.createRandomString('Aa0', 6);
|
||||||
|
const encoded = base64.encodeUri(`${domain.hostname}${domain.pathname}`);
|
||||||
|
|
||||||
|
return `short.ly/${shortCode}`;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Processing Code Templates
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { indent, normalize } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
function generateComponent(name: string, props: string[]): string {
|
||||||
|
const propsSection = props
|
||||||
|
.map(prop => `${prop}: string;`)
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
|
const template = `
|
||||||
|
export interface ${name}Props {
|
||||||
|
${indent.indent(propsSection, 2)}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ${name}(props: ${name}Props) {
|
||||||
|
${indent.indent('// Component implementation', 2)}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
return normalize.standard(template);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Git Repository Manager
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { GitRepo } from '@push.rocks/smartstring';
|
||||||
|
|
||||||
|
class RepoManager {
|
||||||
|
repos: Map<string, GitRepo> = new Map();
|
||||||
|
|
||||||
|
addRepo(url: string): void {
|
||||||
|
const repo = new GitRepo(url);
|
||||||
|
this.repos.set(repo.repo, repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
getCloneCommand(name: string, useSSH = false): string {
|
||||||
|
const repo = this.repos.get(name);
|
||||||
|
if (!repo) throw new Error('Repository not found');
|
||||||
|
|
||||||
|
const url = useSSH ? repo.sshUrl : repo.httpsUrl;
|
||||||
|
return `git clone ${url}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Browser Support
|
||||||
|
|
||||||
|
This package is built for modern environments and includes:
|
||||||
|
- ✅ Full ES Module support
|
||||||
|
- ✅ Tree-shaking ready
|
||||||
|
- ✅ TypeScript definitions
|
||||||
|
- ✅ Browser-compatible (via bundlers)
|
||||||
|
- ✅ Node.js 14+ support
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone the repository
|
||||||
|
git clone https://code.foss.global/push.rocks/smartstring.git
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
pnpm install
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
pnpm test
|
||||||
|
|
||||||
|
# Build the project
|
||||||
|
pnpm build
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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.
|
||||||
23
test/test.base64.both.ts
Normal file
23
test/test.base64.both.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import * as smartstring from '../ts/index.js';
|
||||||
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
|
// Base64
|
||||||
|
let testBase64: smartstring.Base64;
|
||||||
|
|
||||||
|
tap.test('expect create a valid instance of Base64', async () => {
|
||||||
|
testBase64 = new smartstring.Base64('somestring', 'string');
|
||||||
|
expect(testBase64).toBeInstanceOf(smartstring.Base64);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('expect read output a file as base64 and base64uri', async () => {
|
||||||
|
expect(testBase64.base64String).not.toEqual(testBase64.base64UriString);
|
||||||
|
let testBase64_2 = new smartstring.Base64(testBase64.base64UriString, 'base64uri');
|
||||||
|
expect(testBase64_2.simpleString).toEqual(testBase64.simpleString);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should test for a valid base64 token', async () => {
|
||||||
|
const result = smartstring.base64.isBase64('dGVzdA==');
|
||||||
|
expect(result).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import * as smartstring from '../ts/index';
|
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
|
||||||
|
|
||||||
// Base64
|
|
||||||
let testBase64: smartstring.Base64;
|
|
||||||
tap.test('expect create a valid instance of Base64', async () => {
|
|
||||||
testBase64 = new smartstring.Base64('somestring', 'string');
|
|
||||||
expect(testBase64).be.instanceOf(smartstring.Base64);
|
|
||||||
});
|
|
||||||
tap.test('expect read output a file as base64 and base64uri', async () => {
|
|
||||||
expect(testBase64.base64String).not.equal(testBase64.base64UriString);
|
|
||||||
let testBase64_2 = new smartstring.Base64(testBase64.base64UriString, 'base64uri');
|
|
||||||
expect(testBase64_2.simpleString).equal(testBase64.simpleString);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
// Docker
|
// Docker
|
||||||
tap.test('expect create a Env Object', async () => {
|
tap.test('expect create a Env Object', async () => {
|
||||||
let envStringArray = ['VIRTUAL_HOST=sub.domain.tld', 'DEFAULT_HOST=some.domain.com'];
|
let envStringArray = ['VIRTUAL_HOST=sub.domain.tld', 'DEFAULT_HOST=some.domain.com'];
|
||||||
let envObject: any = smartstring.docker.makeEnvObject(envStringArray);
|
let envObject: any = smartstring.docker.makeEnvObject(envStringArray);
|
||||||
expect(envObject.VIRTUAL_HOST).to.equal('sub.domain.tld');
|
expect(envObject.VIRTUAL_HOST).toEqual('sub.domain.tld');
|
||||||
expect(envObject.DEFAULT_HOST).to.equal('some.domain.com');
|
expect(envObject.DEFAULT_HOST).toEqual('some.domain.com');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
// Domain
|
// Domain
|
||||||
let testDomain: smartstring.Domain;
|
let testDomain: smartstring.Domain;
|
||||||
let testDomain2: smartstring.Domain;
|
let testDomain2: smartstring.Domain;
|
||||||
tap.test('expect create a new Domain object', async () => {
|
tap.test('expect create a new Domain object', async () => {
|
||||||
testDomain = new smartstring.Domain('https://level3D.level2D.level1D');
|
testDomain = new smartstring.Domain('https://level3D.level2D.level1D');
|
||||||
expect(testDomain).be.instanceof(smartstring.Domain);
|
expect(testDomain).toBeInstanceOf(smartstring.Domain);
|
||||||
console.log(testDomain);
|
console.log(testDomain);
|
||||||
});
|
});
|
||||||
tap.test('expect have a .topLevel', async () => {
|
tap.test('expect have a .topLevel', async () => {
|
||||||
expect(testDomain.topLevel).equal('level1D');
|
expect(testDomain.topLevel).toEqual('level1D');
|
||||||
});
|
});
|
||||||
tap.test('expect have a .level2', async () => {
|
tap.test('expect have a .level2', async () => {
|
||||||
expect(testDomain.level2).equal('level2D');
|
expect(testDomain.level2).toEqual('level2D');
|
||||||
});
|
});
|
||||||
tap.test('expect have a .level3', async () => {
|
tap.test('expect have a .level3', async () => {
|
||||||
expect(testDomain.level3).equal('level3D');
|
expect(testDomain.level3).toEqual('level3D');
|
||||||
});
|
});
|
||||||
tap.test('expect have the correct dns zone name', async () => {
|
tap.test('expect have the correct dns zone name', async () => {
|
||||||
expect(testDomain.zoneName).equal('level2D.level1D');
|
expect(testDomain.zoneName).toEqual('level2D.level1D');
|
||||||
});
|
});
|
||||||
tap.test('expect have the correct protocol', async () => {
|
tap.test('expect have the correct protocol', async () => {
|
||||||
expect(testDomain.protocol).equal('https');
|
expect(testDomain.protocol).toEqual('https');
|
||||||
});
|
});
|
||||||
tap.test('testDomain2 expect be a basic domain', async () => {
|
tap.test('testDomain2 expect be a basic domain', async () => {
|
||||||
testDomain2 = new smartstring.Domain('bleu.de');
|
testDomain2 = new smartstring.Domain('testing.bleu.de');
|
||||||
console.log(testDomain2);
|
console.log(testDomain2);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1,26 +1,26 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
// git
|
// git
|
||||||
let testGit: smartstring.GitRepo;
|
let testGit: smartstring.GitRepo;
|
||||||
tap.test('expect create a new Git class GitRepo', async () => {
|
tap.test('expect create a new Git class GitRepo', async () => {
|
||||||
testGit = new smartstring.GitRepo('git+https://github.com/pushrocks/smartstring.git');
|
testGit = new smartstring.GitRepo('git+https://github.com/pushrocks/smartstring.git');
|
||||||
expect(testGit).be.instanceof(smartstring.GitRepo);
|
expect(testGit).toBeInstanceOf(smartstring.GitRepo);
|
||||||
});
|
});
|
||||||
tap.test('expect return a .host', async () => {
|
tap.test('expect return a .host', async () => {
|
||||||
expect(testGit.host).equal('github.com');
|
expect(testGit.host).toEqual('github.com');
|
||||||
});
|
});
|
||||||
tap.test('expect return a .user', async () => {
|
tap.test('expect return a .user', async () => {
|
||||||
expect(testGit.user).equal('pushrocks');
|
expect(testGit.user).toEqual('pushrocks');
|
||||||
});
|
});
|
||||||
tap.test('expect return a .repo', async () => {
|
tap.test('expect return a .repo', async () => {
|
||||||
expect(testGit.repo).equal('smartstring');
|
expect(testGit.repo).toEqual('smartstring');
|
||||||
});
|
});
|
||||||
tap.test('expect return a .httpsUrl', async () => {
|
tap.test('expect return a .httpsUrl', async () => {
|
||||||
expect(testGit.httpsUrl).equal('https://github.com/pushrocks/smartstring.git');
|
expect(testGit.httpsUrl).toEqual('https://github.com/pushrocks/smartstring.git');
|
||||||
});
|
});
|
||||||
tap.test('expect return a .sshUrl', async () => {
|
tap.test('expect return a .sshUrl', async () => {
|
||||||
expect(testGit.sshUrl).equal('git@github.com:pushrocks/smartstring.git');
|
expect(testGit.sshUrl).toEqual('git@github.com:pushrocks/smartstring.git');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
// indent
|
// indent
|
||||||
let testString = `
|
let testString = `
|
||||||
20
test/test.normalize.both.ts
Normal file
20
test/test.normalize.both.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
|
import * as smartstring from '../ts/index.js';
|
||||||
|
|
||||||
|
tap.test('should normalize a string', async (toolsArg) => {
|
||||||
|
const testString = `
|
||||||
|
myawesome string;
|
||||||
|
is indented with two spaces
|
||||||
|
`;
|
||||||
|
const normalizedString = smartstring.normalize.standard(testString);
|
||||||
|
console.log(normalizedString);
|
||||||
|
|
||||||
|
expect(normalizedString).toEqual(
|
||||||
|
`myawesome string;
|
||||||
|
is indented with two spaces
|
||||||
|
`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
|
||||||
|
|
||||||
import * as smartstring from '../ts/index';
|
|
||||||
|
|
||||||
tap.test('should normalize a string', async () => {
|
|
||||||
const testString = `
|
|
||||||
myawesome string;
|
|
||||||
is indented with two spaces
|
|
||||||
`;
|
|
||||||
const normalizedString = smartstring.normalize.standard(testString);
|
|
||||||
expect(normalizedString).to.equal(
|
|
||||||
`
|
|
||||||
myawesome string;
|
|
||||||
is indented with two spaces
|
|
||||||
`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
||||||
14
test/test.type.both.ts
Normal file
14
test/test.type.both.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
import * as smartstring from '../ts/index.js';
|
||||||
|
|
||||||
|
tap.test('should state valuid utf8', async () => {
|
||||||
|
expect(smartstring.type.isUtf8('hithere')).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should state wether base64 string is valid', async () => {
|
||||||
|
const base64String = smartstring.base64.encode('hi there');
|
||||||
|
expect(smartstring.type.isBase64(base64String)).toBeTrue();
|
||||||
|
expect(smartstring.type.isBase64('hi there')).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
|
||||||
import * as smartstring from '../ts';
|
|
||||||
|
|
||||||
tap.test('should state valuid utf8', async () => {
|
|
||||||
expect(smartstring.type.isUtf8('hithere')).to.be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should state wether base64 string is valid', async () => {
|
|
||||||
const base64String = smartstring.base64.encode('hi there');
|
|
||||||
expect(smartstring.type.isBase64(base64String)).to.be.true;
|
|
||||||
expect(smartstring.type.isBase64('hi there')).to.be.false;
|
|
||||||
});
|
|
||||||
|
|
||||||
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 @push.rocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smartstring',
|
||||||
|
version: '4.1.0',
|
||||||
|
description: 'A library for handling strings in smart ways, including manipulation and encoding, with TypeScript support.'
|
||||||
|
}
|
||||||
18
ts/index.ts
18
ts/index.ts
@@ -1,13 +1,11 @@
|
|||||||
import * as create from './smartstring.create';
|
import * as create from './smartstring.create.js';
|
||||||
import * as docker from './smartstring.docker';
|
import * as docker from './smartstring.docker.js';
|
||||||
import * as indent from './smartstring.indent';
|
import * as indent from './smartstring.indent.js';
|
||||||
import * as normalize from './smartstring.normalize';
|
import * as normalize from './smartstring.normalize.js';
|
||||||
import * as type from './smartstring.type';
|
import * as type from './smartstring.type.js';
|
||||||
|
|
||||||
export { create, docker, normalize, indent, type };
|
export { create, docker, normalize, indent, type };
|
||||||
|
|
||||||
export { Base64, base64 } from './smartstring.base64';
|
export { Base64, base64 } from './smartstring.base64.js';
|
||||||
export { Domain } from './smartstring.domain';
|
export { Domain } from './smartstring.domain.js';
|
||||||
export { GitRepo } from './smartstring.git';
|
export { GitRepo } from './smartstring.git.js';
|
||||||
|
|
||||||
export { Cryptr } from './smartstring.encryption';
|
|
||||||
|
|||||||
@@ -1,16 +1,95 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the type for base 64
|
* the type for base 64
|
||||||
*/
|
*/
|
||||||
export type TBase64Input = 'string' | 'base64' | 'base64uri';
|
export type TStringInputType = 'string' | 'base64' | 'base64uri';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cross-platform base64 implementation
|
||||||
|
* Works in both Node.js and browser environments
|
||||||
|
*/
|
||||||
|
const universalBase64 = {
|
||||||
|
encode: (str: string): string => {
|
||||||
|
if (typeof Buffer !== 'undefined') {
|
||||||
|
// Node.js environment
|
||||||
|
return Buffer.from(str, 'utf8').toString('base64');
|
||||||
|
} else if (typeof btoa !== 'undefined') {
|
||||||
|
// Browser environment
|
||||||
|
// Handle Unicode properly
|
||||||
|
const utf8Bytes = new TextEncoder().encode(str);
|
||||||
|
const binaryString = Array.from(utf8Bytes, byte => String.fromCharCode(byte)).join('');
|
||||||
|
return btoa(binaryString);
|
||||||
|
} else {
|
||||||
|
// Fallback pure JS implementation
|
||||||
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
|
const bytes = new TextEncoder().encode(str);
|
||||||
|
let result = '';
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
|
while (i < bytes.length) {
|
||||||
|
const a = bytes[i++];
|
||||||
|
const b = i < bytes.length ? bytes[i++] : 0;
|
||||||
|
const c = i < bytes.length ? bytes[i++] : 0;
|
||||||
|
|
||||||
|
const bitmap = (a << 16) | (b << 8) | c;
|
||||||
|
|
||||||
|
result += chars.charAt((bitmap >> 18) & 63);
|
||||||
|
result += chars.charAt((bitmap >> 12) & 63);
|
||||||
|
result += i - 2 < bytes.length ? chars.charAt((bitmap >> 6) & 63) : '=';
|
||||||
|
result += i - 1 < bytes.length ? chars.charAt(bitmap & 63) : '=';
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
decode: (str: string): string => {
|
||||||
|
// Handle base64uri by converting back to standard base64
|
||||||
|
const base64String = str
|
||||||
|
.replace(/-/g, '+')
|
||||||
|
.replace(/_/g, '/')
|
||||||
|
.padEnd(str.length + ((4 - (str.length % 4)) % 4), '=');
|
||||||
|
|
||||||
|
if (typeof Buffer !== 'undefined') {
|
||||||
|
// Node.js environment
|
||||||
|
return Buffer.from(base64String, 'base64').toString('utf8');
|
||||||
|
} else if (typeof atob !== 'undefined') {
|
||||||
|
// Browser environment
|
||||||
|
const binaryString = atob(base64String);
|
||||||
|
const bytes = new Uint8Array(binaryString.length);
|
||||||
|
for (let i = 0; i < binaryString.length; i++) {
|
||||||
|
bytes[i] = binaryString.charCodeAt(i);
|
||||||
|
}
|
||||||
|
return new TextDecoder().decode(bytes);
|
||||||
|
} else {
|
||||||
|
// Fallback pure JS implementation
|
||||||
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
|
let bytes: number[] = [];
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
|
while (i < base64String.length) {
|
||||||
|
const encoded1 = chars.indexOf(base64String.charAt(i++));
|
||||||
|
const encoded2 = chars.indexOf(base64String.charAt(i++));
|
||||||
|
const encoded3 = chars.indexOf(base64String.charAt(i++));
|
||||||
|
const encoded4 = chars.indexOf(base64String.charAt(i++));
|
||||||
|
|
||||||
|
const bitmap = (encoded1 << 18) | (encoded2 << 12) | (encoded3 << 6) | encoded4;
|
||||||
|
|
||||||
|
bytes.push((bitmap >> 16) & 255);
|
||||||
|
if (encoded3 !== 64) bytes.push((bitmap >> 8) & 255);
|
||||||
|
if (encoded4 !== 64) bytes.push(bitmap & 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TextDecoder().decode(new Uint8Array(bytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handle base64 strings
|
* handle base64 strings
|
||||||
*/
|
*/
|
||||||
export class Base64 {
|
export class Base64 {
|
||||||
private refString: string;
|
private refString: string;
|
||||||
constructor(inputStringArg, typeArg: TBase64Input) {
|
constructor(inputStringArg, typeArg: TStringInputType) {
|
||||||
switch (typeArg) {
|
switch (typeArg) {
|
||||||
case 'string': // easiest case
|
case 'string': // easiest case
|
||||||
this.refString = inputStringArg;
|
this.refString = inputStringArg;
|
||||||
@@ -50,20 +129,33 @@ export let base64 = {
|
|||||||
* encodes the string
|
* encodes the string
|
||||||
*/
|
*/
|
||||||
encode: (stringArg: string) => {
|
encode: (stringArg: string) => {
|
||||||
return plugins.jsBase64.encode(stringArg);
|
return universalBase64.encode(stringArg);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* encodes a stringArg to base64 uri style
|
* encodes a stringArg to base64 uri style
|
||||||
*/
|
*/
|
||||||
encodeUri: (stringArg: string) => {
|
encodeUri: (stringArg: string) => {
|
||||||
return plugins.jsBase64.encodeURI(stringArg);
|
return universalBase64.encode(stringArg)
|
||||||
|
.replace(/\+/g, '-')
|
||||||
|
.replace(/\//g, '_')
|
||||||
|
.replace(/=/g, '');
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* decodes a base64 encoded string
|
* decodes a base64 encoded string
|
||||||
*/
|
*/
|
||||||
decode: (stringArg: string) => {
|
decode: (stringArg: string) => {
|
||||||
return plugins.jsBase64.decode(stringArg);
|
return universalBase64.decode(stringArg);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param stringArg
|
||||||
|
* checks wether the string is base64 encoded
|
||||||
|
*/
|
||||||
|
isBase64: (stringArg: string) => {
|
||||||
|
const regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/;
|
||||||
|
return regex.test(stringArg);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,62 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cross-platform random number generator
|
||||||
|
* Uses crypto.getRandomValues in browser and Math.random as fallback
|
||||||
|
*/
|
||||||
|
const getRandomInt = (min: number, max: number): number => {
|
||||||
|
if (typeof globalThis !== 'undefined' && globalThis.crypto && globalThis.crypto.getRandomValues) {
|
||||||
|
// Browser environment with crypto API
|
||||||
|
const range = max - min;
|
||||||
|
const array = new Uint32Array(1);
|
||||||
|
globalThis.crypto.getRandomValues(array);
|
||||||
|
return min + (array[0] % range);
|
||||||
|
} else {
|
||||||
|
// Fallback to Math.random for environments without crypto
|
||||||
|
return Math.floor(Math.random() * (max - min)) + min;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom implementation of randomatic pattern-based string generator
|
||||||
|
* Pattern characters:
|
||||||
|
* A - Uppercase letter
|
||||||
|
* a - Lowercase letter
|
||||||
|
* 0 - Number (0-9)
|
||||||
|
* ! - Special character
|
||||||
|
* * - Any character (A, a, 0, or !)
|
||||||
|
*/
|
||||||
|
const customRandomatic = (pattern: string, length?: number, options?: any): string => {
|
||||||
|
const charSets = {
|
||||||
|
'A': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||||
|
'a': 'abcdefghijklmnopqrstuvwxyz',
|
||||||
|
'0': '0123456789',
|
||||||
|
'!': '!@#$%^&*()_+-=[]{}|;:,.<>?',
|
||||||
|
'*': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?'
|
||||||
|
};
|
||||||
|
|
||||||
|
// If length is provided, repeat the pattern to match length
|
||||||
|
let actualPattern = pattern;
|
||||||
|
if (length && length > pattern.length) {
|
||||||
|
actualPattern = pattern.repeat(Math.ceil(length / pattern.length)).slice(0, length);
|
||||||
|
} else if (length) {
|
||||||
|
actualPattern = pattern.slice(0, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = '';
|
||||||
|
for (const char of actualPattern) {
|
||||||
|
if (charSets[char]) {
|
||||||
|
const charSet = charSets[char];
|
||||||
|
const randomIndex = getRandomInt(0, charSet.length);
|
||||||
|
result += charSet[randomIndex];
|
||||||
|
} else {
|
||||||
|
// If not a pattern character, use it literally
|
||||||
|
result += char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a random string
|
* creates a random string
|
||||||
@@ -17,13 +75,13 @@ export const createRandomString = (
|
|||||||
lengthArg?: number,
|
lengthArg?: number,
|
||||||
optionsArg?: any
|
optionsArg?: any
|
||||||
): string => {
|
): string => {
|
||||||
return plugins.randomatic(patternArg, lengthArg, optionsArg);
|
return customRandomatic(patternArg, lengthArg, optionsArg);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a crytic string in the speicifed length
|
* creates a crytic string in the speicifed length
|
||||||
* @param lengthArg the length of the crypto string
|
* @param lengthArg the length of the crypto string
|
||||||
*/
|
*/
|
||||||
export const createCryptoRandomString = (lengthArg: number): string => {
|
export const createCryptoRandomString = (): string => {
|
||||||
return plugins.cryptoRandomString(lengthArg);
|
return plugins.isounique.uni();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* converts an erray of env strings from docker remote api to an usable object.
|
* converts an erray of env strings from docker remote api to an usable object.
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
|
||||||
|
|
||||||
export class Domain {
|
export class Domain {
|
||||||
public fullName: string;
|
public fullName: string;
|
||||||
public level1: string;
|
public level1: string;
|
||||||
@@ -14,14 +12,20 @@ export class Domain {
|
|||||||
public domainName;
|
public domainName;
|
||||||
public subDomain;
|
public subDomain;
|
||||||
public port;
|
public port;
|
||||||
public nodeParsedUrl: plugins.url.UrlWithStringQuery;
|
public nodeParsedUrl: URL;
|
||||||
constructor(domainStringArg: string) {
|
constructor(domainStringArg: string) {
|
||||||
// lets do the node standard stuff first
|
// lets do the node standard stuff first
|
||||||
this.nodeParsedUrl = plugins.url.parse(domainStringArg);
|
this.protocol = this._protocolRegex(domainStringArg);
|
||||||
|
if (!this.protocol) {
|
||||||
|
domainStringArg = `https://${domainStringArg}`;
|
||||||
|
}
|
||||||
|
this.nodeParsedUrl = new URL(domainStringArg);
|
||||||
this.port = this.nodeParsedUrl.port;
|
this.port = this.nodeParsedUrl.port;
|
||||||
|
|
||||||
// lets do the rest after
|
// lets do the rest after
|
||||||
const regexMatches = this._domainRegex(domainStringArg.replace(this.nodeParsedUrl.path, ''));
|
const regexMatches = this._domainRegex(
|
||||||
|
domainStringArg.replace(this.nodeParsedUrl.pathname, '')
|
||||||
|
);
|
||||||
this.fullName = '';
|
this.fullName = '';
|
||||||
for (let i = 1; i <= 5; i++) {
|
for (let i = 1; i <= 5; i++) {
|
||||||
if (regexMatches[i - 1]) {
|
if (regexMatches[i - 1]) {
|
||||||
@@ -36,7 +40,6 @@ export class Domain {
|
|||||||
this['level' + i.toString()] = undefined;
|
this['level' + i.toString()] = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.protocol = this._protocolRegex(domainStringArg);
|
|
||||||
this.zoneName = this.level2 + '.' + this.level1;
|
this.zoneName = this.level2 + '.' + this.level1;
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
@@ -49,7 +52,8 @@ export class Domain {
|
|||||||
|
|
||||||
/** */
|
/** */
|
||||||
private _domainRegex(stringArg: string) {
|
private _domainRegex(stringArg: string) {
|
||||||
const regexString = /([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}$/;
|
const regexString =
|
||||||
|
/([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}$/;
|
||||||
const regexMatches = regexString.exec(stringArg);
|
const regexMatches = regexString.exec(stringArg);
|
||||||
regexMatches.reverse(); //make sure we build the domain from toplevel to subdomain (reversed order)
|
regexMatches.reverse(); //make sure we build the domain from toplevel to subdomain (reversed order)
|
||||||
regexMatches.pop(); // pop the last element, which is, since we reversed the Array, the full String of matched elements
|
regexMatches.pop(); // pop the last element, which is, since we reversed the Array, the full String of matched elements
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
|
||||||
|
|
||||||
const algorithm = 'aes-256-ctr';
|
|
||||||
|
|
||||||
export class Cryptr {
|
|
||||||
private key: Buffer;
|
|
||||||
|
|
||||||
constructor(secret) {
|
|
||||||
if (!secret || typeof secret !== 'string') {
|
|
||||||
throw new Error('Cryptr: secret must be a non-0-length string');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.key = plugins.crypto.createHash('sha256').update(String(secret)).digest();
|
|
||||||
}
|
|
||||||
|
|
||||||
encrypt(value: string) {
|
|
||||||
if (value == null) {
|
|
||||||
throw new Error('value must not be null or undefined');
|
|
||||||
}
|
|
||||||
|
|
||||||
const iv = plugins.crypto.randomBytes(16);
|
|
||||||
const cipher = plugins.crypto.createCipheriv(algorithm, this.key, iv);
|
|
||||||
const encrypted = cipher.update(String(value), 'utf8', 'hex') + cipher.final('hex');
|
|
||||||
|
|
||||||
return iv.toString('hex') + encrypted;
|
|
||||||
}
|
|
||||||
|
|
||||||
decrypt(value: string) {
|
|
||||||
if (value == null) {
|
|
||||||
throw new Error('value must not be null or undefined');
|
|
||||||
}
|
|
||||||
|
|
||||||
const stringValue = String(value);
|
|
||||||
const iv = Buffer.from(stringValue.slice(0, 32), 'hex');
|
|
||||||
const encrypted = stringValue.slice(32);
|
|
||||||
|
|
||||||
const decipher = plugins.crypto.createDecipheriv(algorithm, this.key, iv);
|
|
||||||
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
/* ---------------------------------------------- *
|
/* ---------------------------------------------- *
|
||||||
* ------------------ classes ------------------- *
|
* ------------------ classes ------------------- *
|
||||||
@@ -25,7 +25,8 @@ export class GitRepo {
|
|||||||
* ------------------ helpers ------------------- *
|
* ------------------ helpers ------------------- *
|
||||||
* ---------------------------------------------- */
|
* ---------------------------------------------- */
|
||||||
const gitRegex = function (stringArg: string) {
|
const gitRegex = function (stringArg: string) {
|
||||||
const regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-\.]*)(?:\/)([a-zA-Z0-9\-\.]*)(?:\.git)/;
|
const regexString =
|
||||||
|
/([a-zA-Z0-9\-_\.]*)(?:\/|\:)([a-zA-Z0-9\-_\.]*)(?:\/)([a-zA-Z0-9\-_\.]*)(?:\.git)/;
|
||||||
let regexMatches = regexString.exec(stringArg);
|
let regexMatches = regexString.exec(stringArg);
|
||||||
return regexMatches;
|
return regexMatches;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* splits a string into an array
|
* splits a string into an array
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* replaces all occurences of something in a string
|
* replaces all occurences of something in a string
|
||||||
* @param stringArg
|
* @param stringArg
|
||||||
@@ -11,12 +9,73 @@ export const replaceAll = (stringArg: string, searchPattern: string, replacement
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* normalizes a string
|
* Custom implementation of strip-indent
|
||||||
* @param stringArg
|
* Removes the minimum indentation from all lines
|
||||||
*/
|
*/
|
||||||
export const standard = (stringArg: string): string => {
|
const stripIndent = (str: string): string => {
|
||||||
let fix1 = plugins.stripIndent(stringArg); // fix indention
|
const lines = str.split('\n');
|
||||||
let fix2 = plugins.normalizeNewline(fix1); // fix newlines
|
|
||||||
let fix3 = replaceAll(fix2, '\t/', ' '); // fix tabs
|
// Find the minimum indentation (ignoring empty lines)
|
||||||
return fix3;
|
let minIndent = Infinity;
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.trim().length > 0) {
|
||||||
|
const match = line.match(/^(\s*)/);
|
||||||
|
if (match) {
|
||||||
|
minIndent = Math.min(minIndent, match[1].length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no indentation found, return original string
|
||||||
|
if (minIndent === Infinity || minIndent === 0) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the minimum indentation from all lines
|
||||||
|
return lines.map(line => {
|
||||||
|
if (line.length >= minIndent) {
|
||||||
|
return line.slice(minIndent);
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
}).join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface INormalizeOptions {
|
||||||
|
stripLeadingTrailingEmptyLines?: boolean;
|
||||||
|
stripAllEmptyLines?: boolean;
|
||||||
|
stripIndent?: boolean;
|
||||||
|
normalizeNewline?: boolean;
|
||||||
|
replaceTabs?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes a string
|
||||||
|
* @param stringArg
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
export const standard = (stringArg: string, options?: INormalizeOptions): string => {
|
||||||
|
let result = stringArg;
|
||||||
|
|
||||||
|
if (!options || options.stripIndent) {
|
||||||
|
result = stripIndent(result); // fix indention
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options || options.normalizeNewline) {
|
||||||
|
result = result.replace(/\r\n/g, '\n'); // fix newlines
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options || options.replaceTabs) {
|
||||||
|
result = replaceAll(result, '\t/', ' '); // fix tabs
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options || options.stripLeadingTrailingEmptyLines) {
|
||||||
|
result = result.replace(/^\s*[\r\n]/gm, '').replace(/\s*[\r\n]$/gm, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options || options.stripAllEmptyLines) {
|
||||||
|
result = result.replace(/^\s*[\r\n]/gm, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,4 @@
|
|||||||
// node native
|
// @push.rocks ecosystem
|
||||||
import * as smartenv from '@pushrocks/smartenv';
|
import * as isounique from '@push.rocks/isounique';
|
||||||
const smartenvInstance = new smartenv.Smartenv();
|
|
||||||
const crypto = smartenvInstance.getSafeNodeModule('crypto');
|
|
||||||
|
|
||||||
import * as url from 'url';
|
export { isounique };
|
||||||
|
|
||||||
export { crypto, url };
|
|
||||||
|
|
||||||
// third party
|
|
||||||
const jsBase64 = require('js-base64').Base64;
|
|
||||||
|
|
||||||
const stripIndent = require('strip-indent');
|
|
||||||
const normalizeNewline = require('normalize-newline');
|
|
||||||
const randomatic = smartenvInstance.getSafeNodeModule('randomatic');
|
|
||||||
const cryptoRandomString = smartenvInstance.getSafeNodeModule('crypto-random-string');
|
|
||||||
|
|
||||||
export { jsBase64, stripIndent, normalizeNewline, randomatic, cryptoRandomString };
|
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
import * as base64 from './smartstring.base64';
|
import * as base64 from './smartstring.base64.js';
|
||||||
|
|
||||||
|
export const isUtf8 = (stringArg: string): boolean => {
|
||||||
|
// Convert string to a Uint8Array. In browsers, this will be a bit more complex
|
||||||
|
// because we need to convert the string to a binary representation first.
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
const bytes = encoder.encode(stringArg);
|
||||||
|
|
||||||
export const isUtf8 = (stringArg: string) => {
|
|
||||||
const bytes = Buffer.from(stringArg);
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (i < bytes.length) {
|
while (i < bytes.length) {
|
||||||
if (
|
if (
|
||||||
@@ -33,12 +37,14 @@ export const isUtf8 = (stringArg: string) => {
|
|||||||
0xa0 <= bytes[i + 1] &&
|
0xa0 <= bytes[i + 1] &&
|
||||||
bytes[i + 1] <= 0xbf &&
|
bytes[i + 1] <= 0xbf &&
|
||||||
0x80 <= bytes[i + 2] &&
|
0x80 <= bytes[i + 2] &&
|
||||||
bytes[i + 2] <= 0xbf) || // straight 3-byte
|
bytes[i + 2] <= 0xbf) ||
|
||||||
|
// straight 3-byte
|
||||||
(((0xe1 <= bytes[i] && bytes[i] <= 0xec) || bytes[i] === 0xee || bytes[i] === 0xef) &&
|
(((0xe1 <= bytes[i] && bytes[i] <= 0xec) || bytes[i] === 0xee || bytes[i] === 0xef) &&
|
||||||
0x80 <= bytes[i + 1] &&
|
0x80 <= bytes[i + 1] &&
|
||||||
bytes[i + 1] <= 0xbf &&
|
bytes[i + 1] <= 0xbf &&
|
||||||
0x80 <= bytes[i + 2] &&
|
0x80 <= bytes[i + 2] &&
|
||||||
bytes[i + 2] <= 0xbf) || // excluding surrogates
|
bytes[i + 2] <= 0xbf) ||
|
||||||
|
// excluding surrogates
|
||||||
(bytes[i] === 0xed &&
|
(bytes[i] === 0xed &&
|
||||||
0x80 <= bytes[i + 1] &&
|
0x80 <= bytes[i + 1] &&
|
||||||
bytes[i + 1] <= 0x9f &&
|
bytes[i + 1] <= 0x9f &&
|
||||||
@@ -57,7 +63,8 @@ export const isUtf8 = (stringArg: string) => {
|
|||||||
0x80 <= bytes[i + 2] &&
|
0x80 <= bytes[i + 2] &&
|
||||||
bytes[i + 2] <= 0xbf &&
|
bytes[i + 2] <= 0xbf &&
|
||||||
0x80 <= bytes[i + 3] &&
|
0x80 <= bytes[i + 3] &&
|
||||||
bytes[i + 3] <= 0xbf) || // planes 4-15
|
bytes[i + 3] <= 0xbf) ||
|
||||||
|
// planes 4-15
|
||||||
(0xf1 <= bytes[i] &&
|
(0xf1 <= bytes[i] &&
|
||||||
bytes[i] <= 0xf3 &&
|
bytes[i] <= 0xf3 &&
|
||||||
0x80 <= bytes[i + 1] &&
|
0x80 <= bytes[i + 1] &&
|
||||||
@@ -65,7 +72,8 @@ export const isUtf8 = (stringArg: string) => {
|
|||||||
0x80 <= bytes[i + 2] &&
|
0x80 <= bytes[i + 2] &&
|
||||||
bytes[i + 2] <= 0xbf &&
|
bytes[i + 2] <= 0xbf &&
|
||||||
0x80 <= bytes[i + 3] &&
|
0x80 <= bytes[i + 3] &&
|
||||||
bytes[i + 3] <= 0xbf) || // plane 16
|
bytes[i + 3] <= 0xbf) ||
|
||||||
|
// plane 16
|
||||||
(bytes[i] === 0xf4 &&
|
(bytes[i] === 0xf4 &&
|
||||||
0x80 <= bytes[i + 1] &&
|
0x80 <= bytes[i + 1] &&
|
||||||
bytes[i + 1] <= 0x8f &&
|
bytes[i + 1] <= 0x8f &&
|
||||||
@@ -84,6 +92,7 @@ export const isUtf8 = (stringArg: string) => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const isBase64 = (stringArg: string) => {
|
export const isBase64 = (stringArg: string) => {
|
||||||
const notBase64 = /[^A-Z0-9+\/=]/i;
|
const notBase64 = /[^A-Z0-9+\/=]/i;
|
||||||
const len = stringArg.length;
|
const len = stringArg.length;
|
||||||
|
|||||||
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"
|
||||||
|
]
|
||||||
|
}
|
||||||
17
tslint.json
17
tslint.json
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user