Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
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
|
@ -1,10 +1,10 @@
|
|||||||
# 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
|
||||||
@ -19,38 +19,41 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- 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
|
|
||||||
|
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
|
|
||||||
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
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
@ -60,7 +63,17 @@ testSTABLE:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -70,6 +83,7 @@ release:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -78,20 +92,16 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
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:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@ -102,18 +112,20 @@ trigger:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- 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:
|
||||||
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -9,6 +9,7 @@
|
|||||||
"dockerSock": false
|
"dockerSock": false
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
10586
package-lock.json
generated
10586
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
43
package.json
43
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstring",
|
"name": "@pushrocks/smartstring",
|
||||||
"version": "3.0.11",
|
"version": "3.0.23",
|
||||||
"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,19 +24,36 @@
|
|||||||
},
|
},
|
||||||
"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.25",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^12.7.12",
|
"@types/node": "^14.14.17",
|
||||||
"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/smartenv": "^4.0.16",
|
||||||
|
"crypto-random-string": "^3.3.0",
|
||||||
"js-base64": "^2.5.1",
|
"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": "^3.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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -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)
|
@ -29,4 +29,9 @@ tap.test('testDomain2 expect be a basic domain', async () => {
|
|||||||
console.log(testDomain2);
|
console.log(testDomain2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should parse complex domains', async () => {
|
||||||
|
testDomain2 = new smartstring.Domain('https://sub1.sub2.lossless.com/some/path:5431');
|
||||||
|
console.log(testDomain2);
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -5,4 +5,10 @@ tap.test('should state valuid utf8', async () => {
|
|||||||
expect(smartstring.type.isUtf8('hithere')).to.be.true;
|
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();
|
tap.start();
|
@ -65,5 +65,5 @@ export let base64 = {
|
|||||||
*/
|
*/
|
||||||
decode: (stringArg: string) => {
|
decode: (stringArg: string) => {
|
||||||
return plugins.jsBase64.decode(stringArg);
|
return plugins.jsBase64.decode(stringArg);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
@ -16,7 +16,12 @@ 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.nodeParsedUrl = plugins.url.parse(domainStringArg);
|
||||||
|
this.port = this.nodeParsedUrl.port;
|
||||||
|
|
||||||
|
// lets do the rest after
|
||||||
|
const regexMatches = this._domainRegex(domainStringArg.replace(this.nodeParsedUrl.path, ''));
|
||||||
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]) {
|
||||||
@ -38,9 +43,6 @@ export class Domain {
|
|||||||
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
|
||||||
|
@ -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) {
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
// 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');
|
||||||
|
|
||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
|
|
||||||
export { crypto, url };
|
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 };
|
||||||
|
@ -1,70 +1,78 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
import * as plugins from './smartstring.plugins';
|
||||||
|
import * as base64 from './smartstring.base64';
|
||||||
|
|
||||||
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
|
if (
|
||||||
(0xC2 <= bytes[i] && bytes[i] <= 0xDF) &&
|
// non-overlong 2-byte
|
||||||
(0x80 <= bytes[i+1] && bytes[i+1] <= 0xBF)
|
0xc2 <= bytes[i] &&
|
||||||
)
|
bytes[i] <= 0xdf &&
|
||||||
|
0x80 <= bytes[i + 1] &&
|
||||||
|
bytes[i + 1] <= 0xbf
|
||||||
) {
|
) {
|
||||||
i += 2;
|
i += 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (// excluding overlongs
|
if (
|
||||||
bytes[i] === 0xE0 &&
|
// excluding overlongs
|
||||||
(0xA0 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) &&
|
(bytes[i] === 0xe0 &&
|
||||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF)
|
0xa0 <= bytes[i + 1] &&
|
||||||
) ||
|
bytes[i + 1] <= 0xbf &&
|
||||||
(// straight 3-byte
|
0x80 <= bytes[i + 2] &&
|
||||||
((0xE1 <= bytes[i] && bytes[i] <= 0xEC) ||
|
bytes[i + 2] <= 0xbf) || // straight 3-byte
|
||||||
bytes[i] === 0xEE ||
|
(((0xe1 <= bytes[i] && bytes[i] <= 0xec) || bytes[i] === 0xee || bytes[i] === 0xef) &&
|
||||||
bytes[i] === 0xEF) &&
|
0x80 <= bytes[i + 1] &&
|
||||||
(0x80 <= bytes[i + 1] && bytes[i+1] <= 0xBF) &&
|
bytes[i + 1] <= 0xbf &&
|
||||||
(0x80 <= bytes[i+2] && bytes[i+2] <= 0xBF)
|
0x80 <= bytes[i + 2] &&
|
||||||
) ||
|
bytes[i + 2] <= 0xbf) || // excluding surrogates
|
||||||
(// excluding surrogates
|
(bytes[i] === 0xed &&
|
||||||
bytes[i] === 0xED &&
|
0x80 <= bytes[i + 1] &&
|
||||||
(0x80 <= bytes[i+1] && bytes[i+1] <= 0x9F) &&
|
bytes[i + 1] <= 0x9f &&
|
||||||
(0x80 <= bytes[i+2] && bytes[i+2] <= 0xBF)
|
0x80 <= bytes[i + 2] &&
|
||||||
)
|
bytes[i + 2] <= 0xbf)
|
||||||
) {
|
) {
|
||||||
i += 3;
|
i += 3;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (// planes 1-3
|
if (
|
||||||
bytes[i] === 0xF0 &&
|
// planes 1-3
|
||||||
(0x90 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) &&
|
(bytes[i] === 0xf0 &&
|
||||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) &&
|
0x90 <= bytes[i + 1] &&
|
||||||
(0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF)
|
bytes[i + 1] <= 0xbf &&
|
||||||
) ||
|
0x80 <= bytes[i + 2] &&
|
||||||
(// planes 4-15
|
bytes[i + 2] <= 0xbf &&
|
||||||
(0xF1 <= bytes[i] && bytes[i] <= 0xF3) &&
|
0x80 <= bytes[i + 3] &&
|
||||||
(0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) &&
|
bytes[i + 3] <= 0xbf) || // planes 4-15
|
||||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) &&
|
(0xf1 <= bytes[i] &&
|
||||||
(0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF)
|
bytes[i] <= 0xf3 &&
|
||||||
) ||
|
0x80 <= bytes[i + 1] &&
|
||||||
(// plane 16
|
bytes[i + 1] <= 0xbf &&
|
||||||
bytes[i] === 0xF4 &&
|
0x80 <= bytes[i + 2] &&
|
||||||
(0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x8F) &&
|
bytes[i + 2] <= 0xbf &&
|
||||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) &&
|
0x80 <= bytes[i + 3] &&
|
||||||
(0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF)
|
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;
|
i += 4;
|
||||||
continue;
|
continue;
|
||||||
@ -75,3 +83,17 @@ export const isUtf8 = (stringArg: string) => {
|
|||||||
|
|
||||||
return true;
|
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