@oliversalzburg/js-utils 0.0.24-dev.27 → 0.0.24-dev.29
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/log/report.d.ts +6 -0
- package/log/report.js +8 -2
- package/log/report.js.map +1 -1
- package/package.json +1 -1
- package/string.d.ts +13 -2
- package/string.js +25 -2
- package/string.js.map +1 -1
package/log/report.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export interface ReportEntry {
|
|
|
15
15
|
*/
|
|
16
16
|
context: Record<string, unknown> | undefined;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Ensures an origin stays within reasonable display size.
|
|
20
|
+
* @param origin - The original log origin.
|
|
21
|
+
* @returns A shortened origin for display.
|
|
22
|
+
*/
|
|
23
|
+
export declare const makeLogOrigin: (origin: string) => string;
|
|
18
24
|
/**
|
|
19
25
|
* A hierarchical background report/log.
|
|
20
26
|
* @group Logging
|
package/log/report.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { TreeNode } from "../data/tree.js";
|
|
2
2
|
import { InvalidOperationError } from "../errors/InvalidOperationError.js";
|
|
3
|
-
import { indent } from "../string.js";
|
|
3
|
+
import { cyrb53, indent } from "../string.js";
|
|
4
|
+
/**
|
|
5
|
+
* Ensures an origin stays within reasonable display size.
|
|
6
|
+
* @param origin - The original log origin.
|
|
7
|
+
* @returns A shortened origin for display.
|
|
8
|
+
*/
|
|
9
|
+
export const makeLogOrigin = (origin) => 100 < origin.length ? cyrb53(origin) : origin;
|
|
4
10
|
/**
|
|
5
11
|
* A hierarchical background report/log.
|
|
6
12
|
* @group Logging
|
|
@@ -53,7 +59,7 @@ export class Report extends TreeNode {
|
|
|
53
59
|
* @param context - An arbitrary key-value object to store with the message.
|
|
54
60
|
*/
|
|
55
61
|
log(message, context) {
|
|
56
|
-
this.#getStoreEntry(this.origin)?.push({ message, context });
|
|
62
|
+
this.#getStoreEntry(makeLogOrigin(this.origin))?.push({ message, context });
|
|
57
63
|
}
|
|
58
64
|
/**
|
|
59
65
|
* Prints the contents of the report.
|
package/log/report.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../source/log/report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../source/log/report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAoB9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAc,EAAU,EAAE,CACtD,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAEhD;;;GAGG;AACH,gDAAgD;AAChD,MAAM,OAAO,MAAO,SAAQ,QAAgB;IAC1C;;OAEG;IACM,MAAM,CAAS;IACxB;;OAEG;IACH,MAAM,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE/C;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACH,YAAY,MAAc,EAAE,MAA2B;QACrD,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,qBAAqB,CAAC,eAAe,MAA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,EAAE,KAAK,CAAC,CAAC,CAAC;gBACjF,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
package/string.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Indent every line of the passed text.
|
|
3
|
-
* @param
|
|
3
|
+
* @param subject - The text to indent.
|
|
4
4
|
* @param depth - How often to apply the indenting.
|
|
5
5
|
* @param prefix - The string to use as the indent.
|
|
6
6
|
* @returns The indented text.
|
|
7
7
|
* @group Strings
|
|
8
8
|
*/
|
|
9
|
-
export declare const indent: (
|
|
9
|
+
export declare const indent: (subject: string, depth?: number, prefix?: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* A fast and simple 53-bit string hash function with decent collision resistance.
|
|
12
|
+
* Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
|
|
13
|
+
* License: Public domain. Attribution appreciated.
|
|
14
|
+
* cyrb53 (c) 2018 bryc (github.com/bryc)
|
|
15
|
+
* @param subject - The string to hash.
|
|
16
|
+
* @param seed - An optional seed value.
|
|
17
|
+
* @returns A hash of the string.
|
|
18
|
+
* @group Strings
|
|
19
|
+
*/
|
|
20
|
+
export declare const cyrb53: (subject: string, seed?: number) => string;
|
package/string.js
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Indent every line of the passed text.
|
|
3
|
-
* @param
|
|
3
|
+
* @param subject - The text to indent.
|
|
4
4
|
* @param depth - How often to apply the indenting.
|
|
5
5
|
* @param prefix - The string to use as the indent.
|
|
6
6
|
* @returns The indented text.
|
|
7
7
|
* @group Strings
|
|
8
8
|
*/
|
|
9
|
-
export const indent = (
|
|
9
|
+
export const indent = (subject, depth = 0, prefix = " ") => subject.replaceAll(/^/gm, prefix.repeat(depth));
|
|
10
|
+
/**
|
|
11
|
+
* A fast and simple 53-bit string hash function with decent collision resistance.
|
|
12
|
+
* Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
|
|
13
|
+
* License: Public domain. Attribution appreciated.
|
|
14
|
+
* cyrb53 (c) 2018 bryc (github.com/bryc)
|
|
15
|
+
* @param subject - The string to hash.
|
|
16
|
+
* @param seed - An optional seed value.
|
|
17
|
+
* @returns A hash of the string.
|
|
18
|
+
* @group Strings
|
|
19
|
+
*/
|
|
20
|
+
export const cyrb53 = (subject, seed = 0) => {
|
|
21
|
+
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
22
|
+
for (let i = 0, ch; i < subject.length; i++) {
|
|
23
|
+
ch = subject.charCodeAt(i);
|
|
24
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
25
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
26
|
+
}
|
|
27
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
|
|
28
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
29
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
|
|
30
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
31
|
+
return (h2 >>> 0).toString(16).padStart(8, "0") + (h1 >>> 0).toString(16).padStart(8, "0");
|
|
32
|
+
};
|
|
10
33
|
//# sourceMappingURL=string.js.map
|
package/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../source/string.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"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