Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
1f31fe9dc5 | |||
bd7888f7ce | |||
201812e182 | |||
8dfa3f8965 | |||
43d50b746b | |||
a1ee8f37d6 | |||
8d9c75e113 | |||
8ff2a9d64a |
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,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
|
||||||
@ -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:
|
||||||
|
66
README.md
66
README.md
@ -1,66 +0,0 @@
|
|||||||
# @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
|
|
||||||
[](https://gitlab.com/pushrocks/smartstring/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartstring/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartstring)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartstring)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://prettier.io/)
|
|
||||||
|
|
||||||
## 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)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstring",
|
"name": "@pushrocks/smartstring",
|
||||||
"version": "3.0.12",
|
"version": "3.0.16",
|
||||||
"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.12",
|
"version": "3.0.16",
|
||||||
"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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -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 };
|
||||||
|
@ -4,68 +4,75 @@ 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;
|
||||||
@ -78,5 +85,15 @@ export const isUtf8 = (stringArg: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const isBase64 = (stringArg: string) => {
|
export const isBase64 = (stringArg: string) => {
|
||||||
return stringArg.endsWith('=');
|
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