fix(core): update

This commit is contained in:
Philipp Kunz 2024-03-01 23:34:43 +01:00
parent 2c29ae3bf0
commit 6f2cedc1dd
7 changed files with 437 additions and 400 deletions

View File

@ -26,20 +26,18 @@
},
"homepage": "https://gitlab.com/push.rocks/smartstring#readme",
"devDependencies": {
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsbuild": "^2.1.72",
"@git.zone/tsrun": "^1.2.42",
"@git.zone/tstest": "^1.0.84",
"@git.zone/tstest": "^1.0.86",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.10.5"
"@types/node": "^20.11.24"
},
"dependencies": {
"@push.rocks/isounique": "^1.0.5",
"@push.rocks/smartenv": "^5.0.12",
"@types/randomatic": "^3.1.5",
"buffer": "^6.0.3",
"crypto-random-string": "^5.0.0",
"js-base64": "^3.7.5",
"normalize-newline": "^4.1.0",
"js-base64": "^3.7.7",
"randomatic": "^3.1.1",
"strip-indent": "^4.0.0",
"url": "^0.11.3"

File diff suppressed because it is too large Load Diff

View File

@ -2,12 +2,14 @@ import { tap, expect } from '@push.rocks/tapbundle';
import * as smartstring from '../ts/index.js';
tap.test('should normalize a string', async () => {
tap.test('should normalize a string', async (toolsArg) => {
const testString = `
myawesome string;
is indented with two spaces
`;
const normalizedString = smartstring.normalize.standard(testString);
console.log(normalizedString);
expect(normalizedString).toEqual(
`myawesome string;
is indented with two spaces

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartstring',
version: '4.0.12',
version: '4.0.14',
description: 'handle strings in smart ways. TypeScript ready.'
}

View File

@ -31,7 +31,7 @@ export const standard = (stringArg: string, options?: INormalizeOptions): string
}
if (!options || options.normalizeNewline) {
result = plugins.normalizeNewline(result); // fix newlines
result = result.replace(/\r\n/g, '\n'); // fix newlines
}
if (!options || options.replaceTabs) {

View File

@ -5,10 +5,6 @@ import * as isounique from '@push.rocks/isounique';
export { isounique };
import { Buffer } from 'buffer';
if (smartenvInstance.isBrowser) {
globalThis.Buffer = Buffer;
}
import * as url from 'url';
export { url };
@ -16,7 +12,6 @@ export { url };
import { Base64 as jsBase64 } from 'js-base64';
import stripIndent from 'strip-indent';
import normalizeNewline from 'normalize-newline';
import randomatic from 'randomatic';
export { jsBase64, stripIndent, normalizeNewline, randomatic };
export { jsBase64, stripIndent, randomatic };

View File

@ -1,8 +1,12 @@
import * as plugins from './smartstring.plugins.js';
import * as base64 from './smartstring.base64.js';
export const isUtf8 = (stringArg: string) => {
const bytes = Buffer.from(stringArg);
export const isUtf8 = (stringArg: string): boolean => {
// Convert string to a Uint8Array. In browsers, this will be a bit more complex
// because we need to convert the string to a binary representation first.
const encoder = new TextEncoder();
const bytes = encoder.encode(stringArg);
let i = 0;
while (i < bytes.length) {
if (
@ -33,12 +37,14 @@ export const isUtf8 = (stringArg: string) => {
0xa0 <= bytes[i + 1] &&
bytes[i + 1] <= 0xbf &&
0x80 <= bytes[i + 2] &&
bytes[i + 2] <= 0xbf) || // straight 3-byte
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 + 2] <= 0xbf) ||
// excluding surrogates
(bytes[i] === 0xed &&
0x80 <= bytes[i + 1] &&
bytes[i + 1] <= 0x9f &&
@ -57,7 +63,8 @@ export const isUtf8 = (stringArg: string) => {
0x80 <= bytes[i + 2] &&
bytes[i + 2] <= 0xbf &&
0x80 <= bytes[i + 3] &&
bytes[i + 3] <= 0xbf) || // planes 4-15
bytes[i + 3] <= 0xbf) ||
// planes 4-15
(0xf1 <= bytes[i] &&
bytes[i] <= 0xf3 &&
0x80 <= bytes[i + 1] &&
@ -65,7 +72,8 @@ export const isUtf8 = (stringArg: string) => {
0x80 <= bytes[i + 2] &&
bytes[i + 2] <= 0xbf &&
0x80 <= bytes[i + 3] &&
bytes[i + 3] <= 0xbf) || // plane 16
bytes[i + 3] <= 0xbf) ||
// plane 16
(bytes[i] === 0xf4 &&
0x80 <= bytes[i + 1] &&
bytes[i + 1] <= 0x8f &&
@ -84,6 +92,7 @@ export const isUtf8 = (stringArg: string) => {
return true;
};
export const isBase64 = (stringArg: string) => {
const notBase64 = /[^A-Z0-9+\/=]/i;
const len = stringArg.length;