fix(core): update

This commit is contained in:
Philipp Kunz 2019-10-10 17:28:23 +02:00
parent 979375f08d
commit 55a5948a51
5 changed files with 695 additions and 571 deletions

1160
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,19 +24,19 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartstring#readme", "homepage": "https://gitlab.com/pushrocks/smartstring#readme",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.4", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.1.17", "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.18", "@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^10.12.18", "@types/node": "^12.7.12",
"tslint": "^5.15.0", "tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"crypto-random-string": "^1.0.0", "crypto-random-string": "^3.0.1",
"js-base64": "^2.5.0", "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": "^2.0.0" "strip-indent": "^3.0.0"
} }
} }

8
test/test.type.ts Normal file
View File

@ -0,0 +1,8 @@
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();

View File

@ -2,8 +2,9 @@ import * as create from './smartstring.create';
import * as docker from './smartstring.docker'; import * as docker from './smartstring.docker';
import * as indent from './smartstring.indent'; import * as indent from './smartstring.indent';
import * as normalize from './smartstring.normalize'; import * as normalize from './smartstring.normalize';
import * as type from './smartstring.type';
export { create, docker, normalize, indent }; export { create, docker, normalize, indent, type };
export { Base64, base64 } from './smartstring.base64'; export { Base64, base64 } from './smartstring.base64';
export { Domain } from './smartstring.domain'; export { Domain } from './smartstring.domain';

77
ts/smartstring.type.ts Normal file
View File

@ -0,0 +1,77 @@
import * as plugins from './smartstring.plugins';
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;
}
return true;
};