@thi.ng/strings 3.7.31 → 3.7.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/center.js +1 -2
- package/cursor.js +2 -4
- package/package.json +11 -12
- package/pad-left.js +1 -2
- package/pad-right.js +1 -2
- package/utf8.js +3 -6
- package/word-wrap.js +1 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/center.js
CHANGED
|
@@ -5,8 +5,7 @@ const center = memoizeJ(
|
|
|
5
5
|
(n, pad = " ") => {
|
|
6
6
|
const buf = repeat(String(pad), n);
|
|
7
7
|
return (x) => {
|
|
8
|
-
if (x == null)
|
|
9
|
-
return buf;
|
|
8
|
+
if (x == null) return buf;
|
|
10
9
|
x = x.toString();
|
|
11
10
|
const r = (n - x.length) / 2;
|
|
12
11
|
return x.length < n ? buf.substring(0, r) + x + buf.substring(
|
package/cursor.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
const computeCursorPos = (str, pos, delim = "\n", offset = [1, 1]) => {
|
|
2
|
-
if (!str.length)
|
|
3
|
-
return [1, 1];
|
|
2
|
+
if (!str.length) return [1, 1];
|
|
4
3
|
pos = Math.min(Math.max(0, pos), str.length);
|
|
5
4
|
const lines = str.split(delim);
|
|
6
5
|
const n = lines.length;
|
|
7
6
|
for (let i = 0; i < n; i++) {
|
|
8
7
|
const l = lines[i];
|
|
9
|
-
if (pos <= l.length)
|
|
10
|
-
return [i + offset[0], pos + offset[1]];
|
|
8
|
+
if (pos <= l.length) return [i + offset[0], pos + offset[1]];
|
|
11
9
|
pos -= l.length + 1;
|
|
12
10
|
}
|
|
13
11
|
return [n + offset[0] - 1, offset[1]];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/strings",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.33",
|
|
4
4
|
"description": "Various string formatting & utility functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
28
|
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
29
|
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
30
|
-
"clean": "
|
|
30
|
+
"clean": "bun ../../tools/src/clean-package.ts",
|
|
31
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
32
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
33
33
|
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
@@ -36,17 +36,16 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/errors": "^2.5.
|
|
41
|
-
"@thi.ng/hex": "^2.3.
|
|
42
|
-
"@thi.ng/memoize": "^3.3.
|
|
39
|
+
"@thi.ng/api": "^8.11.2",
|
|
40
|
+
"@thi.ng/errors": "^2.5.7",
|
|
41
|
+
"@thi.ng/hex": "^2.3.46",
|
|
42
|
+
"@thi.ng/memoize": "^3.3.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.43.
|
|
46
|
-
"esbuild": "^0.
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"typescript": "^5.4.3"
|
|
45
|
+
"@microsoft/api-extractor": "^7.43.2",
|
|
46
|
+
"esbuild": "^0.21.1",
|
|
47
|
+
"typedoc": "^0.25.13",
|
|
48
|
+
"typescript": "^5.4.5"
|
|
50
49
|
},
|
|
51
50
|
"keywords": [
|
|
52
51
|
"ansi",
|
|
@@ -204,5 +203,5 @@
|
|
|
204
203
|
"thi.ng": {
|
|
205
204
|
"year": 2015
|
|
206
205
|
},
|
|
207
|
-
"gitHead": "
|
|
206
|
+
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
|
|
208
207
|
}
|
package/pad-left.js
CHANGED
|
@@ -3,8 +3,7 @@ import { repeat } from "./repeat.js";
|
|
|
3
3
|
const padLeft = memoizeJ((n, ch = " ") => {
|
|
4
4
|
const buf = repeat(String(ch), n);
|
|
5
5
|
return (x, len) => {
|
|
6
|
-
if (x == null)
|
|
7
|
-
return buf;
|
|
6
|
+
if (x == null) return buf;
|
|
8
7
|
x = x.toString();
|
|
9
8
|
len = len !== void 0 ? len : x.length;
|
|
10
9
|
return len < n ? buf.substring(len) + x : x;
|
package/pad-right.js
CHANGED
|
@@ -3,8 +3,7 @@ import { repeat } from "./repeat.js";
|
|
|
3
3
|
const padRight = memoizeJ((n, ch = " ") => {
|
|
4
4
|
const buf = repeat(String(ch), n);
|
|
5
5
|
return (x, len) => {
|
|
6
|
-
if (x == null)
|
|
7
|
-
return buf;
|
|
6
|
+
if (x == null) return buf;
|
|
8
7
|
x = x.toString();
|
|
9
8
|
len = len !== void 0 ? len : x.length;
|
|
10
9
|
return len < n ? x + buf.substring(len) : x;
|
package/utf8.js
CHANGED
|
@@ -27,8 +27,7 @@ const utf8Decode = (buf, start, num) => {
|
|
|
27
27
|
c = (c & 15) << 12 | (buf[i++] & 63) << 6 | buf[i++] & 63;
|
|
28
28
|
} else if (c >= 240 && c < 248) {
|
|
29
29
|
c = (c & 7) << 18 | (buf[i++] & 63) << 12 | (buf[i++] & 63) << 6 | buf[i++] & 63;
|
|
30
|
-
} else
|
|
31
|
-
utf8Error();
|
|
30
|
+
} else utf8Error();
|
|
32
31
|
result += fromUtf8CodePoint(c);
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -51,8 +50,7 @@ const utf8Encode = (src, capacity) => {
|
|
|
51
50
|
c = 65536 + ((c & 1023) << 10) + (src.charCodeAt(++i) & 1023);
|
|
52
51
|
buf[pos++] = 240 | c >> 18;
|
|
53
52
|
buf[pos++] = 128 | c >> 12 & 63;
|
|
54
|
-
} else
|
|
55
|
-
buf[pos++] = 224 | c >> 12;
|
|
53
|
+
} else buf[pos++] = 224 | c >> 12;
|
|
56
54
|
buf[pos++] = 128 | c >> 6 & 63;
|
|
57
55
|
}
|
|
58
56
|
buf[pos++] = 128 | c & 63;
|
|
@@ -61,8 +59,7 @@ const utf8Encode = (src, capacity) => {
|
|
|
61
59
|
return buf.subarray(0, pos);
|
|
62
60
|
};
|
|
63
61
|
const fromUtf8CodePoint = (x) => {
|
|
64
|
-
if (x < 65536)
|
|
65
|
-
return String.fromCharCode(x);
|
|
62
|
+
if (x < 65536) return String.fromCharCode(x);
|
|
66
63
|
if (x < 1114112) {
|
|
67
64
|
x -= 65536;
|
|
68
65
|
return String.fromCharCode(55296 | x >>> 10, 56320 | x & 1023);
|