Compare commits
153 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 | |||
| 76cfc8bec0 | |||
| 7f3118c525 | |||
| 9d189d1b59 | |||
| 0266afca8e | |||
| bef836fc83 | |||
| 2bd1741893 | |||
| bd20512b10 | |||
| 25d0ba8036 | |||
| c517652122 | |||
| bf3e640307 | |||
| 08cb2392fa | |||
| 4e1fa4efab | |||
| 26d00bb9d3 | |||
| fd27ed1a56 | |||
| 1f31fe9dc5 | |||
| bd7888f7ce | |||
| 201812e182 | |||
| 8dfa3f8965 | |||
| 43d50b746b | |||
| a1ee8f37d6 | |||
| 8d9c75e113 | |||
| 8ff2a9d64a | |||
| 8665464416 | |||
| e773644256 | |||
| 71fd0e614c | |||
| 55a5948a51 | |||
| 979375f08d | |||
| 95d5c6ceee | |||
| c92ece79ff | |||
| 7c625c4390 | |||
| 65fc64f6aa | |||
| 8cda8c55c0 | |||
| ec0b82de00 | |||
| 5e69664f59 | |||
| f5838f6d6a | |||
| fb4a03ad37 | |||
| ceb6962a1c | |||
| ffe757d820 | |||
| 60eb4b6b6e | |||
| f73d394d35 | |||
| 212f41e00b | |||
| 59847dd287 | |||
| 7fa2fb1e74 | |||
| 355f7442ca | |||
| 88af0ab9aa | |||
| 5b5bcd804f | |||
| 8c894ea1c1 | |||
| 62336aa2cf | |||
| e9899e5451 | |||
| 235f380139 | |||
| 4a94ce3038 | |||
| 7c4c787539 | |||
| 714e3a162c | |||
| 099bf9b270 | |||
| 83279a9c19 | |||
| 55d679e5ee | |||
| 974bf90703 | |||
| 93029d1aae | |||
| 3a7740024c | |||
| a412285862 | |||
| a57bd446d0 | |||
| afe8d5bc1b | |||
| 576e81588d | |||
| 76c590b045 | |||
| bb7caa36ea | |||
| a3a51bf0ca | |||
| 1684eae1e8 | |||
| 39ce541532 | |||
| c2a4f05b33 | |||
| 3858127968 | |||
| 68d0124c24 | |||
| 16f41a7d63 | |||
| d13dfc9e76 | |||
| 942f6b37cf | |||
|
|
211c7c3308 | ||
|
|
a55d6d2221 | ||
| 98ca73d0c7 | |||
| ffedc7f601 | |||
|
|
8344fdf7b1 | ||
|
|
543dc98961 | ||
|
|
9c60105685 | ||
|
|
bdccf2c3a1 | ||
| 34d6df0923 | |||
| 3d3b07b7cb | |||
|
|
00004f70d6 | ||
|
|
2d263244c7 | ||
|
|
8cb1405d99 | ||
|
|
d357d6e52d | ||
|
|
c124f90a91 | ||
| 4bcf9f941e | |||
| afb204325b | |||
| cefbb6eecd | |||
| c6a1a45812 | |||
| 00a892ee82 | |||
| 0eb6d13be9 | |||
| c34f9611f9 | |||
| 820360a220 | |||
| 3893985bb2 | |||
| 33e19c54d9 | |||
| 074996433e | |||
| 6a803f1db9 | |||
| 927262d6d4 | |||
| df39887de9 | |||
| 2b52b76ac6 | |||
|
|
136a06ff68 | ||
|
|
44bb4fa9ae | ||
|
|
93d5fc3070 | ||
|
|
08cd48b7bc | ||
|
|
bb17908ef5 | ||
|
|
3b8e31c8b0 | ||
| a990c5ca32 | |||
| 2d4c480c1b |
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
|
||||
25
.gitignore
vendored
25
.gitignore
vendored
@@ -1,7 +1,20 @@
|
||||
.idea/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
docs/
|
||||
node_modules
|
||||
ts/**/*.js
|
||||
ts/**/*.js.map
|
||||
ts/typings/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
12
.travis.yml
12
.travis.yml
@@ -1,12 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '4.3.0'
|
||||
- 'stable'
|
||||
deploy:
|
||||
provider: npm
|
||||
email: npm@lossless.digital
|
||||
api_key:
|
||||
secure: oKx1gdYYBnaoUcpxn3WM4SdZdInIYaa3ZgbXLSh88K+PjbcSw3NNbYEnAtWFV1eAQQchDjOHId4D1Ne68DtJb5umahvhYoejtZzawjPaa6Uyi46VPk31wXYzZJyadiyefuwOhLLMM4i3yzYwEC2BeTpbU8Tvaj6B42DoySKNGUnSF9+K2wsFNp13mRje6PLe+fjo+9H4CEKLwf74alwvAWd/PLzv47KKdCZ4/9zX7TxevrIBNie+n6VxjqXm/dTv9k7J3dCunojehBr9X9sn1sd8mR+FexjcgfCA2dz8ViP8qZCslzZixGVuasmjpQH9OabrlOfQ6e+Hs4puv+U7s53SVa9nWntiYHloT29UKCPG6ofuDFq5Nd+1PCNvPfrh99F87IKTOw9DQ9Lx7Q//To4LrbnsC85/uHgkWHhbr/ZGax7wuX9og1rem1MSjYr7gQ1sx9edtDSQe3Yjhi22xDREL5/uCbnThmrd1P44CtAU7UG4TQvnHADFqi4Oogf/VBQvsC+aUJPSfZuoxX31yCYuNToH65j1Vblj9tYuPdHSriPj2OdxbuWh68lpgsh7K64Imb++3oKjh3fKZEzeJsByI+QytyUwO/Qu1c6whlkyv8yMyoaD0WARufU+zcG4P7j4rFlAO/CoezSd6l5HBUiXJNe7XniIi6KZjA1zkZc=
|
||||
on:
|
||||
tags: true
|
||||
repo: pushrocks/smartstring
|
||||
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
11
README.md
11
README.md
@@ -1,11 +0,0 @@
|
||||
# smartstring
|
||||
handle strings in smart ways.
|
||||
|
||||
## Status
|
||||
[](https://travis-ci.org/pushrocks/smartstring)
|
||||
[](https://david-dm.org/pushrocks/smartstring)
|
||||
[](https://www.bithound.io/github/pushrocks/smartstring/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartstring)
|
||||
|
||||
## Usage
|
||||
### Git
|
||||
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.
|
||||
7
dist/index.d.ts
vendored
7
dist/index.d.ts
vendored
@@ -1,7 +0,0 @@
|
||||
import "typings-global";
|
||||
import SmartstringDocker = require("./smartstring.docker");
|
||||
import SmartstringTypescript = require("./smartstring.typescript");
|
||||
export { Domain } from "./smartstring.domain";
|
||||
export { GitRepo } from "./smartstring.git";
|
||||
export declare let docker: typeof SmartstringDocker;
|
||||
export declare let typescript: typeof SmartstringTypescript;
|
||||
12
dist/index.js
vendored
12
dist/index.js
vendored
@@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
var SmartstringDocker = require("./smartstring.docker");
|
||||
var SmartstringTypescript = require("./smartstring.typescript");
|
||||
var smartstring_domain_1 = require("./smartstring.domain");
|
||||
exports.Domain = smartstring_domain_1.Domain;
|
||||
var smartstring_git_1 = require("./smartstring.git");
|
||||
exports.GitRepo = smartstring_git_1.GitRepo;
|
||||
exports.docker = SmartstringDocker;
|
||||
exports.typescript = SmartstringTypescript;
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUNQLENBQUMsQ0FEc0I7QUFDdkIsSUFBTyxpQkFBaUIsV0FBVyxzQkFBc0IsQ0FBQyxDQUFDO0FBQzNELElBQU8scUJBQXFCLFdBQVcsMEJBQTBCLENBQUMsQ0FBQztBQUVuRSxtQ0FBcUIsc0JBQXNCLENBQUM7QUFBcEMsNkNBQW9DO0FBQzVDLGdDQUFzQixtQkFBbUIsQ0FBQztBQUFsQyw0Q0FBa0M7QUFDL0IsY0FBTSxHQUFHLGlCQUFpQixDQUFDO0FBQzNCLGtCQUFVLEdBQUcscUJBQXFCLENBQUMiLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiXHJcbmltcG9ydCBTbWFydHN0cmluZ0RvY2tlciA9IHJlcXVpcmUoXCIuL3NtYXJ0c3RyaW5nLmRvY2tlclwiKTtcclxuaW1wb3J0IFNtYXJ0c3RyaW5nVHlwZXNjcmlwdCA9IHJlcXVpcmUoXCIuL3NtYXJ0c3RyaW5nLnR5cGVzY3JpcHRcIik7XHJcblxyXG5leHBvcnQge0RvbWFpbn0gZnJvbSBcIi4vc21hcnRzdHJpbmcuZG9tYWluXCI7XHJcbmV4cG9ydCB7R2l0UmVwb30gZnJvbSBcIi4vc21hcnRzdHJpbmcuZ2l0XCI7XHJcbmV4cG9ydCBsZXQgZG9ja2VyID0gU21hcnRzdHJpbmdEb2NrZXI7XHJcbmV4cG9ydCBsZXQgdHlwZXNjcmlwdCA9IFNtYXJ0c3RyaW5nVHlwZXNjcmlwdDsiXX0=
|
||||
7
dist/smartstring.docker.d.ts
vendored
7
dist/smartstring.docker.d.ts
vendored
@@ -1,7 +0,0 @@
|
||||
import "typings-global";
|
||||
/**
|
||||
* converts an erray of env strings from docker remote api to an usable object.
|
||||
* @param envArrayArg
|
||||
* @returns {}
|
||||
*/
|
||||
export declare let makeEnvObject: (envArrayArg: string[]) => {};
|
||||
19
dist/smartstring.docker.js
vendored
19
dist/smartstring.docker.js
vendored
@@ -1,19 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
/**
|
||||
* converts an erray of env strings from docker remote api to an usable object.
|
||||
* @param envArrayArg
|
||||
* @returns {}
|
||||
*/
|
||||
exports.makeEnvObject = function (envArrayArg) {
|
||||
var returnObject = {};
|
||||
var regexString = /(.*)=(.*)/;
|
||||
for (var envKey in envArrayArg) {
|
||||
var regexMatches = regexString.exec(envArrayArg[envKey]);
|
||||
returnObject[regexMatches[1]] = regexMatches[2];
|
||||
}
|
||||
;
|
||||
return returnObject;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBR3ZCOzs7O0dBSUc7QUFDUSxxQkFBYSxHQUFHLFVBQVMsV0FBb0I7SUFDcEQsSUFBSSxZQUFZLEdBQUcsRUFBRSxDQUFDO0lBQ3RCLElBQUksV0FBVyxHQUFHLFdBQVcsQ0FBQztJQUM5QixHQUFHLENBQUEsQ0FBQyxJQUFJLE1BQU0sSUFBSSxXQUFXLENBQUMsQ0FBQSxDQUFDO1FBQzNCLElBQUksWUFBWSxHQUFHLFdBQVcsQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7UUFDekQsWUFBWSxDQUFDLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUNwRCxDQUFDO0lBQUEsQ0FBQztJQUNGLE1BQU0sQ0FBQyxZQUFZLENBQUM7QUFDeEIsQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0c3RyaW5nLmRvY2tlci5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCJcclxuaW1wb3J0IHBsdWdpbnMgPSByZXF1aXJlKFwiLi9zbWFydHN0cmluZy5wbHVnaW5zXCIpO1xyXG5cclxuLyoqXHJcbiAqIGNvbnZlcnRzIGFuIGVycmF5IG9mIGVudiBzdHJpbmdzIGZyb20gZG9ja2VyIHJlbW90ZSBhcGkgdG8gYW4gdXNhYmxlIG9iamVjdC5cclxuICogQHBhcmFtIGVudkFycmF5QXJnXHJcbiAqIEByZXR1cm5zIHt9XHJcbiAqL1xyXG5leHBvcnQgbGV0IG1ha2VFbnZPYmplY3QgPSBmdW5jdGlvbihlbnZBcnJheUFyZzpzdHJpbmdbXSl7XHJcbiAgICBsZXQgcmV0dXJuT2JqZWN0ID0ge307XHJcbiAgICBsZXQgcmVnZXhTdHJpbmcgPSAvKC4qKT0oLiopLztcclxuICAgIGZvcihsZXQgZW52S2V5IGluIGVudkFycmF5QXJnKXtcclxuICAgICAgICBsZXQgcmVnZXhNYXRjaGVzID0gcmVnZXhTdHJpbmcuZXhlYyhlbnZBcnJheUFyZ1tlbnZLZXldKTtcclxuICAgICAgICByZXR1cm5PYmplY3RbcmVnZXhNYXRjaGVzWzFdXSA9IHJlZ2V4TWF0Y2hlc1syXTtcclxuICAgIH07XHJcbiAgICByZXR1cm4gcmV0dXJuT2JqZWN0O1xyXG59OyJdfQ==
|
||||
14
dist/smartstring.domain.d.ts
vendored
14
dist/smartstring.domain.d.ts
vendored
@@ -1,14 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare class Domain {
|
||||
fullName: string;
|
||||
level1: string;
|
||||
level2: string;
|
||||
level3: string;
|
||||
level4: string;
|
||||
level5: string;
|
||||
protocol: string;
|
||||
topLevel: string;
|
||||
domainName: any;
|
||||
subDomain: any;
|
||||
constructor(domainStringArg: string);
|
||||
}
|
||||
30
dist/smartstring.domain.js
vendored
30
dist/smartstring.domain.js
vendored
@@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
var Domain = (function () {
|
||||
function Domain(domainStringArg) {
|
||||
this.fullName = domainStringArg;
|
||||
var regexMatches = domainRegex(domainStringArg);
|
||||
this.level1 = regexMatches[0];
|
||||
this.level2 = regexMatches[1];
|
||||
this.level3 = regexMatches[2];
|
||||
this.level4 = regexMatches[3];
|
||||
this.level5 = regexMatches[4];
|
||||
// aliases
|
||||
this.topLevel = this.level1;
|
||||
this.domainName = this.level2;
|
||||
this.subDomain = this.level3;
|
||||
}
|
||||
return Domain;
|
||||
}());
|
||||
exports.Domain = Domain;
|
||||
var domainRegex = function (stringArg) {
|
||||
var 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}$/;
|
||||
var regexMatches = regexString.exec(stringArg);
|
||||
regexMatches.reverse();
|
||||
var regexMatchesFiltered = regexMatches.filter(function (stringArg) {
|
||||
return (stringArg != "");
|
||||
});
|
||||
return regexMatchesFiltered;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLmRvbWFpbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBR3ZCO0lBWUksZ0JBQVksZUFBc0I7UUFDOUIsSUFBSSxDQUFDLFFBQVEsR0FBRyxlQUFlLENBQUM7UUFDaEMsSUFBSSxZQUFZLEdBQUcsV0FBVyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1FBQ2hELElBQUksQ0FBQyxNQUFNLEdBQUcsWUFBWSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzlCLElBQUksQ0FBQyxNQUFNLEdBQUcsWUFBWSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzlCLElBQUksQ0FBQyxNQUFNLEdBQUcsWUFBWSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzlCLElBQUksQ0FBQyxNQUFNLEdBQUcsWUFBWSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzlCLElBQUksQ0FBQyxNQUFNLEdBQUcsWUFBWSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzlCLFVBQVU7UUFDVixJQUFJLENBQUMsUUFBUSxHQUFHLElBQUksQ0FBQyxNQUFNLENBQUM7UUFDNUIsSUFBSSxDQUFDLFVBQVUsR0FBRyxJQUFJLENBQUMsTUFBTSxDQUFDO1FBQzlCLElBQUksQ0FBQyxTQUFTLEdBQUcsSUFBSSxDQUFDLE1BQU0sQ0FBQztJQUNqQyxDQUFDO0lBQ0wsYUFBQztBQUFELENBekJBLEFBeUJDLElBQUE7QUF6QlksY0FBTSxTQXlCbEIsQ0FBQTtBQUdELElBQUksV0FBVyxHQUFHLFVBQVMsU0FBZ0I7SUFDdkMsSUFBSSxXQUFXLEdBQUcsNEdBQTRHLENBQUM7SUFDL0gsSUFBSSxZQUFZLEdBQUcsV0FBVyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQztJQUMvQyxZQUFZLENBQUMsT0FBTyxFQUFFLENBQUM7SUFDdkIsSUFBSSxvQkFBb0IsR0FBRyxZQUFZLENBQUMsTUFBTSxDQUFDLFVBQVMsU0FBZ0I7UUFDcEUsTUFBTSxDQUFBLENBQUMsU0FBUyxJQUFJLEVBQUUsQ0FBQyxDQUFDO0lBQzVCLENBQUMsQ0FBQyxDQUFDO0lBQ0gsTUFBTSxDQUFDLG9CQUFvQixDQUFDO0FBQ2hDLENBQUMsQ0FBQyIsImZpbGUiOiJzbWFydHN0cmluZy5kb21haW4uanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiXHJcbmltcG9ydCBwbHVnaW5zID0gcmVxdWlyZShcIi4vc21hcnRzdHJpbmcucGx1Z2luc1wiKTtcclxuXHJcbmV4cG9ydCBjbGFzcyBEb21haW4ge1xyXG4gICAgZnVsbE5hbWU6c3RyaW5nO1xyXG4gICAgbGV2ZWwxOnN0cmluZztcclxuICAgIGxldmVsMjpzdHJpbmc7XHJcbiAgICBsZXZlbDM6c3RyaW5nO1xyXG4gICAgbGV2ZWw0OnN0cmluZztcclxuICAgIGxldmVsNTpzdHJpbmc7XHJcbiAgICBwcm90b2NvbDpzdHJpbmc7XHJcbiAgICAvL2FsaWFzZXNcclxuICAgIHRvcExldmVsOnN0cmluZztcclxuICAgIGRvbWFpbk5hbWU7XHJcbiAgICBzdWJEb21haW47XHJcbiAgICBjb25zdHJ1Y3Rvcihkb21haW5TdHJpbmdBcmc6c3RyaW5nKXtcclxuICAgICAgICB0aGlzLmZ1bGxOYW1lID0gZG9tYWluU3RyaW5nQXJnO1xyXG4gICAgICAgIGxldCByZWdleE1hdGNoZXMgPSBkb21haW5SZWdleChkb21haW5TdHJpbmdBcmcpO1xyXG4gICAgICAgIHRoaXMubGV2ZWwxID0gcmVnZXhNYXRjaGVzWzBdO1xyXG4gICAgICAgIHRoaXMubGV2ZWwyID0gcmVnZXhNYXRjaGVzWzFdO1xyXG4gICAgICAgIHRoaXMubGV2ZWwzID0gcmVnZXhNYXRjaGVzWzJdO1xyXG4gICAgICAgIHRoaXMubGV2ZWw0ID0gcmVnZXhNYXRjaGVzWzNdO1xyXG4gICAgICAgIHRoaXMubGV2ZWw1ID0gcmVnZXhNYXRjaGVzWzRdO1xyXG4gICAgICAgIC8vIGFsaWFzZXNcclxuICAgICAgICB0aGlzLnRvcExldmVsID0gdGhpcy5sZXZlbDE7XHJcbiAgICAgICAgdGhpcy5kb21haW5OYW1lID0gdGhpcy5sZXZlbDI7XHJcbiAgICAgICAgdGhpcy5zdWJEb21haW4gPSB0aGlzLmxldmVsMztcclxuICAgIH1cclxufVxyXG5cclxuXHJcbmxldCBkb21haW5SZWdleCA9IGZ1bmN0aW9uKHN0cmluZ0FyZzpzdHJpbmcpe1xyXG4gICAgbGV0IHJlZ2V4U3RyaW5nID0gLyhbYS16QS1aMC05XSopXFwuezAsMX0oW2EtekEtWjAtOV0qKVxcLnswLDF9KFthLXpBLVowLTldKilcXC57MCwxfShbYS16QS1aMC05XSopXFwuezAsMX0oW2EtekEtWjAtOV0qKVxcLnswLDF9JC87XHJcbiAgICBsZXQgcmVnZXhNYXRjaGVzID0gcmVnZXhTdHJpbmcuZXhlYyhzdHJpbmdBcmcpO1xyXG4gICAgcmVnZXhNYXRjaGVzLnJldmVyc2UoKTtcclxuICAgIGxldCByZWdleE1hdGNoZXNGaWx0ZXJlZCA9IHJlZ2V4TWF0Y2hlcy5maWx0ZXIoZnVuY3Rpb24oc3RyaW5nQXJnOnN0cmluZyl7XHJcbiAgICAgICAgcmV0dXJuKHN0cmluZ0FyZyAhPSBcIlwiKTtcclxuICAgIH0pO1xyXG4gICAgcmV0dXJuIHJlZ2V4TWF0Y2hlc0ZpbHRlcmVkO1xyXG59OyJdfQ==
|
||||
10
dist/smartstring.git.d.ts
vendored
10
dist/smartstring.git.d.ts
vendored
@@ -1,10 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare class GitRepo {
|
||||
host: string;
|
||||
user: string;
|
||||
repo: string;
|
||||
accessToken: string;
|
||||
sshUrl: string;
|
||||
httpsUrl: string;
|
||||
constructor(stringArg: string, tokenArg?: string);
|
||||
}
|
||||
51
dist/smartstring.git.js
vendored
51
dist/smartstring.git.js
vendored
File diff suppressed because one or more lines are too long
2
dist/smartstring.plugins.d.ts
vendored
2
dist/smartstring.plugins.d.ts
vendored
@@ -1,2 +0,0 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
5
dist/smartstring.plugins.js
vendored
5
dist/smartstring.plugins.js
vendored
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBRVAsQ0FBQyxDQUZzQjtBQUVULGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUMiLCJmaWxlIjoic21hcnRzdHJpbmcucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCJcclxuXHJcbmV4cG9ydCBpbXBvcnQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTsiXX0=
|
||||
2
dist/smartstring.typescript.d.ts
vendored
2
dist/smartstring.typescript.d.ts
vendored
@@ -1,2 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare let regexReferencePath: RegExp;
|
||||
5
dist/smartstring.typescript.js
vendored
5
dist/smartstring.typescript.js
vendored
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/;
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLnR5cGVzY3JpcHQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUdaLDBCQUFrQixHQUFHLDhEQUE4RCxDQUFBIiwiZmlsZSI6InNtYXJ0c3RyaW5nLnR5cGVzY3JpcHQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiXHJcbmltcG9ydCBwbHVnaW5zID0gcmVxdWlyZShcIi4vc21hcnRzdHJpbmcucGx1Z2luc1wiKTtcclxuXHJcbmV4cG9ydCBsZXQgcmVnZXhSZWZlcmVuY2VQYXRoID0gL1xcL1xcL1xcL1xccyo8cmVmZXJlbmNlXFxzK3BhdGhcXHMqPVxccypbXCJ8J10uKltcInwnXVxccypcXC8+XFxzKltcXFxcbl0/LyJdfQ==
|
||||
@@ -1,6 +1,7 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Push.Rocks
|
||||
Copyright (c) 2014 Maurice Butler
|
||||
Copyright (c) 2016 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
|
||||
39
npmextra.json
Normal file
39
npmextra.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"npmdocker": {
|
||||
"baseImage": "hosttoday/ht-docker-node:npmci",
|
||||
"command": "npmci node install stable && npmci npm install && npmci npm test",
|
||||
"dockerSock": false
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartstring",
|
||||
"description": "A library for handling strings in smart ways, including manipulation and encoding, with TypeScript support.",
|
||||
"npmPackagename": "@push.rocks/smartstring",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
62
package.json
62
package.json
@@ -1,33 +1,63 @@
|
||||
{
|
||||
"name": "smartstring",
|
||||
"version": "2.0.0",
|
||||
"description": "bundles a bunch of (regex) matching and altering methods.",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@push.rocks/smartstring",
|
||||
"version": "4.1.0",
|
||||
"private": false,
|
||||
"description": "A library for handling strings in smart ways, including manipulation and encoding, with TypeScript support.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pushrocks/smartstring.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartstring.git"
|
||||
},
|
||||
"keywords": [
|
||||
"string manipulation",
|
||||
"encode",
|
||||
"decode",
|
||||
"base64",
|
||||
"indentation",
|
||||
"normalization",
|
||||
"regex",
|
||||
"string"
|
||||
"random string",
|
||||
"cryptographic string",
|
||||
"domain parsing",
|
||||
"git repository parsing",
|
||||
"docker environment parsing"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/smartstring/issues"
|
||||
"url": "https://gitlab.com/push.rocks/smartstring/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/smartstring#readme",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartstring",
|
||||
"devDependencies": {
|
||||
"npmts": "^5.1.13",
|
||||
"should": "^8.4.0",
|
||||
"typings-test": "^1.0.1"
|
||||
"@git.zone/tsbuild": "^2.1.72",
|
||||
"@git.zone/tsrun": "^1.2.42",
|
||||
"@git.zone/tstest": "^2.3.7",
|
||||
"@types/node": "^20.11.24"
|
||||
},
|
||||
"dependencies": {
|
||||
"beautylog": "^5.0.6",
|
||||
"typings-global": "^1.0.3"
|
||||
}
|
||||
"@push.rocks/isounique": "^1.0.5"
|
||||
},
|
||||
"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.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 @@
|
||||
|
||||
379
readme.md
Normal file
379
readme.md
Normal file
@@ -0,0 +1,379 @@
|
||||
# @push.rocks/smartstring
|
||||
|
||||
🎯 **Smart string manipulation for TypeScript** - Your comprehensive toolkit for handling strings, domains, Git URLs, and encodings with elegance and precision.
|
||||
|
||||
## Why smartstring?
|
||||
|
||||
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
|
||||
- Handle Git repository URLs across different formats
|
||||
- Encode/decode Base64 for data transmission
|
||||
- Normalize indentation in code generators
|
||||
- Create cryptographically secure random strings
|
||||
- Validate string encodings
|
||||
- Parse Docker environment variables
|
||||
|
||||
**smartstring** unifies all these capabilities in a single, tree-shakeable, TypeScript-native package with zero setup overhead.
|
||||
|
||||
## Install
|
||||
|
||||
```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
|
||||
|
||||
### 🌐 Domain Parsing
|
||||
|
||||
Extract detailed information from any URL or domain string:
|
||||
|
||||
```typescript
|
||||
import { Domain } from '@push.rocks/smartstring';
|
||||
|
||||
const domain = new Domain('https://subdomain.example.com:3000/path');
|
||||
|
||||
console.log(domain.protocol); // 'https'
|
||||
console.log(domain.hostname); // 'subdomain.example.com'
|
||||
console.log(domain.port); // '3000'
|
||||
console.log(domain.pathname); // '/path'
|
||||
console.log(domain.fullUrl); // 'https://subdomain.example.com:3000/path'
|
||||
|
||||
// Domain level extraction
|
||||
console.log(domain.level1); // 'com' - TLD
|
||||
console.log(domain.level2); // 'example' - Domain
|
||||
console.log(domain.level3); // 'subdomain' - Subdomain
|
||||
console.log(domain.zoneName); // 'example.com' - Full domain without subdomain
|
||||
console.log(domain.subdomain); // 'subdomain'
|
||||
```
|
||||
|
||||
### 🔧 Git Repository URLs
|
||||
|
||||
Parse and convert Git repository URLs between SSH and HTTPS formats:
|
||||
|
||||
```typescript
|
||||
import { GitRepo } from '@push.rocks/smartstring';
|
||||
|
||||
// Parse SSH format
|
||||
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'
|
||||
|
||||
// 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
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@@ -1 +0,0 @@
|
||||
import "typings-test";
|
||||
12
test/test.docker.both.ts
Normal file
12
test/test.docker.both.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
// Docker
|
||||
tap.test('expect create a Env Object', async () => {
|
||||
let envStringArray = ['VIRTUAL_HOST=sub.domain.tld', 'DEFAULT_HOST=some.domain.com'];
|
||||
let envObject: any = smartstring.docker.makeEnvObject(envStringArray);
|
||||
expect(envObject.VIRTUAL_HOST).toEqual('sub.domain.tld');
|
||||
expect(envObject.DEFAULT_HOST).toEqual('some.domain.com');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
37
test/test.domain.both.ts
Normal file
37
test/test.domain.both.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
// Domain
|
||||
let testDomain: smartstring.Domain;
|
||||
let testDomain2: smartstring.Domain;
|
||||
tap.test('expect create a new Domain object', async () => {
|
||||
testDomain = new smartstring.Domain('https://level3D.level2D.level1D');
|
||||
expect(testDomain).toBeInstanceOf(smartstring.Domain);
|
||||
console.log(testDomain);
|
||||
});
|
||||
tap.test('expect have a .topLevel', async () => {
|
||||
expect(testDomain.topLevel).toEqual('level1D');
|
||||
});
|
||||
tap.test('expect have a .level2', async () => {
|
||||
expect(testDomain.level2).toEqual('level2D');
|
||||
});
|
||||
tap.test('expect have a .level3', async () => {
|
||||
expect(testDomain.level3).toEqual('level3D');
|
||||
});
|
||||
tap.test('expect have the correct dns zone name', async () => {
|
||||
expect(testDomain.zoneName).toEqual('level2D.level1D');
|
||||
});
|
||||
tap.test('expect have the correct protocol', async () => {
|
||||
expect(testDomain.protocol).toEqual('https');
|
||||
});
|
||||
tap.test('testDomain2 expect be a basic domain', async () => {
|
||||
testDomain2 = new smartstring.Domain('testing.bleu.de');
|
||||
console.log(testDomain2);
|
||||
});
|
||||
|
||||
tap.test('should parse complex domains', async () => {
|
||||
testDomain2 = new smartstring.Domain('https://sub1.sub2.lossless.com/some/path:5431');
|
||||
console.log(testDomain2);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
26
test/test.git.both.ts
Normal file
26
test/test.git.both.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
// git
|
||||
let testGit: smartstring.GitRepo;
|
||||
tap.test('expect create a new Git class GitRepo', async () => {
|
||||
testGit = new smartstring.GitRepo('git+https://github.com/pushrocks/smartstring.git');
|
||||
expect(testGit).toBeInstanceOf(smartstring.GitRepo);
|
||||
});
|
||||
tap.test('expect return a .host', async () => {
|
||||
expect(testGit.host).toEqual('github.com');
|
||||
});
|
||||
tap.test('expect return a .user', async () => {
|
||||
expect(testGit.user).toEqual('pushrocks');
|
||||
});
|
||||
tap.test('expect return a .repo', async () => {
|
||||
expect(testGit.repo).toEqual('smartstring');
|
||||
});
|
||||
tap.test('expect return a .httpsUrl', async () => {
|
||||
expect(testGit.httpsUrl).toEqual('https://github.com/pushrocks/smartstring.git');
|
||||
});
|
||||
tap.test('expect return a .sshUrl', async () => {
|
||||
expect(testGit.sshUrl).toEqual('git@github.com:pushrocks/smartstring.git');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
28
test/test.indent.both.ts
Normal file
28
test/test.indent.both.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
// indent
|
||||
let testString = `
|
||||
base
|
||||
expect be indented
|
||||
some more
|
||||
|
||||
base
|
||||
indented
|
||||
`;
|
||||
|
||||
// normalize
|
||||
tap.test('expect normalize a string', async () => {
|
||||
testString = smartstring.indent.normalize(testString);
|
||||
console.log(testString);
|
||||
let zoneNameArg = 'test1';
|
||||
let destinationIpArg = '111';
|
||||
});
|
||||
|
||||
// indent with prefix
|
||||
tap.test('expect indent', async () => {
|
||||
testString = smartstring.indent.indentWithPrefix(testString, '>> ');
|
||||
console.log(testString);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
73
test/test.js
73
test/test.js
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC9C,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE/B,QAAQ,CAAC,aAAa,EAAC;IACnB,QAAQ,CAAC,QAAQ,EAAC;QACd,IAAI,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;QAClF,EAAE,CAAC,uBAAuB,EAAC;YACvB,OAAO,CAAC,IAAI;iBACP,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,uBAAuB,EAAC;YACvB,OAAO,CAAC,IAAI;iBACP,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,uBAAuB,EAAC;YACvB,OAAO,CAAC,IAAI;iBACP,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,2BAA2B,EAAC;YAC3B,OAAO,CAAC,QAAQ;iBACX,MAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,yBAAyB,EAAC;YACzB,OAAO,CAAC,MAAM;iBACT,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAA;IACF,QAAQ,CAAC,SAAS,EAAC;QACf,QAAQ,CAAC,gBAAgB,EAAC;YACtB,EAAE,CAAC,4BAA4B,EAAC;gBAC5B,IAAI,cAAc,GAAG,CAAC,6BAA6B,EAAC,8BAA8B,CAAC,CAAC;gBACpF,IAAI,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;gBACjE,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;gBACtD,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;YAC3D,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAC"}
|
||||
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();
|
||||
71
test/test.ts
71
test/test.ts
@@ -1,71 +0,0 @@
|
||||
import "typings-test"
|
||||
import * as smartstring from "../dist/index";
|
||||
let should = require("should");
|
||||
|
||||
describe("smartstring",function(){
|
||||
describe(".Domain class",function(){
|
||||
let testDomain:smartstring.Domain;
|
||||
it("should create a new Domain object",function(){
|
||||
testDomain = new smartstring.Domain("level3D.level2D.level1D");
|
||||
testDomain.should.be.instanceof(smartstring.Domain);
|
||||
});
|
||||
it("should have a .topLevel",function(){
|
||||
testDomain.topLevel.should.equal("level1D");
|
||||
});
|
||||
it("should have a .level2",function(){
|
||||
testDomain.level2.should.equal("level2D");
|
||||
});
|
||||
it("should have a .level3",function(){
|
||||
testDomain.level3.should.equal("level3D");
|
||||
});
|
||||
})
|
||||
describe(".Git class",function(){
|
||||
let testGit:smartstring.GitRepo;
|
||||
it("should create a new Git class GitRepo",function(){
|
||||
testGit = new smartstring.GitRepo("git+https://github.com/pushrocks/smartstring.git");
|
||||
testGit.should.be.instanceof(smartstring.GitRepo);
|
||||
})
|
||||
it("should return a .host",function(){
|
||||
testGit.host
|
||||
.should.equal("github.com");
|
||||
});
|
||||
it("should return a .user",function(){
|
||||
testGit.user
|
||||
.should.equal("pushrocks");
|
||||
});
|
||||
it("should return a .repo",function(){
|
||||
testGit.repo
|
||||
.should.equal("smartstring");
|
||||
});
|
||||
it("should return a .httpsUrl",function(){
|
||||
testGit.httpsUrl
|
||||
.should.equal("https://github.com/pushrocks/smartstring.git");
|
||||
});
|
||||
it("should return a .sshUrl",function(){
|
||||
testGit.sshUrl
|
||||
.should.equal("git@github.com:pushrocks/smartstring.git");
|
||||
});
|
||||
})
|
||||
describe(".docker",function(){
|
||||
describe(".makeEnvObject",function(){
|
||||
it("should create a Env Object",function(){
|
||||
let envStringArray = ["VIRTUAL_HOST=sub.domain.tld","DEFAULT_HOST=some.domain.com"];
|
||||
let envObject = smartstring.docker.makeEnvObject(envStringArray);
|
||||
envObject.VIRTUAL_HOST.should.equal("sub.domain.tld");
|
||||
envObject.DEFAULT_HOST.should.equal("some.domain.com");
|
||||
})
|
||||
})
|
||||
})
|
||||
describe(".typescript",function(){
|
||||
describe(".referenceRegex",function(){
|
||||
it("should match reference paths",function(){
|
||||
smartstring.typescript.regexReferencePath.test("/// <reference path=\"\" />")
|
||||
.should.be.true();
|
||||
smartstring.typescript.regexReferencePath.test("/// <reference path='' />")
|
||||
.should.be.true();
|
||||
smartstring.typescript.regexReferencePath.test("/// <referencepath=\"\" />")
|
||||
.should.be.false();
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
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();
|
||||
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.'
|
||||
}
|
||||
17
ts/index.ts
17
ts/index.ts
@@ -1,8 +1,11 @@
|
||||
import "typings-global"
|
||||
import SmartstringDocker = require("./smartstring.docker");
|
||||
import SmartstringTypescript = require("./smartstring.typescript");
|
||||
import * as create from './smartstring.create.js';
|
||||
import * as docker from './smartstring.docker.js';
|
||||
import * as indent from './smartstring.indent.js';
|
||||
import * as normalize from './smartstring.normalize.js';
|
||||
import * as type from './smartstring.type.js';
|
||||
|
||||
export {Domain} from "./smartstring.domain";
|
||||
export {GitRepo} from "./smartstring.git";
|
||||
export let docker = SmartstringDocker;
|
||||
export let typescript = SmartstringTypescript;
|
||||
export { create, docker, normalize, indent, type };
|
||||
|
||||
export { Base64, base64 } from './smartstring.base64.js';
|
||||
export { Domain } from './smartstring.domain.js';
|
||||
export { GitRepo } from './smartstring.git.js';
|
||||
|
||||
161
ts/smartstring.base64.ts
Normal file
161
ts/smartstring.base64.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* the type for base 64
|
||||
*/
|
||||
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
|
||||
*/
|
||||
export class Base64 {
|
||||
private refString: string;
|
||||
constructor(inputStringArg, typeArg: TStringInputType) {
|
||||
switch (typeArg) {
|
||||
case 'string': // easiest case
|
||||
this.refString = inputStringArg;
|
||||
break;
|
||||
case 'base64':
|
||||
this.refString = base64.decode(inputStringArg);
|
||||
break;
|
||||
case 'base64uri':
|
||||
this.refString = base64.decode(inputStringArg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the simple string (unencoded)
|
||||
*/
|
||||
get simpleString() {
|
||||
return this.refString;
|
||||
}
|
||||
|
||||
/**
|
||||
* the base64 encoded version of the original string
|
||||
*/
|
||||
get base64String() {
|
||||
return base64.encode(this.refString);
|
||||
}
|
||||
|
||||
/**
|
||||
* the base64uri encoded version of the original string
|
||||
*/
|
||||
get base64UriString() {
|
||||
return base64.encodeUri(this.refString);
|
||||
}
|
||||
}
|
||||
|
||||
export let base64 = {
|
||||
/**
|
||||
* encodes the string
|
||||
*/
|
||||
encode: (stringArg: string) => {
|
||||
return universalBase64.encode(stringArg);
|
||||
},
|
||||
|
||||
/**
|
||||
* encodes a stringArg to base64 uri style
|
||||
*/
|
||||
encodeUri: (stringArg: string) => {
|
||||
return universalBase64.encode(stringArg)
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=/g, '');
|
||||
},
|
||||
|
||||
/**
|
||||
* decodes a base64 encoded string
|
||||
*/
|
||||
decode: (stringArg: string) => {
|
||||
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);
|
||||
},
|
||||
};
|
||||
87
ts/smartstring.create.ts
Normal file
87
ts/smartstring.create.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
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
|
||||
*
|
||||
* ```ts
|
||||
* createRandomString('AAAA')
|
||||
* //=> 'AGHR'
|
||||
* ```
|
||||
*
|
||||
* @param patternArg the pattern argument to use, Aa0!* are viable pattern descritors
|
||||
* @param lengthArg the length of the random string
|
||||
* @param optionsArg options
|
||||
*/
|
||||
export const createRandomString = (
|
||||
patternArg: string,
|
||||
lengthArg?: number,
|
||||
optionsArg?: any
|
||||
): string => {
|
||||
return customRandomatic(patternArg, lengthArg, optionsArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a crytic string in the speicifed length
|
||||
* @param lengthArg the length of the crypto string
|
||||
*/
|
||||
export const createCryptoRandomString = (): string => {
|
||||
return plugins.isounique.uni();
|
||||
};
|
||||
@@ -1,17 +1,18 @@
|
||||
import "typings-global"
|
||||
import plugins = require("./smartstring.plugins");
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/**
|
||||
* converts an erray of env strings from docker remote api to an usable object.
|
||||
* @param envArrayArg
|
||||
* @returns {}
|
||||
*/
|
||||
export let makeEnvObject = function(envArrayArg:string[]){
|
||||
let returnObject = {};
|
||||
let regexString = /(.*)=(.*)/;
|
||||
for(let envKey in envArrayArg){
|
||||
let regexMatches = regexString.exec(envArrayArg[envKey]);
|
||||
returnObject[regexMatches[1]] = regexMatches[2];
|
||||
};
|
||||
return returnObject;
|
||||
export const makeEnvObject = function (envArrayArg: string[]) {
|
||||
let returnObject = {};
|
||||
let regexString = /(.*)=(.*)/;
|
||||
if (typeof envArrayArg !== 'undefined') {
|
||||
for (let envKey in envArrayArg) {
|
||||
let regexMatches = regexString.exec(envArrayArg[envKey]);
|
||||
returnObject[regexMatches[1]] = regexMatches[2];
|
||||
}
|
||||
}
|
||||
return returnObject;
|
||||
};
|
||||
@@ -1,40 +1,85 @@
|
||||
import "typings-global"
|
||||
import plugins = require("./smartstring.plugins");
|
||||
|
||||
export class Domain {
|
||||
fullName:string;
|
||||
level1:string;
|
||||
level2:string;
|
||||
level3:string;
|
||||
level4:string;
|
||||
level5:string;
|
||||
protocol:string;
|
||||
//aliases
|
||||
topLevel:string;
|
||||
domainName;
|
||||
subDomain;
|
||||
constructor(domainStringArg:string){
|
||||
this.fullName = domainStringArg;
|
||||
let regexMatches = domainRegex(domainStringArg);
|
||||
this.level1 = regexMatches[0];
|
||||
this.level2 = regexMatches[1];
|
||||
this.level3 = regexMatches[2];
|
||||
this.level4 = regexMatches[3];
|
||||
this.level5 = regexMatches[4];
|
||||
// aliases
|
||||
this.topLevel = this.level1;
|
||||
this.domainName = this.level2;
|
||||
this.subDomain = this.level3;
|
||||
public fullName: string;
|
||||
public level1: string;
|
||||
public level2: string;
|
||||
public level3: string;
|
||||
public level4: string;
|
||||
public level5: string;
|
||||
public protocol: string;
|
||||
public zoneName: string;
|
||||
// aliases
|
||||
public topLevel: string;
|
||||
public domainName;
|
||||
public subDomain;
|
||||
public port;
|
||||
public nodeParsedUrl: URL;
|
||||
constructor(domainStringArg: string) {
|
||||
// lets do the node standard stuff first
|
||||
this.protocol = this._protocolRegex(domainStringArg);
|
||||
if (!this.protocol) {
|
||||
domainStringArg = `https://${domainStringArg}`;
|
||||
}
|
||||
}
|
||||
this.nodeParsedUrl = new URL(domainStringArg);
|
||||
this.port = this.nodeParsedUrl.port;
|
||||
|
||||
// lets do the rest after
|
||||
const regexMatches = this._domainRegex(
|
||||
domainStringArg.replace(this.nodeParsedUrl.pathname, '')
|
||||
);
|
||||
this.fullName = '';
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
if (regexMatches[i - 1]) {
|
||||
const localMatch = regexMatches[i - 1];
|
||||
this['level' + i.toString()] = localMatch;
|
||||
if (this.fullName === '') {
|
||||
this.fullName = localMatch;
|
||||
} else {
|
||||
this.fullName = localMatch + '.' + this.fullName;
|
||||
}
|
||||
} else {
|
||||
this['level' + i.toString()] = undefined;
|
||||
}
|
||||
}
|
||||
this.zoneName = this.level2 + '.' + this.level1;
|
||||
|
||||
let domainRegex = function(stringArg:string){
|
||||
let 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}$/;
|
||||
let regexMatches = regexString.exec(stringArg);
|
||||
regexMatches.reverse();
|
||||
let regexMatchesFiltered = regexMatches.filter(function(stringArg:string){
|
||||
return(stringArg != "");
|
||||
// aliases
|
||||
this.topLevel = this.level1;
|
||||
this.domainName = this.level2;
|
||||
this.subDomain = this.level3;
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
/** */
|
||||
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 regexMatches = regexString.exec(stringArg);
|
||||
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
|
||||
const regexMatchesFiltered = regexMatches.filter(function (stringArg: string) {
|
||||
return stringArg !== '';
|
||||
});
|
||||
return regexMatchesFiltered;
|
||||
};
|
||||
}
|
||||
|
||||
private _protocolRegex(stringArg: string) {
|
||||
const regexString = /^([a-zA-Z0-9]*):\/\//;
|
||||
const regexMatches = regexString.exec(stringArg);
|
||||
if (regexMatches) {
|
||||
return regexMatches[1];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private _portRegex(stringArg: string) {
|
||||
const regexString = /^([a-zA-Z0-9]*):\/\//;
|
||||
const regexMatches = regexString.exec(stringArg);
|
||||
if (regexMatches) {
|
||||
return regexMatches[1];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,57 @@
|
||||
import "typings-global"
|
||||
import plugins = require("./smartstring.plugins");
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ classes ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
export class GitRepo {
|
||||
host:string;
|
||||
user:string;
|
||||
repo:string;
|
||||
accessToken:string;
|
||||
sshUrl:string;
|
||||
httpsUrl:string;
|
||||
constructor(stringArg:string,tokenArg?:string){
|
||||
let regexMatches = gitRegex(stringArg);
|
||||
this.host = regexMatches[1];
|
||||
this.user = regexMatches[2];
|
||||
this.repo = regexMatches[3];
|
||||
this.accessToken = tokenArg;
|
||||
this.sshUrl = gitLink(this.host,this.user,this.repo,this.accessToken, "ssh");
|
||||
this.httpsUrl = gitLink(this.host,this.user,this.repo,this.accessToken, "https");
|
||||
};
|
||||
host: string;
|
||||
user: string;
|
||||
repo: string;
|
||||
accessToken: string;
|
||||
sshUrl: string;
|
||||
httpsUrl: string;
|
||||
constructor(stringArg: string, tokenArg?: string) {
|
||||
let regexMatches = gitRegex(stringArg);
|
||||
this.host = regexMatches[1];
|
||||
this.user = regexMatches[2];
|
||||
this.repo = regexMatches[3];
|
||||
this.accessToken = tokenArg;
|
||||
this.sshUrl = gitLink(this.host, this.user, this.repo, this.accessToken, 'ssh');
|
||||
this.httpsUrl = gitLink(this.host, this.user, this.repo, this.accessToken, 'https');
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ helpers ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
let gitRegex = function(stringArg:string){
|
||||
let regexString = /(?:git\+|git\@|https\:\/\/|)(?:https\:\/\/|)([^\/|\:]*)(?:\/|:)([^\/]+)*(?:\/|:)([^\.]+)/;
|
||||
let regexMatches = regexString.exec(stringArg);
|
||||
return regexMatches;
|
||||
const gitRegex = function (stringArg: string) {
|
||||
const regexString =
|
||||
/([a-zA-Z0-9\-_\.]*)(?:\/|\:)([a-zA-Z0-9\-_\.]*)(?:\/)([a-zA-Z0-9\-_\.]*)(?:\.git)/;
|
||||
let regexMatches = regexString.exec(stringArg);
|
||||
return regexMatches;
|
||||
};
|
||||
|
||||
let gitLink = function(hostArg:string, userArg:string, repoArg:string, tokenArg:string = "", linkTypeArg):string{
|
||||
let returnString;
|
||||
if (tokenArg !== ""){
|
||||
tokenArg = tokenArg + "@"
|
||||
}
|
||||
switch (linkTypeArg) {
|
||||
case "https":
|
||||
returnString = "https://" +
|
||||
tokenArg + hostArg + "/" + userArg + "/" + repoArg + ".git";
|
||||
break;
|
||||
case "ssh":
|
||||
returnString = "git@" +
|
||||
hostArg + ":" + userArg + "/" + repoArg + ".git";
|
||||
break;
|
||||
default:
|
||||
plugins.beautylog.error("Link Type " + linkTypeArg + " not known");
|
||||
break;
|
||||
}
|
||||
return returnString;
|
||||
const gitLink = function (
|
||||
hostArg: string,
|
||||
userArg: string,
|
||||
repoArg: string,
|
||||
tokenArg: string = '',
|
||||
linkTypeArg
|
||||
): string {
|
||||
let returnString;
|
||||
if (tokenArg !== '') {
|
||||
tokenArg = tokenArg + '@';
|
||||
}
|
||||
switch (linkTypeArg) {
|
||||
case 'https':
|
||||
returnString = 'https://' + tokenArg + hostArg + '/' + userArg + '/' + repoArg + '.git';
|
||||
break;
|
||||
case 'ssh':
|
||||
returnString = 'git@' + hostArg + ':' + userArg + '/' + repoArg + '.git';
|
||||
break;
|
||||
default:
|
||||
console.error('Link Type ' + linkTypeArg + ' not known');
|
||||
break;
|
||||
}
|
||||
return returnString;
|
||||
};
|
||||
92
ts/smartstring.indent.ts
Normal file
92
ts/smartstring.indent.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/**
|
||||
* splits a string into an array
|
||||
* @param stringArg
|
||||
*/
|
||||
const splitStringAtLineBreak = (stringArg: string): string[] => {
|
||||
let resultArray = stringArg.split('\n');
|
||||
return cleanStringArray(resultArray);
|
||||
};
|
||||
|
||||
/**
|
||||
* joins a string together again
|
||||
* @param stringArrayArg
|
||||
*/
|
||||
const joinStringWithLineBreaks = (stringArrayArg: string[]): string => {
|
||||
let resultString: string = '';
|
||||
for (let line of stringArrayArg) {
|
||||
resultString = resultString + line + '\n'; // add new line at end
|
||||
}
|
||||
return resultString;
|
||||
};
|
||||
|
||||
/**
|
||||
* cleans first and last line in case they are empty
|
||||
* @param stringArrayArg
|
||||
*/
|
||||
const cleanStringArray = (stringArrayArg: string[]): string[] => {
|
||||
let testRegex = /^[\s]*$/;
|
||||
if (testRegex.test(stringArrayArg[0])) {
|
||||
stringArrayArg.shift();
|
||||
}
|
||||
if (testRegex.test(stringArrayArg[stringArrayArg.length - 1])) {
|
||||
stringArrayArg.pop();
|
||||
}
|
||||
return stringArrayArg;
|
||||
};
|
||||
|
||||
/**
|
||||
* indent an array
|
||||
* @param stringArg
|
||||
* @param spaceAmount
|
||||
*/
|
||||
export const indent = (stringArg: string, spaceAmount: number): string => {
|
||||
let localStringArray = splitStringAtLineBreak(stringArg);
|
||||
for (let stringArg of localStringArray) {
|
||||
stringArg = ' '.repeat(spaceAmount) + stringArg;
|
||||
}
|
||||
let resultString = joinStringWithLineBreaks(localStringArray);
|
||||
return resultString;
|
||||
};
|
||||
|
||||
/**
|
||||
* indents a string with prefix
|
||||
* @param stringArg
|
||||
* @param prefixArg
|
||||
*/
|
||||
export const indentWithPrefix = (stringArg: string, prefixArg: string): string => {
|
||||
let resultString: string;
|
||||
let stringArray = splitStringAtLineBreak(stringArg);
|
||||
let resultArray: string[] = [];
|
||||
for (let stringItem of stringArray) {
|
||||
resultArray.push(prefixArg + stringItem);
|
||||
}
|
||||
resultString = joinStringWithLineBreaks(resultArray);
|
||||
return resultString;
|
||||
};
|
||||
|
||||
export const normalize = (stringArg: string): string => {
|
||||
let resultString: string;
|
||||
let splitStringArray: string[] = splitStringAtLineBreak(stringArg);
|
||||
let minCommonLeftOffset: number;
|
||||
|
||||
const deIndentRegex = /^(\s*)/;
|
||||
const emptyLineRegex = /^(\s*)$/;
|
||||
|
||||
for (let stringItem of splitStringArray) {
|
||||
let offsetString = deIndentRegex.exec(stringItem)[1];
|
||||
if (
|
||||
(typeof minCommonLeftOffset === 'undefined' || offsetString.length < minCommonLeftOffset) &&
|
||||
!emptyLineRegex.test(stringItem)
|
||||
) {
|
||||
minCommonLeftOffset = offsetString.length;
|
||||
}
|
||||
}
|
||||
let resultSplitStringArray = [];
|
||||
for (let stringItem of splitStringArray) {
|
||||
resultSplitStringArray.push(stringItem.substr(minCommonLeftOffset));
|
||||
}
|
||||
resultString = joinStringWithLineBreaks(resultSplitStringArray);
|
||||
return resultString;
|
||||
};
|
||||
81
ts/smartstring.normalize.ts
Normal file
81
ts/smartstring.normalize.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* replaces all occurences of something in a string
|
||||
* @param stringArg
|
||||
* @param searchPattern
|
||||
* @param replacementString
|
||||
*/
|
||||
export const replaceAll = (stringArg: string, searchPattern: string, replacementString: string) => {
|
||||
return stringArg.replace(new RegExp(searchPattern, 'g'), replacementString);
|
||||
};
|
||||
|
||||
/**
|
||||
* Custom implementation of strip-indent
|
||||
* Removes the minimum indentation from all lines
|
||||
*/
|
||||
const stripIndent = (str: string): string => {
|
||||
const lines = str.split('\n');
|
||||
|
||||
// Find the minimum indentation (ignoring empty lines)
|
||||
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,3 +1,4 @@
|
||||
import "typings-global"
|
||||
// @push.rocks ecosystem
|
||||
import * as isounique from '@push.rocks/isounique';
|
||||
|
||||
export import beautylog = require("beautylog");
|
||||
export { isounique };
|
||||
|
||||
108
ts/smartstring.type.ts
Normal file
108
ts/smartstring.type.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
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);
|
||||
|
||||
let i = 0;
|
||||
while (i < bytes.length) {
|
||||
if (
|
||||
// ASCII
|
||||
bytes[i] === 0x09 ||
|
||||
bytes[i] === 0x0a ||
|
||||
bytes[i] === 0x0d ||
|
||||
(0x20 <= bytes[i] && bytes[i] <= 0x7e)
|
||||
) {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
// non-overlong 2-byte
|
||||
0xc2 <= bytes[i] &&
|
||||
bytes[i] <= 0xdf &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf
|
||||
) {
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
// excluding overlongs
|
||||
(bytes[i] === 0xe0 &&
|
||||
0xa0 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf) ||
|
||||
// straight 3-byte
|
||||
(((0xe1 <= bytes[i] && bytes[i] <= 0xec) || bytes[i] === 0xee || bytes[i] === 0xef) &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf) ||
|
||||
// excluding surrogates
|
||||
(bytes[i] === 0xed &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0x9f &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf)
|
||||
) {
|
||||
i += 3;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
// planes 1-3
|
||||
(bytes[i] === 0xf0 &&
|
||||
0x90 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf &&
|
||||
0x80 <= bytes[i + 3] &&
|
||||
bytes[i + 3] <= 0xbf) ||
|
||||
// planes 4-15
|
||||
(0xf1 <= bytes[i] &&
|
||||
bytes[i] <= 0xf3 &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf &&
|
||||
0x80 <= bytes[i + 3] &&
|
||||
bytes[i + 3] <= 0xbf) ||
|
||||
// plane 16
|
||||
(bytes[i] === 0xf4 &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0x8f &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf &&
|
||||
0x80 <= bytes[i + 3] &&
|
||||
bytes[i + 3] <= 0xbf)
|
||||
) {
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
export const isBase64 = (stringArg: string) => {
|
||||
const notBase64 = /[^A-Z0-9+\/=]/i;
|
||||
const len = stringArg.length;
|
||||
if (!len || len % 4 !== 0 || notBase64.test(stringArg)) {
|
||||
return false;
|
||||
}
|
||||
const firstPaddingChar = stringArg.indexOf('=');
|
||||
return (
|
||||
firstPaddingChar === -1 ||
|
||||
firstPaddingChar === len - 1 ||
|
||||
(firstPaddingChar === len - 2 && stringArg[len - 1] === '=')
|
||||
);
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
import "typings-global"
|
||||
import plugins = require("./smartstring.plugins");
|
||||
|
||||
export let regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts",
|
||||
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
|
||||
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts"
|
||||
}
|
||||
}
|
||||
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