Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
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
|
131
.gitlab-ci.yml
131
.gitlab-ci.yml
@ -1,16 +1,19 @@
|
|||||||
# 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
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,102 +21,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
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# 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 typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--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:
|
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:
|
||||||
@ -121,5 +136,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -9,11 +9,12 @@
|
|||||||
"dockerSock": false
|
"dockerSock": false
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartstring",
|
"gitrepo": "smartstring",
|
||||||
"shortDescription": "handle strings in smart ways. TypeScript ready.",
|
"description": "handle strings in smart ways. TypeScript ready.",
|
||||||
"npmPackagename": "@pushrocks/smartstring",
|
"npmPackagename": "@pushrocks/smartstring",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
18997
package-lock.json
generated
18997
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
51
package.json
51
package.json
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstring",
|
"name": "@pushrocks/smartstring",
|
||||||
"version": "3.0.11",
|
"version": "4.0.0",
|
||||||
"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",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web --allowimplicitany)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,19 +25,39 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.59",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.31",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.69",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^5.0.2",
|
||||||
"@types/node": "^12.7.12",
|
"@types/node": "^17.0.21",
|
||||||
"tslint": "^5.20.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"crypto-random-string": "^3.0.1",
|
"@pushrocks/isounique": "^1.0.5",
|
||||||
"js-base64": "^2.5.1",
|
"@pushrocks/smartenv": "^5.0.0",
|
||||||
"normalize-newline": "^3.0.0",
|
"@types/randomatic": "^3.1.3",
|
||||||
|
"buffer": "^6.0.3",
|
||||||
|
"crypto-random-string": "^4.0.0",
|
||||||
|
"js-base64": "^3.7.2",
|
||||||
|
"normalize-newline": "^4.1.0",
|
||||||
"randomatic": "^3.1.1",
|
"randomatic": "^3.1.1",
|
||||||
"strip-indent": "^3.0.0"
|
"strip-indent": "^4.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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,20 @@ handle strings in smart ways. TypeScript ready.
|
|||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstring/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstring/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smartstring/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartstring/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartstring)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartstring)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
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
|
## Usage
|
||||||
|
|
||||||
@ -58,9 +65,13 @@ smartstring.indent.indent('somestringanotherstring', '>>>> '); // indents a stri
|
|||||||
smartstring.indent.normalize(' somestring anotherstring', '>>>> '); // looks for the least amount of indention and removes superflouous space
|
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.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
[](https://maintainedby.lossless.com)
|
@ -1,16 +1,16 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
// Base64
|
// Base64
|
||||||
let testBase64: smartstring.Base64;
|
let testBase64: smartstring.Base64;
|
||||||
tap.test('expect create a valid instance of Base64', async () => {
|
tap.test('expect create a valid instance of Base64', async () => {
|
||||||
testBase64 = new smartstring.Base64('somestring', 'string');
|
testBase64 = new smartstring.Base64('somestring', 'string');
|
||||||
expect(testBase64).be.instanceOf(smartstring.Base64);
|
expect(testBase64).toBeInstanceOf(smartstring.Base64);
|
||||||
});
|
});
|
||||||
tap.test('expect read output a file as base64 and base64uri', async () => {
|
tap.test('expect read output a file as base64 and base64uri', async () => {
|
||||||
expect(testBase64.base64String).not.equal(testBase64.base64UriString);
|
expect(testBase64.base64String).not.toEqual(testBase64.base64UriString);
|
||||||
let testBase64_2 = new smartstring.Base64(testBase64.base64UriString, 'base64uri');
|
let testBase64_2 = new smartstring.Base64(testBase64.base64UriString, 'base64uri');
|
||||||
expect(testBase64_2.simpleString).equal(testBase64.simpleString);
|
expect(testBase64_2.simpleString).toEqual(testBase64.simpleString);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
@ -1,12 +1,12 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
// Docker
|
// Docker
|
||||||
tap.test('expect create a Env Object', async () => {
|
tap.test('expect create a Env Object', async () => {
|
||||||
let envStringArray = ['VIRTUAL_HOST=sub.domain.tld', 'DEFAULT_HOST=some.domain.com'];
|
let envStringArray = ['VIRTUAL_HOST=sub.domain.tld', 'DEFAULT_HOST=some.domain.com'];
|
||||||
let envObject: any = smartstring.docker.makeEnvObject(envStringArray);
|
let envObject: any = smartstring.docker.makeEnvObject(envStringArray);
|
||||||
expect(envObject.VIRTUAL_HOST).to.equal('sub.domain.tld');
|
expect(envObject.VIRTUAL_HOST).toEqual('sub.domain.tld');
|
||||||
expect(envObject.DEFAULT_HOST).to.equal('some.domain.com');
|
expect(envObject.DEFAULT_HOST).toEqual('some.domain.com');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
@ -1,4 +1,4 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
// Domain
|
// Domain
|
||||||
@ -6,26 +6,31 @@ let testDomain: smartstring.Domain;
|
|||||||
let testDomain2: smartstring.Domain;
|
let testDomain2: smartstring.Domain;
|
||||||
tap.test('expect create a new Domain object', async () => {
|
tap.test('expect create a new Domain object', async () => {
|
||||||
testDomain = new smartstring.Domain('https://level3D.level2D.level1D');
|
testDomain = new smartstring.Domain('https://level3D.level2D.level1D');
|
||||||
expect(testDomain).be.instanceof(smartstring.Domain);
|
expect(testDomain).toBeInstanceOf(smartstring.Domain);
|
||||||
console.log(testDomain);
|
console.log(testDomain);
|
||||||
});
|
});
|
||||||
tap.test('expect have a .topLevel', async () => {
|
tap.test('expect have a .topLevel', async () => {
|
||||||
expect(testDomain.topLevel).equal('level1D');
|
expect(testDomain.topLevel).toEqual('level1D');
|
||||||
});
|
});
|
||||||
tap.test('expect have a .level2', async () => {
|
tap.test('expect have a .level2', async () => {
|
||||||
expect(testDomain.level2).equal('level2D');
|
expect(testDomain.level2).toEqual('level2D');
|
||||||
});
|
});
|
||||||
tap.test('expect have a .level3', async () => {
|
tap.test('expect have a .level3', async () => {
|
||||||
expect(testDomain.level3).equal('level3D');
|
expect(testDomain.level3).toEqual('level3D');
|
||||||
});
|
});
|
||||||
tap.test('expect have the correct dns zone name', async () => {
|
tap.test('expect have the correct dns zone name', async () => {
|
||||||
expect(testDomain.zoneName).equal('level2D.level1D');
|
expect(testDomain.zoneName).toEqual('level2D.level1D');
|
||||||
});
|
});
|
||||||
tap.test('expect have the correct protocol', async () => {
|
tap.test('expect have the correct protocol', async () => {
|
||||||
expect(testDomain.protocol).equal('https');
|
expect(testDomain.protocol).toEqual('https');
|
||||||
});
|
});
|
||||||
tap.test('testDomain2 expect be a basic domain', async () => {
|
tap.test('testDomain2 expect be a basic domain', async () => {
|
||||||
testDomain2 = new smartstring.Domain('bleu.de');
|
testDomain2 = new smartstring.Domain('testing.bleu.de');
|
||||||
|
console.log(testDomain2);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should parse complex domains', async () => {
|
||||||
|
testDomain2 = new smartstring.Domain('https://sub1.sub2.lossless.com/some/path:5431');
|
||||||
console.log(testDomain2);
|
console.log(testDomain2);
|
||||||
});
|
});
|
||||||
|
|
@ -1,26 +1,26 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
// git
|
// git
|
||||||
let testGit: smartstring.GitRepo;
|
let testGit: smartstring.GitRepo;
|
||||||
tap.test('expect create a new Git class GitRepo', async () => {
|
tap.test('expect create a new Git class GitRepo', async () => {
|
||||||
testGit = new smartstring.GitRepo('git+https://github.com/pushrocks/smartstring.git');
|
testGit = new smartstring.GitRepo('git+https://github.com/pushrocks/smartstring.git');
|
||||||
expect(testGit).be.instanceof(smartstring.GitRepo);
|
expect(testGit).toBeInstanceOf(smartstring.GitRepo);
|
||||||
});
|
});
|
||||||
tap.test('expect return a .host', async () => {
|
tap.test('expect return a .host', async () => {
|
||||||
expect(testGit.host).equal('github.com');
|
expect(testGit.host).toEqual('github.com');
|
||||||
});
|
});
|
||||||
tap.test('expect return a .user', async () => {
|
tap.test('expect return a .user', async () => {
|
||||||
expect(testGit.user).equal('pushrocks');
|
expect(testGit.user).toEqual('pushrocks');
|
||||||
});
|
});
|
||||||
tap.test('expect return a .repo', async () => {
|
tap.test('expect return a .repo', async () => {
|
||||||
expect(testGit.repo).equal('smartstring');
|
expect(testGit.repo).toEqual('smartstring');
|
||||||
});
|
});
|
||||||
tap.test('expect return a .httpsUrl', async () => {
|
tap.test('expect return a .httpsUrl', async () => {
|
||||||
expect(testGit.httpsUrl).equal('https://github.com/pushrocks/smartstring.git');
|
expect(testGit.httpsUrl).toEqual('https://github.com/pushrocks/smartstring.git');
|
||||||
});
|
});
|
||||||
tap.test('expect return a .sshUrl', async () => {
|
tap.test('expect return a .sshUrl', async () => {
|
||||||
expect(testGit.sshUrl).equal('git@github.com:pushrocks/smartstring.git');
|
expect(testGit.sshUrl).toEqual('git@github.com:pushrocks/smartstring.git');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
@ -1,4 +1,4 @@
|
|||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
// indent
|
// indent
|
@ -1,6 +1,6 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as smartstring from '../ts/index';
|
import * as smartstring from '../ts/index.js';
|
||||||
|
|
||||||
tap.test('should normalize a string', async () => {
|
tap.test('should normalize a string', async () => {
|
||||||
const testString = `
|
const testString = `
|
||||||
@ -8,7 +8,7 @@ tap.test('should normalize a string', async () => {
|
|||||||
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).toEqual(
|
||||||
`
|
`
|
||||||
myawesome string;
|
myawesome string;
|
||||||
is indented with two spaces
|
is indented with two spaces
|
14
test/test.type.both.ts
Normal file
14
test/test.type.both.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { tap, expect } from '@pushrocks/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();
|
|
18
ts/index.ts
18
ts/index.ts
@ -1,13 +1,11 @@
|
|||||||
import * as create from './smartstring.create';
|
import * as create from './smartstring.create.js';
|
||||||
import * as docker from './smartstring.docker';
|
import * as docker from './smartstring.docker.js';
|
||||||
import * as indent from './smartstring.indent';
|
import * as indent from './smartstring.indent.js';
|
||||||
import * as normalize from './smartstring.normalize';
|
import * as normalize from './smartstring.normalize.js';
|
||||||
import * as type from './smartstring.type';
|
import * as type from './smartstring.type.js';
|
||||||
|
|
||||||
export { create, docker, normalize, indent, type };
|
export { create, docker, normalize, indent, type };
|
||||||
|
|
||||||
export { Base64, base64 } from './smartstring.base64';
|
export { Base64, base64 } from './smartstring.base64.js';
|
||||||
export { Domain } from './smartstring.domain';
|
export { Domain } from './smartstring.domain.js';
|
||||||
export { GitRepo } from './smartstring.git';
|
export { GitRepo } from './smartstring.git.js';
|
||||||
|
|
||||||
export { Cryptr } from './smartstring.encryption';
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the type for base 64
|
* the type for base 64
|
||||||
@ -65,5 +65,5 @@ export let base64 = {
|
|||||||
*/
|
*/
|
||||||
decode: (stringArg: string) => {
|
decode: (stringArg: string) => {
|
||||||
return plugins.jsBase64.decode(stringArg);
|
return plugins.jsBase64.decode(stringArg);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a random string
|
* creates a random string
|
||||||
@ -24,6 +24,6 @@ export const createRandomString = (
|
|||||||
* creates a crytic string in the speicifed length
|
* creates a crytic string in the speicifed length
|
||||||
* @param lengthArg the length of the crypto string
|
* @param lengthArg the length of the crypto string
|
||||||
*/
|
*/
|
||||||
export const createCryptoRandomString = (lengthArg: number): string => {
|
export const createCryptoRandomString = (): string => {
|
||||||
return plugins.cryptoRandomString(lengthArg);
|
return plugins.isounique.uni();
|
||||||
};
|
};
|
||||||
|
@ -1,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.
|
* converts an erray of env strings from docker remote api to an usable object.
|
||||||
* @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,4 +1,4 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
export class Domain {
|
export class Domain {
|
||||||
public fullName: string;
|
public fullName: string;
|
||||||
@ -16,7 +16,18 @@ export class Domain {
|
|||||||
public port;
|
public port;
|
||||||
public nodeParsedUrl: plugins.url.UrlWithStringQuery;
|
public nodeParsedUrl: plugins.url.UrlWithStringQuery;
|
||||||
constructor(domainStringArg: string) {
|
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 = '';
|
this.fullName = '';
|
||||||
for (let i = 1; i <= 5; i++) {
|
for (let i = 1; i <= 5; i++) {
|
||||||
if (regexMatches[i - 1]) {
|
if (regexMatches[i - 1]) {
|
||||||
@ -31,27 +42,24 @@ export class Domain {
|
|||||||
this['level' + i.toString()] = undefined;
|
this['level' + i.toString()] = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.protocol = this._protocolRegex(domainStringArg);
|
|
||||||
this.zoneName = this.level2 + '.' + this.level1;
|
this.zoneName = this.level2 + '.' + this.level1;
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
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
|
// helper functions
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
private _domainRegex(stringArg: string) {
|
private _domainRegex(stringArg: string) {
|
||||||
const regexString = /([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}$/;
|
const regexString =
|
||||||
|
/([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}$/;
|
||||||
const regexMatches = regexString.exec(stringArg);
|
const regexMatches = regexString.exec(stringArg);
|
||||||
regexMatches.reverse(); //make sure we build the domain from toplevel to subdomain (reversed order)
|
regexMatches.reverse(); //make sure we build the domain from toplevel to subdomain (reversed order)
|
||||||
regexMatches.pop(); // pop the last element, which is, since we reversed the Array, the full String of matched elements
|
regexMatches.pop(); // pop the last element, which is, since we reversed the Array, the full String of matched elements
|
||||||
const regexMatchesFiltered = regexMatches.filter(function(stringArg: string) {
|
const regexMatchesFiltered = regexMatches.filter(function (stringArg: string) {
|
||||||
return stringArg !== '';
|
return stringArg !== '';
|
||||||
});
|
});
|
||||||
return regexMatchesFiltered;
|
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 ------------------- *
|
* ------------------ classes ------------------- *
|
||||||
@ -24,13 +24,14 @@ 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,4 +1,4 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* splits a string into an array
|
* splits a string into an array
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* replaces all occurences of something in a string
|
* replaces all occurences of something in a string
|
||||||
|
@ -1,13 +1,22 @@
|
|||||||
// node native
|
// node native
|
||||||
import * as crypto from 'crypto';
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
import * as url from 'url';
|
const smartenvInstance = new smartenv.Smartenv();
|
||||||
|
import * as isounique from '@pushrocks/isounique';
|
||||||
|
|
||||||
export { crypto, url };
|
export { isounique };
|
||||||
|
|
||||||
|
import { Buffer } from 'buffer';
|
||||||
|
if (smartenvInstance.isBrowser) {
|
||||||
|
globalThis.Buffer = Buffer;
|
||||||
|
}
|
||||||
|
import * as url from 'url';
|
||||||
|
export { url };
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
export let jsBase64 = require('js-base64').Base64;
|
import { Base64 as jsBase64 } from 'js-base64';
|
||||||
|
|
||||||
export let stripIndent = require('strip-indent');
|
import stripIndent from 'strip-indent';
|
||||||
export let normalizeNewline = require('normalize-newline');
|
import normalizeNewline from 'normalize-newline';
|
||||||
export let randomatic = require('randomatic');
|
import randomatic from 'randomatic';
|
||||||
export let cryptoRandomString = require('crypto-random-string');
|
|
||||||
|
export { jsBase64, stripIndent, normalizeNewline, randomatic };
|
||||||
|
@ -1,77 +1,99 @@
|
|||||||
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) => {
|
export const isUtf8 = (stringArg: string) => {
|
||||||
const bytes = Buffer.from(stringArg);
|
const bytes = Buffer.from(stringArg);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while(i < bytes.length)
|
while (i < bytes.length) {
|
||||||
{
|
if (
|
||||||
if( (// ASCII
|
// ASCII
|
||||||
bytes[i] === 0x09 ||
|
bytes[i] === 0x09 ||
|
||||||
bytes[i] === 0x0A ||
|
bytes[i] === 0x0a ||
|
||||||
bytes[i] === 0x0D ||
|
bytes[i] === 0x0d ||
|
||||||
(0x20 <= bytes[i] && bytes[i] <= 0x7E)
|
(0x20 <= bytes[i] && bytes[i] <= 0x7e)
|
||||||
)
|
) {
|
||||||
) {
|
i += 1;
|
||||||
i += 1;
|
continue;
|
||||||
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;
|
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] === '=')
|
||||||
|
);
|
||||||
|
};
|
||||||
|
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
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