@thi.ng/strings 3.8.6 → 3.8.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-10-05T12:12:32Z
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
@@ -151,7 +151,7 @@ For Node.js REPL:
151
151
  const str = await import("@thi.ng/strings");
152
152
  ```
153
153
 
154
- Package sizes (brotli'd, pre-treeshake): ESM: 5.52 KB
154
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.50 KB
155
155
 
156
156
  ## Dependencies
157
157
 
package/center.js CHANGED
@@ -1,20 +1,15 @@
1
- import { memoizeJ } from "@thi.ng/memoize/memoizej";
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 = memoizeJ(
5
- (n, pad = " ") => {
6
- const buf = repeat(String(pad), n);
7
- return (x) => {
8
- if (x == null) return buf;
9
- x = x.toString();
10
- const r = (n - x.length) / 2;
11
- return x.length < n ? buf.substring(0, r) + x + buf.substring(
12
- 0,
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
@@ -27,5 +27,5 @@ import type { Stringer } from "./api.js";
27
27
  * // "f 1/2 3/4 5/6"
28
28
  * ```
29
29
  */
30
- export declare const join: (x: string) => Stringer<any[]>;
30
+ export declare const join: import("@thi.ng/api").Fn<string, Stringer<any[]>>;
31
31
  //# sourceMappingURL=join.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/strings",
3
- "version": "3.8.6",
3
+ "version": "3.8.8",
4
4
  "description": "Various string formatting & utility functions",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -39,7 +39,7 @@
39
39
  "@thi.ng/api": "^8.11.11",
40
40
  "@thi.ng/errors": "^2.5.17",
41
41
  "@thi.ng/hex": "^2.3.55",
42
- "@thi.ng/memoize": "^3.3.13"
42
+ "@thi.ng/memoize": "^4.0.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@microsoft/api-extractor": "^7.47.9",
@@ -208,5 +208,5 @@
208
208
  "thi.ng": {
209
209
  "year": 2015
210
210
  },
211
- "gitHead": "11ae480076e61a2263f5730ffb37dfddbf01c7d1\n"
211
+ "gitHead": "1148f3130b867c65141957b4b7617021d7ac7fc9\n"
212
212
  }
package/pad-left.js CHANGED
@@ -1,6 +1,6 @@
1
- import { memoizeJ } from "@thi.ng/memoize/memoizej";
1
+ import { memoizeO } from "@thi.ng/memoize/memoizeo";
2
2
  import { repeat } from "./repeat.js";
3
- const padLeft = memoizeJ((n, ch = " ") => {
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 { memoizeJ } from "@thi.ng/memoize/memoizej";
1
+ import { memoizeO } from "@thi.ng/memoize/memoizeo";
2
2
  import { repeat } from "./repeat.js";
3
- const padRight = memoizeJ((n, ch = " ") => {
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
- U64HL,
6
- U8 as $8
5
+ U8 as $8,
6
+ U64HL
7
7
  } from "@thi.ng/hex";
8
- import { memoizeJ } from "@thi.ng/memoize/memoizej";
8
+ import { memoizeO } from "@thi.ng/memoize/memoizeo";
9
9
  import { repeat } from "./repeat.js";
10
- const radix = memoizeJ(
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
@@ -2,5 +2,5 @@
2
2
  * @param ch - character
3
3
  * @param n - repeat count
4
4
  */
5
- export declare const repeat: import("@thi.ng/api").Fn2<string, number, string>;
5
+ export declare const repeat: (ch: string, n: number) => string;
6
6
  //# sourceMappingURL=repeat.d.ts.map
package/repeat.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { memoizeJ } from "@thi.ng/memoize/memoizej";
2
- const repeat = memoizeJ(
3
- (ch, n) => ch.repeat(n)
4
- );
2
+ const repeat = memoizeJ((ch, n) => ch.repeat(n));
5
3
  export {
6
4
  repeat
7
5
  };
package/trim.d.ts CHANGED
@@ -20,5 +20,5 @@ import type { Stringer } from "./api.js";
20
20
  *
21
21
  * @param chars -
22
22
  */
23
- export declare const trim: (x: string) => Stringer<string>;
23
+ export declare const trim: import("@thi.ng/api").Fn<string, Stringer<string>>;
24
24
  //# sourceMappingURL=trim.d.ts.map
package/units.js CHANGED
@@ -1,26 +1,28 @@
1
1
  import { memoizeJ } from "@thi.ng/memoize/memoizej";
2
- const units = memoizeJ((exp, base, prec = 2) => {
3
- const groups = exp.map(
4
- (x) => [
5
- x[0],
6
- x[2] != null ? x[2] : prec,
7
- x[1]
8
- ]
9
- ).sort((a, b) => a[0] - b[0]);
10
- return (x) => {
11
- if (x === 0) {
12
- return `0${base}`;
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
- return "";
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
  [