Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
26d00bb9d3 | |||
fd27ed1a56 | |||
1f31fe9dc5 | |||
bd7888f7ce | |||
201812e182 | |||
8dfa3f8965 | |||
43d50b746b | |||
a1ee8f37d6 | |||
8d9c75e113 | |||
8ff2a9d64a | |||
8665464416 | |||
e773644256 |
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,4 +1,22 @@
|
|||||||
.yarn/
|
.nogit/
|
||||||
pages/
|
|
||||||
|
# artifacts
|
||||||
|
coverage/
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -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
|
||||||
@ -20,17 +20,19 @@ mirror:
|
|||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
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 snyk test
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -38,19 +40,7 @@ snyk:
|
|||||||
# 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
|
||||||
@ -59,6 +49,20 @@ testSTABLE:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
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:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -70,6 +74,7 @@ release:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -78,20 +83,14 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
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 +101,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:
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstring",
|
"name": "@pushrocks/smartstring",
|
||||||
"version": "3.0.11",
|
"version": "3.0.17",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
15
package.json
15
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstring",
|
"name": "@pushrocks/smartstring",
|
||||||
"version": "3.0.11",
|
"version": "3.0.17",
|
||||||
"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/index.js",
|
||||||
@ -38,5 +38,16 @@
|
|||||||
"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"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_web/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,14 @@ 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)
|
@ -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();
|
@ -1,5 +1,5 @@
|
|||||||
// node native
|
// node native
|
||||||
import * as crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
|
|
||||||
export { crypto, url };
|
export { crypto, url };
|
||||||
|
@ -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