Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
9d189d1b59 | |||
0266afca8e | |||
bef836fc83 | |||
2bd1741893 | |||
bd20512b10 | |||
25d0ba8036 | |||
c517652122 | |||
bf3e640307 | |||
08cb2392fa | |||
4e1fa4efab | |||
26d00bb9d3 | |||
fd27ed1a56 | |||
1f31fe9dc5 | |||
bd7888f7ce | |||
201812e182 | |||
8dfa3f8965 | |||
43d50b746b | |||
a1ee8f37d6 | |||
8d9c75e113 | |||
8ff2a9d64a | |||
8665464416 | |||
e773644256 | |||
71fd0e614c | |||
55a5948a51 | |||
979375f08d | |||
95d5c6ceee | |||
c92ece79ff | |||
7c625c4390 |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,20 @@
|
|||||||
.yarn/
|
.nogit/
|
||||||
pages/
|
|
||||||
|
# artifacts
|
||||||
|
coverage/
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
149
.gitlab-ci.yml
149
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,127 +18,114 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
sast:
|
|
||||||
stage: security
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
|
||||||
variables:
|
|
||||||
DOCKER_DRIVER: overlay2
|
|
||||||
allow_failure: true
|
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
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
only:
|
||||||
- docker:stable-dind
|
- tags
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--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:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci node install lts
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -146,5 +133,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||||
|
version: v1.13.5
|
||||||
|
ignore: {}
|
||||||
|
patch: {}
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
70
README.md
70
README.md
@ -1,70 +0,0 @@
|
|||||||
# smartstring
|
|
||||||
|
|
||||||
handle strings in smart ways. TypeScript ready.
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartstring)
|
|
||||||
[](https://GitLab.com/pushrocks/smartstring)
|
|
||||||
[](https://github.com/pushrocks/smartstring)
|
|
||||||
[](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/smartstring)
|
|
||||||
[](https://david-dm.org/pushrocks/smartstring)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartstring/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartstring)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](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)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
@ -7,5 +7,16 @@
|
|||||||
"baseImage": "hosttoday/ht-docker-node:npmci",
|
"baseImage": "hosttoday/ht-docker-node:npmci",
|
||||||
"command": "npmci node install stable && npmci npm install && npmci npm test",
|
"command": "npmci node install stable && npmci npm install && npmci npm test",
|
||||||
"dockerSock": false
|
"dockerSock": false
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartstring",
|
||||||
|
"shortDescription": "handle strings in smart ways. TypeScript ready.",
|
||||||
|
"npmPackagename": "@pushrocks/smartstring",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
10911
package-lock.json
generated
10911
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstring",
|
"name": "@pushrocks/smartstring",
|
||||||
"version": "3.0.8",
|
"version": "3.0.22",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "handle strings in smart ways. TypeScript ready.",
|
"description": "handle strings in smart ways. TypeScript ready.",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,17 +24,36 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.4",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsrun": "^1.1.17",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.18",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^10.12.18"
|
"@types/node": "^14.14.17",
|
||||||
|
"tslint": "^6.1.3",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"crypto-random-string": "^1.0.0",
|
"@pushrocks/smartenv": "^4.0.16",
|
||||||
"js-base64": "^2.5.0",
|
"crypto-random-string": "^3.3.0",
|
||||||
|
"js-base64": "^2.5.1",
|
||||||
"normalize-newline": "^3.0.0",
|
"normalize-newline": "^3.0.0",
|
||||||
"randomatic": "^3.1.1",
|
"randomatic": "^3.1.1",
|
||||||
"strip-indent": "^2.0.0"
|
"strip-indent": "^3.0.0",
|
||||||
}
|
"url": "^0.11.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
77
readme.md
Normal file
77
readme.md
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# @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
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](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.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
@ -6,14 +6,14 @@ tap.test('should normalize a string', async () => {
|
|||||||
const testString = `
|
const testString = `
|
||||||
myawesome string;
|
myawesome string;
|
||||||
is indented with two spaces
|
is indented with two spaces
|
||||||
`
|
`;
|
||||||
const normalizedString = smartstring.normalize.standard(testString);
|
const normalizedString = smartstring.normalize.standard(testString);
|
||||||
expect(normalizedString).to.equal(
|
expect(normalizedString).to.equal(
|
||||||
`
|
`
|
||||||
myawesome string;
|
myawesome string;
|
||||||
is indented with two spaces
|
is indented with two spaces
|
||||||
`
|
`
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.start()
|
tap.start();
|
||||||
|
14
test/test.type.ts
Normal file
14
test/test.type.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
import * as smartstring from '../ts';
|
||||||
|
|
||||||
|
tap.test('should state valuid utf8', async () => {
|
||||||
|
expect(smartstring.type.isUtf8('hithere')).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should state wether base64 string is valid', async () => {
|
||||||
|
const base64String = smartstring.base64.encode('hi there');
|
||||||
|
expect(smartstring.type.isBase64(base64String)).to.be.true;
|
||||||
|
expect(smartstring.type.isBase64('hi there')).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -2,8 +2,9 @@ import * as create from './smartstring.create';
|
|||||||
import * as docker from './smartstring.docker';
|
import * as docker from './smartstring.docker';
|
||||||
import * as indent from './smartstring.indent';
|
import * as indent from './smartstring.indent';
|
||||||
import * as normalize from './smartstring.normalize';
|
import * as normalize from './smartstring.normalize';
|
||||||
|
import * as type from './smartstring.type';
|
||||||
|
|
||||||
export { create, docker, normalize, indent };
|
export { create, docker, normalize, indent, type };
|
||||||
|
|
||||||
export { Base64, base64 } from './smartstring.base64';
|
export { Base64, base64 } from './smartstring.base64';
|
||||||
export { Domain } from './smartstring.domain';
|
export { Domain } from './smartstring.domain';
|
||||||
|
@ -65,5 +65,5 @@ export let base64 = {
|
|||||||
*/
|
*/
|
||||||
decode: (stringArg: string) => {
|
decode: (stringArg: string) => {
|
||||||
return plugins.jsBase64.decode(stringArg);
|
return plugins.jsBase64.decode(stringArg);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
@ -2,12 +2,12 @@ import * as plugins from './smartstring.plugins';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a random string
|
* creates a random string
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* createRandomString('AAAA')
|
* createRandomString('AAAA')
|
||||||
* //=> 'AGHR'
|
* //=> 'AGHR'
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param patternArg the pattern argument to use, Aa0!* are viable pattern descritors
|
* @param patternArg the pattern argument to use, Aa0!* are viable pattern descritors
|
||||||
* @param lengthArg the length of the random string
|
* @param lengthArg the length of the random string
|
||||||
* @param optionsArg options
|
* @param optionsArg options
|
||||||
|
@ -5,7 +5,7 @@ import * as plugins from './smartstring.plugins';
|
|||||||
* @param envArrayArg
|
* @param envArrayArg
|
||||||
* @returns {}
|
* @returns {}
|
||||||
*/
|
*/
|
||||||
export const makeEnvObject = function(envArrayArg: string[]) {
|
export const makeEnvObject = function (envArrayArg: string[]) {
|
||||||
let returnObject = {};
|
let returnObject = {};
|
||||||
let regexString = /(.*)=(.*)/;
|
let regexString = /(.*)=(.*)/;
|
||||||
if (typeof envArrayArg !== 'undefined') {
|
if (typeof envArrayArg !== 'undefined') {
|
||||||
|
@ -1,24 +1,26 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins';
|
||||||
|
|
||||||
export class Domain {
|
export class Domain {
|
||||||
fullName: string;
|
public fullName: string;
|
||||||
level1: string;
|
public level1: string;
|
||||||
level2: string;
|
public level2: string;
|
||||||
level3: string;
|
public level3: string;
|
||||||
level4: string;
|
public level4: string;
|
||||||
level5: string;
|
public level5: string;
|
||||||
protocol: string;
|
public protocol: string;
|
||||||
zoneName: string;
|
public zoneName: string;
|
||||||
// aliases
|
// aliases
|
||||||
topLevel: string;
|
public topLevel: string;
|
||||||
domainName;
|
public domainName;
|
||||||
subDomain;
|
public subDomain;
|
||||||
|
public port;
|
||||||
|
public nodeParsedUrl: plugins.url.UrlWithStringQuery;
|
||||||
constructor(domainStringArg: string) {
|
constructor(domainStringArg: string) {
|
||||||
let regexMatches = domainRegex(domainStringArg);
|
const regexMatches = this._domainRegex(domainStringArg);
|
||||||
this.fullName = '';
|
this.fullName = '';
|
||||||
for (let i = 1; i <= 5; i++) {
|
for (let i = 1; i <= 5; i++) {
|
||||||
if (regexMatches[i - 1]) {
|
if (regexMatches[i - 1]) {
|
||||||
let localMatch = regexMatches[i - 1];
|
const localMatch = regexMatches[i - 1];
|
||||||
this['level' + i.toString()] = localMatch;
|
this['level' + i.toString()] = localMatch;
|
||||||
if (this.fullName === '') {
|
if (this.fullName === '') {
|
||||||
this.fullName = localMatch;
|
this.fullName = localMatch;
|
||||||
@ -29,33 +31,49 @@ export class Domain {
|
|||||||
this['level' + i.toString()] = undefined;
|
this['level' + i.toString()] = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.protocol = protocolRegex(domainStringArg);
|
this.protocol = this._protocolRegex(domainStringArg);
|
||||||
this.zoneName = this.level2 + '.' + this.level1;
|
this.zoneName = this.level2 + '.' + this.level1;
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
this.topLevel = this.level1;
|
this.topLevel = this.level1;
|
||||||
this.domainName = this.level2;
|
this.domainName = this.level2;
|
||||||
this.subDomain = this.level3;
|
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 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
let protocolRegex = function(stringArg: string) {
|
|
||||||
let regexString = /^([a-zA-Z0-9]*):\/\//;
|
|
||||||
let regexMatches = regexString.exec(stringArg);
|
|
||||||
if (regexMatches) {
|
|
||||||
return regexMatches[1];
|
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
@ -10,10 +10,7 @@ export class Cryptr {
|
|||||||
throw new Error('Cryptr: secret must be a non-0-length string');
|
throw new Error('Cryptr: secret must be a non-0-length string');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.key = plugins.crypto
|
this.key = plugins.crypto.createHash('sha256').update(String(secret)).digest();
|
||||||
.createHash('sha256')
|
|
||||||
.update(String(secret))
|
|
||||||
.digest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
encrypt(value: string) {
|
encrypt(value: string) {
|
||||||
|
@ -24,13 +24,13 @@ export class GitRepo {
|
|||||||
/* ---------------------------------------------- *
|
/* ---------------------------------------------- *
|
||||||
* ------------------ helpers ------------------- *
|
* ------------------ helpers ------------------- *
|
||||||
* ---------------------------------------------- */
|
* ---------------------------------------------- */
|
||||||
const gitRegex = function(stringArg: string) {
|
const gitRegex = function (stringArg: string) {
|
||||||
const regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-\.]*)(?:\/)([a-zA-Z0-9\-\.]*)(?:\.git)/;
|
const regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-\.]*)(?:\/)([a-zA-Z0-9\-\.]*)(?:\.git)/;
|
||||||
let regexMatches = regexString.exec(stringArg);
|
let regexMatches = regexString.exec(stringArg);
|
||||||
return regexMatches;
|
return regexMatches;
|
||||||
};
|
};
|
||||||
|
|
||||||
const gitLink = function(
|
const gitLink = function (
|
||||||
hostArg: string,
|
hostArg: string,
|
||||||
userArg: string,
|
userArg: string,
|
||||||
repoArg: string,
|
repoArg: string,
|
||||||
|
@ -1,15 +1,24 @@
|
|||||||
// node native
|
// node native
|
||||||
import * as crypto from 'crypto';
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
|
const smartenvInstance = new smartenv.Smartenv();
|
||||||
|
const crypto = smartenvInstance.getSafeNodeModule('crypto');
|
||||||
|
|
||||||
export {
|
import * as url from 'url';
|
||||||
crypto
|
|
||||||
}
|
export { crypto, url };
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
export let jsBase64 = require('js-base64').Base64;
|
const jsBase64 = require('js-base64').Base64;
|
||||||
|
|
||||||
export let stripIndent = require('strip-indent');
|
const stripIndent = require('strip-indent');
|
||||||
export let normalizeNewline = require('normalize-newline');
|
const normalizeNewline = require('normalize-newline');
|
||||||
export let randomatic = require('randomatic');
|
const randomatic = smartenvInstance.getSafeNodeModule('randomatic');
|
||||||
export let cryptoRandomString = require('crypto-random-string');
|
const cryptoRandomString = smartenvInstance.getSafeNodeModule('crypto-random-string');
|
||||||
|
|
||||||
|
export {
|
||||||
|
jsBase64,
|
||||||
|
stripIndent,
|
||||||
|
normalizeNewline,
|
||||||
|
randomatic,
|
||||||
|
cryptoRandomString
|
||||||
|
}
|
99
ts/smartstring.type.ts
Normal file
99
ts/smartstring.type.ts
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
import * as plugins from './smartstring.plugins';
|
||||||
|
import * as base64 from './smartstring.base64';
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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] === '=')
|
||||||
|
);
|
||||||
|
};
|
Reference in New Issue
Block a user