Compare commits
63 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
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
|
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,20 @@
|
||||
.yarn/
|
||||
pages/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
125
.gitlab-ci.yml
125
.gitlab-ci.yml
@ -1,125 +0,0 @@
|
||||
# gitzone standard
|
||||
image: 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
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
66
README.md
66
README.md
@ -1,66 +0,0 @@
|
||||
# @pushrocks/smartstring
|
||||
handle strings in smart ways. TypeScript ready.
|
||||
|
||||
## Availabililty and Links
|
||||
* [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
|
||||
[](https://gitlab.com/pushrocks/smartstring/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartstring/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartstring)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartstring)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import * as smartstring from 'smartstring';
|
||||
|
||||
// classes
|
||||
|
||||
// smartstring.Domain class
|
||||
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
|
||||
let myGitRepo = new smartstring.GitRepo('git@github.com:someorg/somerepo.git'); // takes https and git and npm repo URL versions
|
||||
myGitRepo.host; // "github.com"
|
||||
myGitRepo.user; // "someorg"
|
||||
myGitRepo.repo; // "somerepo"
|
||||
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
|
||||
let myBase64 = new smartstring.Base64('somestring', 'string'); // first arg is the string, second is string type (can be string, base64, base64uri)
|
||||
myBase64.simpleString; // 'somestring'
|
||||
myBase64.base64String; // base64 representation of 'somestring'
|
||||
myBase64.base64UriString; // base64uri representation of 'sometring'
|
||||
|
||||
// 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
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
@ -9,13 +9,31 @@
|
||||
"dockerSock": false
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartstring",
|
||||
"shortDescription": "handle strings in smart ways. TypeScript ready.",
|
||||
"npmPackagename": "@pushrocks/smartstring",
|
||||
"license": "MIT"
|
||||
"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"
|
||||
}
|
||||
}
|
1687
package-lock.json
generated
1687
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
74
package.json
74
package.json
@ -1,42 +1,70 @@
|
||||
{
|
||||
"name": "@pushrocks/smartstring",
|
||||
"version": "3.0.11",
|
||||
"name": "@push.rocks/smartstring",
|
||||
"version": "4.0.15",
|
||||
"private": false,
|
||||
"description": "handle strings in smart ways. TypeScript ready.",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"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": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://gitlab.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://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": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^12.7.12",
|
||||
"tslint": "^5.20.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@git.zone/tsbuild": "^2.1.72",
|
||||
"@git.zone/tsrun": "^1.2.42",
|
||||
"@git.zone/tstest": "^1.0.86",
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"@types/node": "^20.11.24"
|
||||
},
|
||||
"dependencies": {
|
||||
"crypto-random-string": "^3.0.1",
|
||||
"js-base64": "^2.5.1",
|
||||
"normalize-newline": "^3.0.0",
|
||||
"@push.rocks/isounique": "^1.0.5",
|
||||
"@push.rocks/smartenv": "^5.0.12",
|
||||
"@types/randomatic": "^3.1.5",
|
||||
"crypto-random-string": "^5.0.0",
|
||||
"js-base64": "^3.7.7",
|
||||
"randomatic": "^3.1.1",
|
||||
"strip-indent": "^3.0.0"
|
||||
}
|
||||
}
|
||||
"strip-indent": "^4.0.0",
|
||||
"url": "^0.11.3"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
5953
pnpm-lock.yaml
generated
Normal file
5953
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 @@
|
||||
|
151
readme.md
Normal file
151
readme.md
Normal file
@ -0,0 +1,151 @@
|
||||
# @push.rocks/smartstring
|
||||
handle strings in smart ways. TypeScript ready.
|
||||
|
||||
## Install
|
||||
To install `@push.rocks/smartstring`, use the following npm command:
|
||||
|
||||
```bash
|
||||
npm install @push.rocks/smartstring --save
|
||||
```
|
||||
|
||||
This will add it to your project's dependencies.
|
||||
|
||||
## Usage
|
||||
|
||||
The `@push.rocks/smartstring` package provides a powerful set of utilities to handle and manipulate strings in various ways, ready for TypeScript usage. Here's an exhaustive guide to using this package.
|
||||
|
||||
### Working with Domain Strings
|
||||
|
||||
The `Domain` class helps in parsing and extracting information from domain URLs.
|
||||
|
||||
```typescript
|
||||
import { Domain } from '@push.rocks/smartstring';
|
||||
|
||||
// Parse a domain URL
|
||||
const myDomain = new Domain('https://sub.example.com');
|
||||
console.log(myDomain.level1); // Output: "com"
|
||||
console.log(myDomain.level2); // Output: "example"
|
||||
console.log(myDomain.zoneName); // Output: "example.com"
|
||||
console.log(myDomain.protocol); // Output: "https"
|
||||
```
|
||||
|
||||
### Handling Git Repositories
|
||||
|
||||
The `GitRepo` class is designed for extracting information from Git repository URLs.
|
||||
|
||||
```typescript
|
||||
import { GitRepo } from '@push.rocks/smartstring';
|
||||
|
||||
// Parse a Git repository URL
|
||||
const myGitRepo = new GitRepo('git@github.com:user/repo.git');
|
||||
console.log(myGitRepo.host); // Output: "github.com"
|
||||
console.log(myGitRepo.user); // Output: "user"
|
||||
console.log(myGitRepo.repo); // Output: "repo"
|
||||
console.log(myGitRepo.sshUrl); // Output: "git@github.com:user/repo.git"
|
||||
console.log(myGitRepo.httpsUrl); // Output: "https://github.com/user/repo.git"
|
||||
```
|
||||
|
||||
### Encoding and Decoding Base64 Strings
|
||||
|
||||
`@push.rocks/smartstring` offers base64 encoding and decoding through the `Base64` class and utility functions.
|
||||
|
||||
```typescript
|
||||
import { Base64, base64 } from '@push.rocks/smartstring';
|
||||
|
||||
// Using the Base64 class
|
||||
const myBase64 = new Base64('hello world', 'string');
|
||||
console.log(myBase64.base64String); // Encoded string
|
||||
console.log(myBase64.base64UriString); // Encoded URI compatible string
|
||||
|
||||
// Using utility functions
|
||||
const encoded = base64.encode('hello world');
|
||||
const decoded = base64.decode(encoded);
|
||||
console.log(encoded); // Encoded string
|
||||
console.log(decoded); // "hello world"
|
||||
```
|
||||
|
||||
### Applying Indentation
|
||||
|
||||
SmartString allows you to easily indent strings or normalize indentation across a multi-line string.
|
||||
|
||||
```typescript
|
||||
import { indent } from '@push.rocks/smartstring';
|
||||
|
||||
// Indent a string by 4 spaces
|
||||
const indentedString = indent.indent('Some text\nAnother line', 4);
|
||||
console.log(indentedString);
|
||||
|
||||
// Indent using a prefix
|
||||
const prefixedString = indent.indentWithPrefix('Line 1\nLine 2', '> ');
|
||||
console.log(prefixedString);
|
||||
|
||||
// Normalize indentation
|
||||
const normalizedString = indent.normalize(' Some indented text\n Another line');
|
||||
console.log(normalizedString);
|
||||
```
|
||||
|
||||
### Creating Random or Encrypted Strings
|
||||
|
||||
Create random strings based on patterns or generate cryptographically strong random strings.
|
||||
|
||||
```typescript
|
||||
import { create } from '@push.rocks/smartstring';
|
||||
|
||||
// Create a random string
|
||||
const randomString = create.createRandomString('aA0', 10);
|
||||
console.log(randomString); // Example output: "a9mB8v2Dq1"
|
||||
|
||||
// Create a crypto-random string
|
||||
const cryptoString = create.createCryptoRandomString(10);
|
||||
console.log(cryptoString); // Example output: "f28Bb90aCc"
|
||||
```
|
||||
|
||||
### Normalizing Strings
|
||||
|
||||
Normalize strings by removing leading/trailing whitespace, fixing indentation, and more.
|
||||
|
||||
```typescript
|
||||
import { normalize } from '@push.rocks/smartstring';
|
||||
|
||||
// Normalize a multi-line string
|
||||
const exampleString = `
|
||||
This is an example.
|
||||
The indentation will be fixed.
|
||||
`;
|
||||
const normalized = normalize.standard(exampleString);
|
||||
console.log(normalized);
|
||||
```
|
||||
|
||||
### Working with Docker Environment Variables
|
||||
|
||||
Transform an array of Docker environment variables into an object for easy access.
|
||||
|
||||
```typescript
|
||||
import { docker } from '@push.rocks/smartstring';
|
||||
|
||||
const envVars = ['NODE_ENV=production', 'PORT=3000'];
|
||||
const envObject = docker.makeEnvObject(envVars);
|
||||
console.log(envObject.NODE_ENV); // Output: "production"
|
||||
console.log(envObject.PORT); // Output: "3000"
|
||||
```
|
||||
|
||||
This guide covers the primary features of `@push.rocks/smartstring`, making string manipulation and information extraction simple and efficient in your TypeScript projects.
|
||||
|
||||
## 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 '@push.rocks/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 { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartstring from '../ts/index.js';
|
||||
import { tap, expect } from '@push.rocks/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).to.equal('sub.domain.tld');
|
||||
expect(envObject.DEFAULT_HOST).to.equal('some.domain.com');
|
||||
expect(envObject.VIRTUAL_HOST).toEqual('sub.domain.tld');
|
||||
expect(envObject.DEFAULT_HOST).toEqual('some.domain.com');
|
||||
});
|
||||
|
||||
tap.start();
|
@ -1,31 +1,36 @@
|
||||
import * as smartstring from '../ts/index';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartstring from '../ts/index.js';
|
||||
import { tap, expect } from '@push.rocks/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).be.instanceof(smartstring.Domain);
|
||||
expect(testDomain).toBeInstanceOf(smartstring.Domain);
|
||||
console.log(testDomain);
|
||||
});
|
||||
tap.test('expect have a .topLevel', async () => {
|
||||
expect(testDomain.topLevel).equal('level1D');
|
||||
expect(testDomain.topLevel).toEqual('level1D');
|
||||
});
|
||||
tap.test('expect have a .level2', async () => {
|
||||
expect(testDomain.level2).equal('level2D');
|
||||
expect(testDomain.level2).toEqual('level2D');
|
||||
});
|
||||
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 () => {
|
||||
expect(testDomain.zoneName).equal('level2D.level1D');
|
||||
expect(testDomain.zoneName).toEqual('level2D.level1D');
|
||||
});
|
||||
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 () => {
|
||||
testDomain2 = new smartstring.Domain('bleu.de');
|
||||
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);
|
||||
});
|
||||
|
@ -1,26 +1,26 @@
|
||||
import * as smartstring from '../ts/index';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartstring from '../ts/index.js';
|
||||
import { tap, expect } from '@push.rocks/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).be.instanceof(smartstring.GitRepo);
|
||||
expect(testGit).toBeInstanceOf(smartstring.GitRepo);
|
||||
});
|
||||
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 () => {
|
||||
expect(testGit.user).equal('pushrocks');
|
||||
expect(testGit.user).toEqual('pushrocks');
|
||||
});
|
||||
tap.test('expect return a .repo', async () => {
|
||||
expect(testGit.repo).equal('smartstring');
|
||||
expect(testGit.repo).toEqual('smartstring');
|
||||
});
|
||||
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 () => {
|
||||
expect(testGit.sshUrl).equal('git@github.com:pushrocks/smartstring.git');
|
||||
expect(testGit.sshUrl).toEqual('git@github.com:pushrocks/smartstring.git');
|
||||
});
|
||||
|
||||
tap.start();
|
@ -1,5 +1,5 @@
|
||||
import * as smartstring from '../ts/index';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartstring from '../ts/index.js';
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
|
||||
// indent
|
||||
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 '@push.rocks/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 '@push.rocks/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,8 +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.start();
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartstring',
|
||||
version: '4.0.15',
|
||||
description: 'handle strings in smart ways. TypeScript ready.'
|
||||
}
|
18
ts/index.ts
18
ts/index.ts
@ -1,13 +1,11 @@
|
||||
import * as create from './smartstring.create';
|
||||
import * as docker from './smartstring.docker';
|
||||
import * as indent from './smartstring.indent';
|
||||
import * as normalize from './smartstring.normalize';
|
||||
import * as type from './smartstring.type';
|
||||
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 { create, docker, normalize, indent, type };
|
||||
|
||||
export { Base64, base64 } from './smartstring.base64';
|
||||
export { Domain } from './smartstring.domain';
|
||||
export { GitRepo } from './smartstring.git';
|
||||
|
||||
export { Cryptr } from './smartstring.encryption';
|
||||
export { Base64, base64 } from './smartstring.base64.js';
|
||||
export { Domain } from './smartstring.domain.js';
|
||||
export { GitRepo } from './smartstring.git.js';
|
||||
|
@ -1,16 +1,16 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/**
|
||||
* the type for base 64
|
||||
*/
|
||||
export type TBase64Input = 'string' | 'base64' | 'base64uri';
|
||||
export type TStringInputType = 'string' | 'base64' | 'base64uri';
|
||||
|
||||
/**
|
||||
* handle base64 strings
|
||||
*/
|
||||
export class Base64 {
|
||||
private refString: string;
|
||||
constructor(inputStringArg, typeArg: TBase64Input) {
|
||||
constructor(inputStringArg, typeArg: TStringInputType) {
|
||||
switch (typeArg) {
|
||||
case 'string': // easiest case
|
||||
this.refString = inputStringArg;
|
||||
@ -65,5 +65,15 @@ export let base64 = {
|
||||
*/
|
||||
decode: (stringArg: string) => {
|
||||
return plugins.jsBase64.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,4 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/**
|
||||
* creates a random string
|
||||
@ -24,6 +24,6 @@ export const createRandomString = (
|
||||
* creates a crytic string in the speicifed length
|
||||
* @param lengthArg the length of the crypto string
|
||||
*/
|
||||
export const createCryptoRandomString = (lengthArg: number): string => {
|
||||
return plugins.cryptoRandomString(lengthArg);
|
||||
export const createCryptoRandomString = (): string => {
|
||||
return plugins.isounique.uni();
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
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.
|
||||
* @param envArrayArg
|
||||
* @returns {}
|
||||
*/
|
||||
export const makeEnvObject = function(envArrayArg: string[]) {
|
||||
export const makeEnvObject = function (envArrayArg: string[]) {
|
||||
let returnObject = {};
|
||||
let regexString = /(.*)=(.*)/;
|
||||
if (typeof envArrayArg !== 'undefined') {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
export class Domain {
|
||||
public fullName: string;
|
||||
@ -16,7 +16,18 @@ export class Domain {
|
||||
public port;
|
||||
public nodeParsedUrl: plugins.url.UrlWithStringQuery;
|
||||
constructor(domainStringArg: string) {
|
||||
const regexMatches = this._domainRegex(domainStringArg);
|
||||
// lets do the node standard stuff first
|
||||
this.protocol = this._protocolRegex(domainStringArg);
|
||||
if (!this.protocol) {
|
||||
domainStringArg = `https://${domainStringArg}`;
|
||||
}
|
||||
this.nodeParsedUrl = plugins.url.parse(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]) {
|
||||
@ -31,27 +42,24 @@ export class Domain {
|
||||
this['level' + i.toString()] = undefined;
|
||||
}
|
||||
}
|
||||
this.protocol = this._protocolRegex(domainStringArg);
|
||||
this.zoneName = this.level2 + '.' + this.level1;
|
||||
|
||||
// aliases
|
||||
this.topLevel = this.level1;
|
||||
this.domainName = this.level2;
|
||||
this.subDomain = this.level3;
|
||||
|
||||
this.nodeParsedUrl = plugins.url.parse(domainStringArg);
|
||||
this.port = this.nodeParsedUrl.port;
|
||||
}
|
||||
|
||||
// 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 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) {
|
||||
const regexMatchesFiltered = regexMatches.filter(function (stringArg: string) {
|
||||
return stringArg !== '';
|
||||
});
|
||||
return regexMatchesFiltered;
|
||||
|
@ -1,43 +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 ------------------- *
|
||||
@ -24,13 +24,14 @@ export class GitRepo {
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ helpers ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
const gitRegex = function(stringArg: string) {
|
||||
const regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-\.]*)(?:\/)([a-zA-Z0-9\-\.]*)(?:\.git)/;
|
||||
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;
|
||||
};
|
||||
|
||||
const gitLink = function(
|
||||
const gitLink = function (
|
||||
hostArg: string,
|
||||
userArg: string,
|
||||
repoArg: string,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/**
|
||||
* splits a string into an array
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/**
|
||||
* replaces all occurences of something in a string
|
||||
@ -10,13 +10,42 @@ export const replaceAll = (stringArg: string, searchPattern: string, replacement
|
||||
return stringArg.replace(new RegExp(searchPattern, 'g'), replacementString);
|
||||
};
|
||||
|
||||
export interface INormalizeOptions {
|
||||
stripLeadingTrailingEmptyLines?: boolean;
|
||||
stripAllEmptyLines?: boolean;
|
||||
stripIndent?: boolean;
|
||||
normalizeNewline?: boolean;
|
||||
replaceTabs?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* normalizes a string
|
||||
* Normalizes a string
|
||||
* @param stringArg
|
||||
* @param options
|
||||
*/
|
||||
export const standard = (stringArg: string): string => {
|
||||
let fix1 = plugins.stripIndent(stringArg); // fix indention
|
||||
let fix2 = plugins.normalizeNewline(fix1); // fix newlines
|
||||
let fix3 = replaceAll(fix2, '\t/', ' '); // fix tabs
|
||||
return fix3;
|
||||
export const standard = (stringArg: string, options?: INormalizeOptions): string => {
|
||||
let result = stringArg;
|
||||
|
||||
if (!options || options.stripIndent) {
|
||||
result = plugins.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,13 +1,17 @@
|
||||
// node native
|
||||
import * as crypto from 'crypto';
|
||||
import * as url from 'url';
|
||||
import * as smartenv from '@push.rocks/smartenv';
|
||||
const smartenvInstance = new smartenv.Smartenv();
|
||||
import * as isounique from '@push.rocks/isounique';
|
||||
|
||||
export { crypto, url };
|
||||
export { isounique };
|
||||
|
||||
import * as url from 'url';
|
||||
export { url };
|
||||
|
||||
// third party
|
||||
export let jsBase64 = require('js-base64').Base64;
|
||||
import { Base64 as jsBase64 } from 'js-base64';
|
||||
|
||||
export let stripIndent = require('strip-indent');
|
||||
export let normalizeNewline = require('normalize-newline');
|
||||
export let randomatic = require('randomatic');
|
||||
export let cryptoRandomString = require('crypto-random-string');
|
||||
import stripIndent from 'strip-indent';
|
||||
import randomatic from 'randomatic';
|
||||
|
||||
export { jsBase64, stripIndent, randomatic };
|
||||
|
@ -1,77 +1,108 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
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);
|
||||
|
||||
export const isUtf8 = (stringArg: string) => {
|
||||
const bytes = Buffer.from(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;
|
||||
while (i < bytes.length) {
|
||||
if (
|
||||
// ASCII
|
||||
bytes[i] === 0x09 ||
|
||||
bytes[i] === 0x0a ||
|
||||
bytes[i] === 0x0d ||
|
||||
(0x20 <= bytes[i] && bytes[i] <= 0x7e)
|
||||
) {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
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] === '=')
|
||||
);
|
||||
};
|
||||
|
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