From 8ff2a9d64a53019476e1d6c52bf7da5d21258f81 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 10 Oct 2019 18:14:07 +0200 Subject: [PATCH] fix(core): update --- .gitignore | 22 ++++++- .gitlab-ci.yml | 53 ++++++++--------- README.md | 4 +- package.json | 15 ++++- test/test.type.ts | 2 +- ts/smartstring.type.ts | 129 +++++++++++++++++++---------------------- 6 files changed, 120 insertions(+), 105 deletions(-) diff --git a/.gitignore b/.gitignore index 2de0d1f..91c0db0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,22 @@ -.yarn/ -pages/ +.nogit/ + +# artifacts +coverage/ public/ +pages/ + +# installs node_modules/ + +# caches +.yarn/ +.cache/ +.rpt2_cache + +# builds +dist/ +dist_web/ +dist_serve/ +dist_ts_web/ + +# custom \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8321aed..0b92fd3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ -# gitzone standard -image: hosttoday/ht-docker-node:npmci +# gitzone ci_default +image: registry.gitlab.com/hosttoday/ht-docker-node:npmci cache: paths: @@ -38,19 +38,7 @@ snyk: # test stage # ==================== -testLTS: - 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: +testStable: stage: test script: - npmci npm prepare @@ -60,6 +48,18 @@ testSTABLE: coverage: /\d+.?\d+?\%\s*coverage/ tags: - 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: + - docker - notpriv release: @@ -78,19 +78,12 @@ release: # ==================== codequality: stage: metadata - image: docker:stable allow_failure: true - services: - - docker:stable-dind script: - - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - - docker run - --env SOURCE_CODE="$PWD" - --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] + - npmci command npm install -g tslint typescript + - npmci npm prepare + - npmci npm install + - npmci command "tslint -c tslint.json ./ts/**/*.ts" tags: - docker - priv @@ -106,13 +99,15 @@ trigger: - notpriv pages: - image: hosttoday/ht-docker-node:npmci + image: hosttoday/ht-docker-dbase:npmci + services: + - docker:stable-dind stage: metadata script: - - npmci command npm install -g typedoc typescript + - npmci command npm install -g @gitzone/tsdoc - npmci npm prepare - npmci npm install - - npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ + - npmci command tsdoc tags: - docker - notpriv diff --git a/README.md b/README.md index dc4f548..07c71a4 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,6 @@ smartstring.indent.normalize(' somestring anotherstring', '>>>> '); // 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) +| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) -[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) +[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com) diff --git a/package.json b/package.json index 15a9ff7..3cb1355 100644 --- a/package.json +++ b/package.json @@ -38,5 +38,16 @@ "normalize-newline": "^3.0.0", "randomatic": "^3.1.1", "strip-indent": "^3.0.0" - } -} + }, + "files": [ + "ts/**/*", + "ts_web/**/*", + "dist/**/*", + "dist_web/**/*", + "dist_ts_web/**/*", + "assets/**/*", + "cli.js", + "npmextra.json", + "readme.md" + ] +} \ No newline at end of file diff --git a/test/test.type.ts b/test/test.type.ts index b6e31f5..b5b9f73 100644 --- a/test/test.type.ts +++ b/test/test.type.ts @@ -11,4 +11,4 @@ tap.test('should state wether base64 string is valid', async () => { expect(smartstring.type.isBase64('hi there')).to.be.false; }); -tap.start(); \ No newline at end of file +tap.start(); diff --git a/ts/smartstring.type.ts b/ts/smartstring.type.ts index bbfef91..692f30a 100644 --- a/ts/smartstring.type.ts +++ b/ts/smartstring.type.ts @@ -4,77 +4,68 @@ import * as base64 from './smartstring.base64'; export const isUtf8 = (stringArg: string) => { const bytes = Buffer.from(stringArg); let i = 0; - while(i < bytes.length) - { - if( (// ASCII - bytes[i] === 0x09 || - bytes[i] === 0x0A || - bytes[i] === 0x0D || - (0x20 <= bytes[i] && bytes[i] <= 0x7E) - ) - ) { - i += 1; - continue; - } - - if( (// non-overlong 2-byte - (0xC2 <= bytes[i] && bytes[i] <= 0xDF) && - (0x80 <= bytes[i+1] && bytes[i+1] <= 0xBF) - ) - ) { - i += 2; - continue; - } - - if( (// excluding overlongs - bytes[i] === 0xE0 && - (0xA0 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) - ) || - (// straight 3-byte - ((0xE1 <= bytes[i] && bytes[i] <= 0xEC) || - bytes[i] === 0xEE || - bytes[i] === 0xEF) && - (0x80 <= bytes[i + 1] && bytes[i+1] <= 0xBF) && - (0x80 <= bytes[i+2] && bytes[i+2] <= 0xBF) - ) || - (// excluding surrogates - bytes[i] === 0xED && - (0x80 <= bytes[i+1] && bytes[i+1] <= 0x9F) && - (0x80 <= bytes[i+2] && bytes[i+2] <= 0xBF) - ) - ) { - i += 3; - continue; - } - - if( (// planes 1-3 - bytes[i] === 0xF0 && - (0x90 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && - (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) - ) || - (// planes 4-15 - (0xF1 <= bytes[i] && bytes[i] <= 0xF3) && - (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && - (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) - ) || - (// plane 16 - bytes[i] === 0xF4 && - (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x8F) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && - (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) - ) - ) { - i += 4; - continue; - } - - return false; + while (i < bytes.length) { + if ( + // ASCII + bytes[i] === 0x09 || + bytes[i] === 0x0a || + bytes[i] === 0x0d || + (0x20 <= bytes[i] && bytes[i] <= 0x7e) + ) { + i += 1; + continue; } - 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) => {