Compare commits

...

62 Commits

Author SHA1 Message Date
3f5b0ebe1e 4.0.14 2024-03-01 23:34:44 +01:00
6f2cedc1dd fix(core): update 2024-03-01 23:34:43 +01:00
2c29ae3bf0 4.0.13 2024-01-08 14:41:44 +01:00
b26b8ed4a6 4.0.12 2024-01-08 14:24:22 +01:00
0e6877d2d1 fix(core): update 2024-01-08 14:24:21 +01:00
8a0c3fe906 4.0.11 2024-01-08 14:17:10 +01:00
ae861fa271 4.0.10 2023-12-27 21:57:45 +01:00
3e78466e5f fix(core): update 2023-12-27 21:57:45 +01:00
eea19bcd89 4.0.9 2023-08-31 16:31:24 +02:00
1fc95fcf0e fix(core): update 2023-08-31 16:31:23 +02:00
14ba4465d9 4.0.8 2023-08-18 13:12:26 +02:00
707e31d517 fix(core): update 2023-08-18 13:12:25 +02:00
64d85e711a 4.0.7 2023-06-26 10:01:24 +02:00
34a5cc9862 fix(core): update 2023-06-26 10:01:23 +02:00
d43d1ba212 4.0.6 2023-06-26 09:57:32 +02:00
65e771f1ba fix(core): update 2023-06-26 09:57:32 +02:00
5825a602ed 4.0.5 2022-09-13 19:23:11 +02:00
5e961f7a5b fix(core): update 2022-09-13 19:23:11 +02:00
36bcb9265a 4.0.4 2022-09-13 19:13:04 +02:00
53bf2f3569 fix(core): update 2022-09-13 19:13:04 +02:00
523ab7ee77 4.0.3 2022-09-13 18:47:19 +02:00
d60cc5430f fix(core): update 2022-09-13 18:47:19 +02:00
c0035bb4f3 4.0.2 2022-03-24 19:57:09 +01:00
976f81420f fix(core): update 2022-03-24 19:57:09 +01:00
1be144d099 4.0.1 2022-03-18 23:15:02 +01:00
9d4b7a5292 4.0.0 2022-03-18 23:05:32 +01:00
563d6f0ac3 3.0.26 2022-03-18 22:52:38 +01:00
4da0aeb871 fix(core): update 2022-03-18 22:52:38 +01:00
931defe98a 3.0.25 2022-03-18 22:50:25 +01:00
1e6077ce34 fix(core): update 2022-03-18 22:50:24 +01:00
8b1769d65e 3.0.24 2021-01-22 18:27:51 +00:00
48878c0b38 fix(core): update 2021-01-22 18:27:50 +00:00
76cfc8bec0 3.0.23 2021-01-22 14:46:04 +00:00
7f3118c525 fix(core): update 2021-01-22 14:46:02 +00:00
9d189d1b59 3.0.22 2020-12-31 04:42:47 +00:00
0266afca8e fix(core): update 2020-12-31 04:42:46 +00:00
bef836fc83 3.0.21 2020-12-31 04:25:31 +00:00
2bd1741893 fix(core): update 2020-12-31 04:25:31 +00:00
bd20512b10 3.0.20 2020-12-31 04:11:34 +00:00
25d0ba8036 fix(core): update 2020-12-31 04:11:33 +00:00
c517652122 3.0.19 2020-12-31 03:56:41 +00:00
bf3e640307 fix(core): update 2020-12-31 03:56:40 +00:00
08cb2392fa 3.0.18 2020-01-23 17:14:58 +00:00
4e1fa4efab fix(core): update 2020-01-23 17:14:57 +00:00
26d00bb9d3 3.0.17 2019-11-24 11:44:33 +00:00
fd27ed1a56 fix(core): update 2019-11-24 11:44:32 +00:00
1f31fe9dc5 3.0.16 2019-11-24 11:44:21 +00:00
bd7888f7ce fix(core): update 2019-11-24 11:44:21 +00:00
201812e182 3.0.15 2019-11-24 11:43:32 +00:00
8dfa3f8965 fix(core): update 2019-11-24 11:43:32 +00:00
43d50b746b 3.0.14 2019-10-10 18:24:04 +02:00
a1ee8f37d6 fix(core): update 2019-10-10 18:24:03 +02:00
8d9c75e113 3.0.13 2019-10-10 18:14:08 +02:00
8ff2a9d64a fix(core): update 2019-10-10 18:14:07 +02:00
8665464416 3.0.12 2019-10-10 18:03:05 +02:00
e773644256 fix(core): update 2019-10-10 18:03:04 +02:00
71fd0e614c 3.0.11 2019-10-10 17:28:24 +02:00
55a5948a51 fix(core): update 2019-10-10 17:28:23 +02:00
979375f08d 3.0.10 2019-04-16 08:55:37 +02:00
95d5c6ceee fix(core): update 2019-04-16 08:55:37 +02:00
c92ece79ff 3.0.9 2019-04-16 08:54:27 +02:00
7c625c4390 fix(core): update 2019-04-16 08:54:27 +02:00
36 changed files with 6678 additions and 1875 deletions

View 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

View 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
View File

@ -1,4 +1,20 @@
.yarn/
pages/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,150 +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
sast:
stage: security
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script:
- npmci npm prepare
- npmci npm install
- npmci command npm run build
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD:/code"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
artifacts:
reports:
sast: gl-sast-report.json
tags:
- docker
- priv
# ====================
# 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
View 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
View 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"]
}
}
}
}
}
}
]
}

