@thi.ng/strings 3.8.5 → 3.8.7
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 +7 -1
- package/README.md +1 -1
- package/center.js +10 -15
- package/join.d.ts +1 -1
- package/package.json +7 -7
- package/pad-left.js +2 -2
- package/pad-right.js +2 -2
- package/radix.js +4 -4
- package/repeat.d.ts +1 -1
- package/repeat.js +1 -3
- package/trim.d.ts +1 -1
- package/units.js +23 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-10-31T22:57:28Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [3.8.7](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.8.7) (2024-10-31)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- update memoizations ([7c3ca44](https://github.com/thi-ng/umbrella/commit/7c3ca44))
|
|
17
|
+
|
|
12
18
|
## [3.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.8.0) (2024-07-19)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
package/center.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { memoizeO } from "@thi.ng/memoize/memoizeo";
|
|
2
2
|
import { repeat } from "./repeat.js";
|
|
3
3
|
import { truncate } from "./truncate.js";
|
|
4
|
-
const center =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
r + ((n & 1) === (x.length & 1) ? 0 : 1)
|
|
14
|
-
) : truncate(n)(x);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
);
|
|
4
|
+
const center = memoizeO((n, pad = " ") => {
|
|
5
|
+
const buf = repeat(String(pad), n);
|
|
6
|
+
return (x) => {
|
|
7
|
+
if (x == null) return buf;
|
|
8
|
+
x = x.toString();
|
|
9
|
+
const r = (n - x.length) / 2;
|
|
10
|
+
return x.length < n ? buf.substring(0, r) + x + buf.substring(0, r + ((n & 1) === (x.length & 1) ? 0 : 1)) : truncate(n)(x);
|
|
11
|
+
};
|
|
12
|
+
});
|
|
18
13
|
export {
|
|
19
14
|
center
|
|
20
15
|
};
|
package/join.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/strings",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.7",
|
|
4
4
|
"description": "Various string formatting & utility functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,14 +36,14 @@
|
|
|
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": "^
|
|
39
|
+
"@thi.ng/api": "^8.11.11",
|
|
40
|
+
"@thi.ng/errors": "^2.5.17",
|
|
41
|
+
"@thi.ng/hex": "^2.3.55",
|
|
42
|
+
"@thi.ng/memoize": "^4.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@microsoft/api-extractor": "^7.47.9",
|
|
46
|
-
"esbuild": "^0.
|
|
46
|
+
"esbuild": "^0.24.0",
|
|
47
47
|
"typedoc": "^0.26.7",
|
|
48
48
|
"typescript": "^5.6.2"
|
|
49
49
|
},
|
|
@@ -208,5 +208,5 @@
|
|
|
208
208
|
"thi.ng": {
|
|
209
209
|
"year": 2015
|
|
210
210
|
},
|
|
211
|
-
"gitHead": "
|
|
211
|
+
"gitHead": "36d88652f6712b0e7ed8e55d1f4d9b3718294f7f\n"
|
|
212
212
|
}
|
package/pad-left.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { memoizeO } from "@thi.ng/memoize/memoizeo";
|
|
2
2
|
import { repeat } from "./repeat.js";
|
|
3
|
-
const padLeft =
|
|
3
|
+
const padLeft = memoizeO((n, ch = " ") => {
|
|
4
4
|
const buf = repeat(String(ch), n);
|
|
5
5
|
return (x, len) => {
|
|
6
6
|
if (x == null) return buf;
|
package/pad-right.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { memoizeO } from "@thi.ng/memoize/memoizeo";
|
|
2
2
|
import { repeat } from "./repeat.js";
|
|
3
|
-
const padRight =
|
|
3
|
+
const padRight = memoizeO((n, ch = " ") => {
|
|
4
4
|
const buf = repeat(String(ch), n);
|
|
5
5
|
return (x, len) => {
|
|
6
6
|
if (x == null) return buf;
|
package/radix.js
CHANGED
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
U16 as $16,
|
|
3
3
|
U24 as $24,
|
|
4
4
|
U32 as $32,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
U8 as $8,
|
|
6
|
+
U64HL
|
|
7
7
|
} from "@thi.ng/hex";
|
|
8
|
-
import {
|
|
8
|
+
import { memoizeO } from "@thi.ng/memoize/memoizeo";
|
|
9
9
|
import { repeat } from "./repeat.js";
|
|
10
|
-
const radix =
|
|
10
|
+
const radix = memoizeO(
|
|
11
11
|
(radix2, n, prefix = "") => {
|
|
12
12
|
const buf = repeat("0", n);
|
|
13
13
|
return (x) => {
|
package/repeat.d.ts
CHANGED
package/repeat.js
CHANGED
package/trim.d.ts
CHANGED
package/units.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { memoizeJ } from "@thi.ng/memoize/memoizej";
|
|
2
|
-
const units = memoizeJ(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
x[
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const absX = Math.abs(x);
|
|
15
|
-
for (let i = groups.length; i-- > 0; ) {
|
|
16
|
-
const g = groups[i];
|
|
17
|
-
if (absX >= g[0] || i === 0) {
|
|
18
|
-
return (x / g[0]).toFixed(g[1]) + g[2];
|
|
2
|
+
const units = memoizeJ(
|
|
3
|
+
(exp, base, prec = 2) => {
|
|
4
|
+
const groups = exp.map(
|
|
5
|
+
(x) => [
|
|
6
|
+
x[0],
|
|
7
|
+
x[2] != null ? x[2] : prec,
|
|
8
|
+
x[1]
|
|
9
|
+
]
|
|
10
|
+
).sort((a, b) => a[0] - b[0]);
|
|
11
|
+
return (x) => {
|
|
12
|
+
if (x === 0) {
|
|
13
|
+
return `0${base}`;
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const absX = Math.abs(x);
|
|
16
|
+
for (let i = groups.length; i-- > 0; ) {
|
|
17
|
+
const g = groups[i];
|
|
18
|
+
if (absX >= g[0] || i === 0) {
|
|
19
|
+
return (x / g[0]).toFixed(g[1]) + g[2];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return "";
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
);
|
|
24
26
|
const KB = 1024;
|
|
25
27
|
const bits = units(
|
|
26
28
|
[
|