View File

@ -1,70 +0,0 @@
# smartstring
handle strings in smart ways. TypeScript ready.
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartstring)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartstring)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartstring)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartstring/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartstring/badges/master/build.svg)](https://GitLab.com/pushrocks/smartstring/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartstring/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartstring/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartstring.svg)](https://www.npmjs.com/package/smartstring)
[![Dependency Status](https://david-dm.org/pushrocks/smartstring.svg)](https://david-dm.org/pushrocks/smartstring)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartstring/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartstring/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartstring/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartstring)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## 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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

View File

@ -7,5 +7,16 @@
"baseImage": "hosttoday/ht-docker-node:npmci",
"command": "npmci node install stable && npmci npm install && npmci npm test",
"dockerSock": false
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "push.rocks",
"gitrepo": "smartstring",
"description": "handle strings in smart ways. TypeScript ready.",
"npmPackagename": "@push.rocks/smartstring",
"license": "MIT"
}
}
}

1440
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,19 @@
{
"name": "@pushrocks/smartstring",
"version": "3.0.8",
"name": "@push.rocks/smartstring",
"version": "4.0.14",
"private": false,
"description": "handle strings in smart ways. TypeScript ready.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"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": "git+https://gitlab.com/push.rocks/smartstring.git"
},
"keywords": [
"regex",
@ -20,21 +22,39 @@
"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://gitlab.com/push.rocks/smartstring#readme",
"devDependencies": {
"@gitzone/tsbuild": "^2.1.4",
"@gitzone/tsrun": "^1.1.17",
"@gitzone/tstest": "^1.0.18",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.18"
"@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": "^1.0.0",
"js-base64": "^2.5.0",
"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": "^2.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

File diff suppressed because it is too large Load Diff

75
readme.md Normal file
View File

@ -0,0 +1,75 @@
# @push.rocks/smartstring
handle strings in smart ways. TypeScript ready.
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartstring)
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartstring)
* [github.com (source mirror)](https://github.com/push.rocks/smartstring)
* [docs (typedoc)](https://push.rocks.gitlab.io/smartstring/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartstring/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartstring/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartstring)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartstring)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartstring)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartstring)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartstring)](https://lossless.cloud)
## 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
```
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)

23
test/test.base64.both.ts Normal file
View 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();

View File

@ -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();

View File

@ -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();

View File

@ -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);
});

View File

@ -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();

View File

@ -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 = `

View 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();

View File

@ -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
View 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();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartstring',
version: '4.0.14',
description: 'handle strings in smart ways. TypeScript ready.'
}

View File

@ -1,12 +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 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 };
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';

View File

@ -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);
},
};

View File

@ -1,13 +1,13 @@
import * as plugins from './smartstring.plugins';
import * as plugins from './smartstring.plugins.js';
/**
* creates a random string
*
*
* ```ts
* createRandomString('AAAA')
* //=> 'AGHR'
* //=> 'AGHR'
* ```
*
*
* @param patternArg the pattern argument to use, Aa0!* are viable pattern descritors
* @param lengthArg the length of the random string
* @param optionsArg options
@ -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();
};

View File

@ -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') {

View File

@ -1,24 +1,37 @@
import * as plugins from './smartstring.plugins';
import * as plugins from './smartstring.plugins.js';
export class Domain {
fullName: string;
level1: string;
level2: string;
level3: string;
level4: string;
level5: string;
protocol: string;
zoneName: string;
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
topLevel: string;
domainName;
subDomain;
public topLevel: string;
public domainName;
public subDomain;
public port;
public nodeParsedUrl: plugins.url.UrlWithStringQuery;
constructor(domainStringArg: string) {
let regexMatches = 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]) {
let localMatch = regexMatches[i - 1];
const localMatch = regexMatches[i - 1];
this['level' + i.toString()] = localMatch;
if (this.fullName === '') {
this.fullName = localMatch;
@ -29,7 +42,6 @@ export class Domain {
this['level' + i.toString()] = undefined;
}
}
this.protocol = protocolRegex(domainStringArg);
this.zoneName = this.level2 + '.' + this.level1;
// aliases
@ -37,25 +49,39 @@ export class Domain {
this.domainName = this.level2;
this.subDomain = this.level3;
}
}
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(); //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
let regexMatchesFiltered = regexMatches.filter(function(stringArg: string) {
return stringArg !== '';
});
return regexMatchesFiltered;
};
// helper functions
let protocolRegex = function(stringArg: string) {
let regexString = /^([a-zA-Z0-9]*):\/\//;
let regexMatches = regexString.exec(stringArg);
if (regexMatches) {
return regexMatches[1];
} else {
return undefined;
/** */
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;
}
}
}

View File

@ -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');
}
}

View File

@ -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,

View File

@ -1,4 +1,4 @@
import * as plugins from './smartstring.plugins';
import * as plugins from './smartstring.plugins.js';
/**
* splits a string into an array

View File

@ -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;
};

View File

@ -1,15 +1,17 @@
// node native
import * as crypto from 'crypto';
import * as smartenv from '@push.rocks/smartenv';
const smartenvInstance = new smartenv.Smartenv();
import * as isounique from '@push.rocks/isounique';
export {
crypto
}
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 };

108
ts/smartstring.type.ts Normal file
View 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] === '=')
);
};

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
}
}

View File

@ -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"
}