@e280/stz 0.0.0-3 → 0.0.0-30
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/README.md +170 -0
- package/package.json +14 -7
- package/s/clone/clone.test.ts +123 -123
- package/s/coalesce.ts +1 -0
- package/s/data/base-x.ts +170 -0
- package/s/data/base58.ts +15 -5
- package/s/data/base64.ts +15 -6
- package/s/data/base64url.ts +15 -6
- package/s/data/bytename/bytename.test.ts +49 -0
- package/s/data/{barname/barname.ts → bytename/bytename.ts} +38 -10
- package/s/data/bytename/index.ts +4 -0
- package/s/data/bytename/thumbprint.test.ts +53 -0
- package/s/data/bytename/thumbprint.ts +112 -0
- package/s/data/bytes.ts +12 -2
- package/s/data/data.test.ts +98 -0
- package/s/data/hex.ts +15 -5
- package/s/data/txt.ts +14 -4
- package/s/deadline.ts +1 -0
- package/s/debounce/debounce.test.ts +73 -73
- package/s/deep/deep.test.ts +8 -8
- package/s/deep/parts/equal.test.ts +123 -124
- package/s/{defer-promise.ts → defer.ts} +2 -2
- package/s/drill.ts +2 -4
- package/s/ev.ts +20 -0
- package/s/id-counter.ts +9 -0
- package/s/index.ts +16 -2
- package/s/is.ts +10 -4
- package/s/loopy.ts +12 -0
- package/s/map-g.ts +2 -2
- package/s/nap.ts +1 -0
- package/s/once.ts +14 -0
- package/s/pubsub.ts +24 -6
- package/s/queue/queue.test.ts +67 -0
- package/s/queue/queue.ts +21 -0
- package/s/repeat.ts +25 -0
- package/s/tests.test.ts +21 -0
- package/s/time.ts +22 -0
- package/x/clone/clone.test.d.ts +15 -1
- package/x/clone/clone.test.js +106 -124
- package/x/clone/clone.test.js.map +1 -1
- package/x/coalesce.d.ts +1 -0
- package/x/coalesce.js +1 -0
- package/x/coalesce.js.map +1 -1
- package/x/data/base-x.d.ts +47 -0
- package/x/data/base-x.js +147 -0
- package/x/data/base-x.js.map +1 -0
- package/x/data/base58.d.ts +5 -1
- package/x/data/base58.js +13 -5
- package/x/data/base58.js.map +1 -1
- package/x/data/base64.d.ts +7 -3
- package/x/data/base64.js +13 -5
- package/x/data/base64.js.map +1 -1
- package/x/data/base64url.d.ts +5 -1
- package/x/data/base64url.js +13 -5
- package/x/data/base64url.js.map +1 -1
- package/x/data/bytename/bytename.d.ts +19 -0
- package/x/data/{barname/barname.js → bytename/bytename.js} +27 -11
- package/x/data/bytename/bytename.js.map +1 -0
- package/x/data/bytename/bytename.test.d.ts +17 -0
- package/x/data/bytename/bytename.test.js +41 -0
- package/x/data/bytename/bytename.test.js.map +1 -0
- package/x/data/bytename/index.d.ts +2 -0
- package/x/data/bytename/index.js +3 -0
- package/x/data/bytename/index.js.map +1 -0
- package/x/data/bytename/thumbprint.d.ts +36 -0
- package/x/data/bytename/thumbprint.js +79 -0
- package/x/data/bytename/thumbprint.js.map +1 -0
- package/x/data/bytename/thumbprint.test.d.ts +24 -0
- package/x/data/bytename/thumbprint.test.js +45 -0
- package/x/data/bytename/thumbprint.test.js.map +1 -0
- package/x/data/bytename/utils/prefixes.js.map +1 -0
- package/x/data/bytename/utils/suffixes.js.map +1 -0
- package/x/data/bytes.d.ts +3 -2
- package/x/data/bytes.js +11 -2
- package/x/data/bytes.js.map +1 -1
- package/x/data/data.test.d.ts +69 -0
- package/x/data/data.test.js +77 -0
- package/x/data/data.test.js.map +1 -0
- package/x/data/hex.d.ts +8 -4
- package/x/data/hex.js +13 -5
- package/x/data/hex.js.map +1 -1
- package/x/data/txt.d.ts +6 -2
- package/x/data/txt.js +12 -4
- package/x/data/txt.js.map +1 -1
- package/x/debounce/debounce.test.d.ts +8 -1
- package/x/debounce/debounce.test.js +70 -74
- package/x/debounce/debounce.test.js.map +1 -1
- package/x/deep/deep.test.d.ts +21 -1
- package/x/deep/deep.test.js +5 -9
- package/x/deep/deep.test.js.map +1 -1
- package/x/deep/parts/equal.test.d.ts +19 -1
- package/x/deep/parts/equal.test.js +107 -125
- package/x/deep/parts/equal.test.js.map +1 -1
- package/x/{defer-promise.d.ts → defer.d.ts} +2 -2
- package/x/{defer-promise.js → defer.js} +2 -2
- package/x/defer.js.map +1 -0
- package/x/drill.d.ts +1 -3
- package/x/drill.js +2 -4
- package/x/drill.js.map +1 -1
- package/x/ev.d.ts +6 -0
- package/x/ev.js +10 -0
- package/x/ev.js.map +1 -0
- package/x/id-counter.d.ts +5 -0
- package/x/id-counter.js +10 -0
- package/x/id-counter.js.map +1 -0
- package/x/index.d.ts +13 -2
- package/x/index.js +13 -2
- package/x/index.js.map +1 -1
- package/x/is.d.ts +6 -4
- package/x/is.js +6 -4
- package/x/is.js.map +1 -1
- package/x/loopy.d.ts +2 -0
- package/x/loopy.js +10 -0
- package/x/loopy.js.map +1 -0
- package/x/map-g.d.ts +3 -3
- package/x/map-g.js +1 -1
- package/x/map-g.js.map +1 -1
- package/x/nap.d.ts +1 -0
- package/x/nap.js +1 -0
- package/x/nap.js.map +1 -1
- package/x/once.d.ts +1 -0
- package/x/once.js +12 -0
- package/x/once.js.map +1 -0
- package/x/pubsub.d.ts +12 -1
- package/x/pubsub.js +7 -5
- package/x/pubsub.js.map +1 -1
- package/x/queue/queue.d.ts +4 -0
- package/x/queue/queue.js +14 -0
- package/x/queue/queue.js.map +1 -0
- package/x/queue/queue.test.d.ts +8 -0
- package/x/queue/queue.test.js +57 -0
- package/x/queue/queue.test.js.map +1 -0
- package/x/repeat.d.ts +5 -0
- package/x/repeat.js +23 -0
- package/x/repeat.js.map +1 -0
- package/x/tests.test.js +18 -0
- package/x/tests.test.js.map +1 -0
- package/x/time.d.ts +18 -0
- package/x/time.js +19 -0
- package/x/time.js.map +1 -0
- package/readme.md +0 -85
- package/s/data/anka.ts +0 -66
- package/s/data/barname/badge.ts +0 -78
- package/s/data/barname/demo.ts +0 -49
- package/s/data/barname/index.ts +0 -4
- package/x/data/anka.d.ts +0 -5
- package/x/data/anka.js +0 -53
- package/x/data/anka.js.map +0 -1
- package/x/data/barname/badge.d.ts +0 -25
- package/x/data/barname/badge.js +0 -64
- package/x/data/barname/badge.js.map +0 -1
- package/x/data/barname/barname.d.ts +0 -7
- package/x/data/barname/barname.js.map +0 -1
- package/x/data/barname/demo.js +0 -45
- package/x/data/barname/demo.js.map +0 -1
- package/x/data/barname/index.d.ts +0 -2
- package/x/data/barname/index.js +0 -3
- package/x/data/barname/index.js.map +0 -1
- package/x/data/barname/utils/prefixes.js.map +0 -1
- package/x/data/barname/utils/suffixes.js.map +0 -1
- package/x/defer-promise.js.map +0 -1
- /package/{license → LICENSE} +0 -0
- /package/s/data/{barname → bytename}/utils/prefixes.ts +0 -0
- /package/s/data/{barname → bytename}/utils/suffixes.ts +0 -0
- /package/x/data/{barname → bytename}/utils/prefixes.d.ts +0 -0
- /package/x/data/{barname → bytename}/utils/prefixes.js +0 -0
- /package/x/data/{barname → bytename}/utils/suffixes.d.ts +0 -0
- /package/x/data/{barname → bytename}/utils/suffixes.js +0 -0
- /package/x/{data/barname/demo.d.ts → tests.test.d.ts} +0 -0
package/x/pubsub.d.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
export type Listener<A extends any[]> = (...a: A) => (void | Promise<void>);
|
|
2
2
|
export interface Xub<A extends any[] = []> {
|
|
3
|
+
/** publish to all subscribed listeners. */
|
|
3
4
|
pub(...a: A): Promise<void>;
|
|
5
|
+
/** subscribe a listener function. */
|
|
4
6
|
sub(fn: Listener<A>): () => void;
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* subscribe a listener function.
|
|
9
|
+
* @alias sub
|
|
10
|
+
*/
|
|
11
|
+
on(fn: Listener<A>): () => void;
|
|
12
|
+
/** wait for the next published value */
|
|
13
|
+
next(): Promise<A>;
|
|
14
|
+
/** wipe all listeners attached to this. */
|
|
6
15
|
clear(): void;
|
|
7
16
|
}
|
|
17
|
+
/** subscriber fn that can be published to. */
|
|
8
18
|
export interface Sub<A extends any[] = []> extends Xub<A> {
|
|
9
19
|
(fn: Listener<A>): () => void;
|
|
10
20
|
}
|
|
21
|
+
/** publisher fn that can be published to. */
|
|
11
22
|
export interface Pub<A extends any[] = []> extends Xub<A> {
|
|
12
23
|
(...a: A): Promise<void>;
|
|
13
24
|
}
|
package/x/pubsub.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defer } from "./defer.js";
|
|
2
2
|
export function xub() {
|
|
3
3
|
const set = new Set();
|
|
4
4
|
function sub(fn) {
|
|
@@ -8,8 +8,8 @@ export function xub() {
|
|
|
8
8
|
async function pub(...a) {
|
|
9
9
|
await Promise.all([...set].map(fn => fn(...a)));
|
|
10
10
|
}
|
|
11
|
-
async function
|
|
12
|
-
const { promise, resolve } =
|
|
11
|
+
async function next() {
|
|
12
|
+
const { promise, resolve } = defer();
|
|
13
13
|
const unsubscribe = sub((...a) => {
|
|
14
14
|
resolve(a);
|
|
15
15
|
unsubscribe();
|
|
@@ -21,11 +21,13 @@ export function xub() {
|
|
|
21
21
|
}
|
|
22
22
|
sub.pub = pub;
|
|
23
23
|
sub.sub = sub;
|
|
24
|
-
sub.
|
|
24
|
+
sub.on = sub;
|
|
25
|
+
sub.next = next;
|
|
25
26
|
sub.clear = clear;
|
|
26
27
|
pub.pub = pub;
|
|
27
28
|
pub.sub = sub;
|
|
28
|
-
pub.
|
|
29
|
+
pub.on = sub;
|
|
30
|
+
pub.next = next;
|
|
29
31
|
pub.clear = clear;
|
|
30
32
|
return [pub, sub];
|
|
31
33
|
}
|
package/x/pubsub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../s/pubsub.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../s/pubsub.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAmChC,MAAM,UAAU,GAAG;IAClB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAe,CAAA;IAElC,SAAS,GAAG,CAAC,EAAe;QAC3B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACX,OAAO,GAAG,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA,CAAC,CAAC,CAAA;IAChC,CAAC;IAED,KAAK,UAAU,GAAG,CAAC,GAAG,CAAI;QACzB,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,KAAK,UAAU,IAAI;QAClB,MAAM,EAAC,OAAO,EAAE,OAAO,EAAC,GAAG,KAAK,EAAK,CAAA;QACrC,MAAM,WAAW,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE;YAChC,OAAO,CAAC,CAAC,CAAC,CAAA;YACV,WAAW,EAAE,CAAA;QACd,CAAC,CAAC,CAAA;QACF,OAAO,OAAO,CAAA;IACf,CAAC;IAED,SAAS,KAAK;QACb,GAAG,CAAC,KAAK,EAAE,CAAA;IACZ,CAAC;IAED,GAAG,CAAC,GAAG,GAAG,GAAG,CAAA;IACb,GAAG,CAAC,GAAG,GAAG,GAAG,CAAA;IACb,GAAG,CAAC,EAAE,GAAG,GAAG,CAAA;IACZ,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;IACf,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;IAEjB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAA;IACb,GAAG,CAAC,GAAG,GAAG,GAAG,CAAA;IACb,GAAG,CAAC,EAAE,GAAG,GAAG,CAAA;IACZ,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;IACf,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;IAEjB,OAAO,CAAC,GAAG,EAAE,GAAG,CAAqB,CAAA;AACtC,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,GAAG,CAAuB,QAAsB;IAC/D,MAAM,EAAE,GAAG,GAAG,EAAK,CAAC,CAAC,CAAC,CAAA;IACtB,IAAI,QAAQ;QACX,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACjB,OAAO,EAAE,CAAA;AACV,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,GAAG,CAAuB,QAAsB;IAC/D,MAAM,EAAE,GAAG,GAAG,EAAK,CAAC,CAAC,CAAC,CAAA;IACtB,IAAI,QAAQ;QACX,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACjB,OAAO,EAAE,CAAA;AACV,CAAC"}
|
package/x/queue/queue.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* create a job queue that ensures the given fn is always called in sequence (not concurrently).
|
|
3
|
+
*/
|
|
4
|
+
export function queue(fn) {
|
|
5
|
+
let last = Promise.resolve();
|
|
6
|
+
return (...args) => {
|
|
7
|
+
const job = () => fn(...args);
|
|
8
|
+
const current = last.then(job);
|
|
9
|
+
// prevent unhandled rejection breaking the chain
|
|
10
|
+
last = current.catch(() => { });
|
|
11
|
+
return current;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../s/queue/queue.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,UAAU,KAAK,CACnB,EAAsC;IAGvC,IAAI,IAAI,GAAiB,OAAO,CAAC,OAAO,EAAE,CAAA;IAE1C,OAAO,CAAC,GAAG,IAAU,EAAmB,EAAE;QACzC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAE9B,iDAAiD;QACjD,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAE9B,OAAO,OAAO,CAAA;IACf,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Science } from "@e280/science";
|
|
2
|
+
declare const _default: {
|
|
3
|
+
"job runs": Science.Test;
|
|
4
|
+
"sequencing is enforced": Science.Test;
|
|
5
|
+
"params and return values seem to work": Science.Test;
|
|
6
|
+
"first job throws, second job unaffected": Science.Test;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Science, expect } from "@e280/science";
|
|
2
|
+
import { nap } from "../nap.js";
|
|
3
|
+
import { queue } from "./queue.js";
|
|
4
|
+
export default Science.suite({
|
|
5
|
+
"job runs": Science.test(async () => {
|
|
6
|
+
let concurrent = 0;
|
|
7
|
+
const job = queue(async () => {
|
|
8
|
+
concurrent++;
|
|
9
|
+
await nap(100);
|
|
10
|
+
concurrent--;
|
|
11
|
+
});
|
|
12
|
+
const promise1 = job();
|
|
13
|
+
await nap(50);
|
|
14
|
+
expect(concurrent).is(1);
|
|
15
|
+
await promise1;
|
|
16
|
+
expect(concurrent).is(0);
|
|
17
|
+
}),
|
|
18
|
+
"sequencing is enforced": Science.test(async () => {
|
|
19
|
+
let concurrent = 0;
|
|
20
|
+
const job = queue(async () => {
|
|
21
|
+
concurrent++;
|
|
22
|
+
await nap(100);
|
|
23
|
+
concurrent--;
|
|
24
|
+
});
|
|
25
|
+
const promise1 = job();
|
|
26
|
+
const promise2 = job();
|
|
27
|
+
await nap(50);
|
|
28
|
+
expect(concurrent).is(1);
|
|
29
|
+
await promise1;
|
|
30
|
+
await nap(50);
|
|
31
|
+
expect(concurrent).is(1);
|
|
32
|
+
await promise2;
|
|
33
|
+
expect(concurrent).is(0);
|
|
34
|
+
}),
|
|
35
|
+
"params and return values seem to work": Science.test(async () => {
|
|
36
|
+
const add = queue(async (a, b) => {
|
|
37
|
+
await nap(100);
|
|
38
|
+
return a + b;
|
|
39
|
+
});
|
|
40
|
+
const promise1 = add(1, 2);
|
|
41
|
+
const promise2 = add(10, 20);
|
|
42
|
+
expect(await promise1).is(3);
|
|
43
|
+
expect(await promise2).is(30);
|
|
44
|
+
}),
|
|
45
|
+
"first job throws, second job unaffected": Science.test(async () => {
|
|
46
|
+
let run = 0;
|
|
47
|
+
const job = queue(async () => {
|
|
48
|
+
run++;
|
|
49
|
+
await nap(100);
|
|
50
|
+
if (run === 1)
|
|
51
|
+
throw new Error("first job failed");
|
|
52
|
+
});
|
|
53
|
+
expect(async () => job()).throwsAsync();
|
|
54
|
+
expect(async () => job()).not.throwsAsync();
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=queue.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.test.js","sourceRoot":"","sources":["../../s/queue/queue.test.ts"],"names":[],"mappings":"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"}
|
package/x/repeat.d.ts
ADDED
package/x/repeat.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* repeat the given async function over and over.
|
|
3
|
+
* - consider using `nap` in your fn to create a delay
|
|
4
|
+
*/
|
|
5
|
+
export function repeat(fn) {
|
|
6
|
+
let timeout;
|
|
7
|
+
let stopped = false;
|
|
8
|
+
const stop = () => {
|
|
9
|
+
stopped = true;
|
|
10
|
+
clearTimeout(timeout);
|
|
11
|
+
};
|
|
12
|
+
const tick = async () => {
|
|
13
|
+
if (stopped)
|
|
14
|
+
return;
|
|
15
|
+
await fn(stop);
|
|
16
|
+
if (stopped)
|
|
17
|
+
return;
|
|
18
|
+
timeout = setTimeout(tick, 0);
|
|
19
|
+
};
|
|
20
|
+
tick();
|
|
21
|
+
return stop;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=repeat.js.map
|
package/x/repeat.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repeat.js","sourceRoot":"","sources":["../s/repeat.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,EAAuC;IAC7D,IAAI,OAAY,CAAA;IAChB,IAAI,OAAO,GAAG,KAAK,CAAA;IAEnB,MAAM,IAAI,GAAG,GAAG,EAAE;QACjB,OAAO,GAAG,IAAI,CAAA;QACd,YAAY,CAAC,OAAO,CAAC,CAAA;IACtB,CAAC,CAAA;IAED,MAAM,IAAI,GAAG,KAAK,IAAG,EAAE;QACtB,IAAI,OAAO;YAAE,OAAM;QACnB,MAAM,EAAE,CAAC,IAAI,CAAC,CAAA;QACd,IAAI,OAAO;YAAE,OAAM;QACnB,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IAC9B,CAAC,CAAA;IAED,IAAI,EAAE,CAAA;IACN,OAAO,IAAI,CAAA;AACZ,CAAC"}
|
package/x/tests.test.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Science } from "@e280/science";
|
|
2
|
+
import clone from "./clone/clone.test.js";
|
|
3
|
+
import thumbprint from "./data/bytename/thumbprint.test.js";
|
|
4
|
+
import debounce from "./debounce/debounce.test.js";
|
|
5
|
+
import bytename from "./data/bytename/bytename.test.js";
|
|
6
|
+
import deep from "./deep/deep.test.js";
|
|
7
|
+
import data from "./data/data.test.js";
|
|
8
|
+
import queue from "./queue/queue.test.js";
|
|
9
|
+
await Science.run({
|
|
10
|
+
clone,
|
|
11
|
+
bytename,
|
|
12
|
+
thumbprint,
|
|
13
|
+
debounce,
|
|
14
|
+
deep,
|
|
15
|
+
data,
|
|
16
|
+
queue,
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=tests.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tests.test.js","sourceRoot":"","sources":["../s/tests.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,OAAO,KAAK,MAAM,uBAAuB,CAAA;AACzC,OAAO,UAAU,MAAM,oCAAoC,CAAA;AAC3D,OAAO,QAAQ,MAAM,6BAA6B,CAAA;AAClD,OAAO,QAAQ,MAAM,kCAAkC,CAAA;AACvD,OAAO,IAAI,MAAM,qBAAqB,CAAA;AACtC,OAAO,IAAI,MAAM,qBAAqB,CAAA;AACtC,OAAO,KAAK,MAAM,uBAAuB,CAAA;AAEzC,MAAM,OAAO,CAAC,GAAG,CAAC;IACjB,KAAK;IACL,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,IAAI;IACJ,IAAI;IACJ,KAAK;CACL,CAAC,CAAA"}
|
package/x/time.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const Time: {
|
|
2
|
+
seconds: (n: number) => number;
|
|
3
|
+
minutes: (n: number) => number;
|
|
4
|
+
hours: (n: number) => number;
|
|
5
|
+
days: (n: number) => number;
|
|
6
|
+
future: {
|
|
7
|
+
seconds: (n: number) => number;
|
|
8
|
+
minutes: (n: number) => number;
|
|
9
|
+
hours: (n: number) => number;
|
|
10
|
+
days: (n: number) => number;
|
|
11
|
+
};
|
|
12
|
+
past: {
|
|
13
|
+
seconds: (n: number) => number;
|
|
14
|
+
minutes: (n: number) => number;
|
|
15
|
+
hours: (n: number) => number;
|
|
16
|
+
days: (n: number) => number;
|
|
17
|
+
};
|
|
18
|
+
};
|
package/x/time.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const Time = {
|
|
2
|
+
seconds: (n) => (n * 1000),
|
|
3
|
+
minutes: (n) => (n * Time.seconds(60)),
|
|
4
|
+
hours: (n) => (n * Time.minutes(60)),
|
|
5
|
+
days: (n) => (n * Time.hours(24)),
|
|
6
|
+
future: {
|
|
7
|
+
seconds: (n) => (Date.now() + Time.seconds(n)),
|
|
8
|
+
minutes: (n) => (Date.now() + Time.minutes(n)),
|
|
9
|
+
hours: (n) => (Date.now() + Time.hours(n)),
|
|
10
|
+
days: (n) => (Date.now() + Time.days(n)),
|
|
11
|
+
},
|
|
12
|
+
past: {
|
|
13
|
+
seconds: (n) => (Date.now() - Time.seconds(n)),
|
|
14
|
+
minutes: (n) => (Date.now() - Time.minutes(n)),
|
|
15
|
+
hours: (n) => (Date.now() - Time.hours(n)),
|
|
16
|
+
days: (n) => (Date.now() - Time.days(n)),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=time.js.map
|
package/x/time.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../s/time.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,IAAI,GAAG;IACnB,OAAO,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC9C,KAAK,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC5C,IAAI,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAEzC,MAAM,EAAE;QACP,OAAO,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACtD,OAAO,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACtD,KAAK,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClD,IAAI,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAChD;IAED,IAAI,EAAE;QACL,OAAO,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACtD,OAAO,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACtD,KAAK,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClD,IAAI,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAChD;CACD,CAAA"}
|
package/readme.md
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# `@e280/stz`
|
|
3
|
-
standard library of environment-agnostic typescript functions we use basically everywhere
|
|
4
|
-
|
|
5
|
-
<br/>
|
|
6
|
-
|
|
7
|
-
## the tools
|
|
8
|
-
stz has many more tools than documented below, see their [sourcecode here in s/](./s/)
|
|
9
|
-
|
|
10
|
-
### MapG — an extension of js Map with handy methods
|
|
11
|
-
- `map.require`
|
|
12
|
-
```ts
|
|
13
|
-
import {MapG} from "@e280/stz"
|
|
14
|
-
|
|
15
|
-
const map = new MapG<number, string>([
|
|
16
|
-
[1, "hello"],
|
|
17
|
-
[2, "world"],
|
|
18
|
-
])
|
|
19
|
-
|
|
20
|
-
// throws error if the value is undefined
|
|
21
|
-
const value = map.require(1)
|
|
22
|
-
```
|
|
23
|
-
- `map.guarantee`
|
|
24
|
-
```ts
|
|
25
|
-
// if the value is undefined, the new value "rofl" is set and returned
|
|
26
|
-
const value = map.guarantee(3, () => "rofl")
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### pub and sub — minimal ergonomic event system
|
|
30
|
-
- make a publisher fn
|
|
31
|
-
```ts
|
|
32
|
-
import {pub} from "@e280/stz"
|
|
33
|
-
|
|
34
|
-
// create a pub fn
|
|
35
|
-
const sendMessage = pub<[string]>()
|
|
36
|
-
|
|
37
|
-
// subscribe to it
|
|
38
|
-
sendMessage.sub(m => console.log(m))
|
|
39
|
-
|
|
40
|
-
// publish to it
|
|
41
|
-
sendMessage("hello")
|
|
42
|
-
```
|
|
43
|
-
- make a subscriber fn *(see how it's just the reverse of pub?)*
|
|
44
|
-
```ts
|
|
45
|
-
import {sub} from "@e280/stz"
|
|
46
|
-
|
|
47
|
-
// create a sub fn
|
|
48
|
-
const onMessage = sub<[string]>()
|
|
49
|
-
|
|
50
|
-
// subscribe to it
|
|
51
|
-
onMessage(m => console.log(m))
|
|
52
|
-
|
|
53
|
-
// publish to it
|
|
54
|
-
onMessage.pub("hello")
|
|
55
|
-
```
|
|
56
|
-
- the pub and sub are the same, but have differing invoke signatures
|
|
57
|
-
- i seem to use `sub` more often
|
|
58
|
-
- both have some extra functionality
|
|
59
|
-
```ts
|
|
60
|
-
// pub fns return a promise, to wait for all async subscribers
|
|
61
|
-
await sendMessage("hello")
|
|
62
|
-
await onMessage.pub("hello")
|
|
63
|
-
|
|
64
|
-
// sub fns return an unsub fn
|
|
65
|
-
const unsub1 = onMessage(m => console.log(m))
|
|
66
|
-
unsub1() // unsubscribe that listener
|
|
67
|
-
|
|
68
|
-
const unsub2 = sendMessage.sub(m => console.log(m))
|
|
69
|
-
unsub2() // unsubscribe that listener
|
|
70
|
-
|
|
71
|
-
// you can clear all subscribers from a pub or a sub
|
|
72
|
-
sendMessage.clear()
|
|
73
|
-
onMessage.clear()
|
|
74
|
-
|
|
75
|
-
// you can subscribe to only one next call
|
|
76
|
-
onMessage.once(m => console.log(m))
|
|
77
|
-
sendMessage.once(m => console.log(m))
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
<br/>
|
|
81
|
-
|
|
82
|
-
## 💖 made with open source love
|
|
83
|
-
reward us with github stars
|
|
84
|
-
build with us at https://e280.org/ but only if you're cool
|
|
85
|
-
|
package/s/data/anka.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/*
|
|
3
|
-
|
|
4
|
-
"anka" is an alternative to base64 that i totally made up.
|
|
5
|
-
- it looks cool because it features characters from the indian subcontinent.
|
|
6
|
-
- each byte is represented by one character, which makes a 256 bit id incomparably short at only 32 characters.
|
|
7
|
-
- however, it's probably a bad idea, for these negative reasons:
|
|
8
|
-
1. many of these characters are actually 2-or-3-byte sequences (so even though anka is visually more compact than base64 to the user, it's actually more data in terms of bytes).
|
|
9
|
-
2. it's horrible for url-encoding.
|
|
10
|
-
3. it's horrible for trying to manually copy by typing.
|
|
11
|
-
|
|
12
|
-
256-bit anka ids look like this:
|
|
13
|
-
|
|
14
|
-
ஒഐওଆઊসਅവஎଉखਬശயഘसചവਭଏரঊझഠடଓઐഴঠണവઞ
|
|
15
|
-
ठକநइஎਦਏஒഊটਹஜഴयભকயঙਪഉजकঝഐवઠসഏਓਡਟऋ
|
|
16
|
-
થঞठખஉધഫரਜऐફരਪਙਗഭਣഎफઇমએরଔડਉதਤஅदઘച
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import {Bytes} from "./bytes.js"
|
|
21
|
-
|
|
22
|
-
const characters = [...new Set([
|
|
23
|
-
// devanagari
|
|
24
|
-
..."अआइईउऊऋएऐओऔकखगघङचछजझञटठडढणतथदधनपफबभमयरलवशषसह",
|
|
25
|
-
|
|
26
|
-
// tamil
|
|
27
|
-
..."அஆஇஈஉஊஎஏஐஒஓகஙசஜஞடணதநபமயரலவழளறன",
|
|
28
|
-
|
|
29
|
-
// bengali
|
|
30
|
-
..."অআইঈউঊএঐওকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ",
|
|
31
|
-
|
|
32
|
-
// gurmukhi
|
|
33
|
-
..."ਅਆਇਈਉਊਏਐਓਕਖਗਘਙਚਛਜਝਞਟਠਡਢਣਤਥਦਧਨਪਫਬਭਮਯਰਲਵਸਹ",
|
|
34
|
-
|
|
35
|
-
// malayalam
|
|
36
|
-
..."അആഇഈഉഊഎഏഐഒഓകഖഗഘങചഛജഝഞടഠഡഢണതഥദധനപഫബഭമയരലവശസഹളഴറ",
|
|
37
|
-
|
|
38
|
-
// gujarati
|
|
39
|
-
..."અઆઇઈઉઊએઐઓકખગઘઙચછજઝઞટઠડઢણતથદધનપફબભમયરલવશષસહ",
|
|
40
|
-
|
|
41
|
-
// odia
|
|
42
|
-
..."ଅଆଇଈଉଊଏଐଓଔକଖଗଘଙଚଛଜଝଞଟଠଡଢଣତଥଦଧନପଫବଭମଯରଲଶଷସହ",
|
|
43
|
-
])]
|
|
44
|
-
|
|
45
|
-
export const Anka = Object.freeze({
|
|
46
|
-
|
|
47
|
-
string(bytes: Uint8Array) {
|
|
48
|
-
return [...bytes]
|
|
49
|
-
.map(int => characters.at(int))
|
|
50
|
-
.join("")
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
bytes(code: string) {
|
|
54
|
-
return new Uint8Array([...code].map(char => {
|
|
55
|
-
const index = characters.indexOf(char)
|
|
56
|
-
if (index === -1)
|
|
57
|
-
throw new Error(`invalid anka character "${char}"`)
|
|
58
|
-
return index
|
|
59
|
-
}))
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
random(count = 32) {
|
|
63
|
-
return this.string(Bytes.random(count))
|
|
64
|
-
},
|
|
65
|
-
})
|
|
66
|
-
|
package/s/data/barname/badge.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {Hex} from "../hex.js"
|
|
3
|
-
import {Base58} from "../base58.js"
|
|
4
|
-
import {Barname} from "./barname.js"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Badge is a human-friendly presentation format for arbitrary binary data.
|
|
8
|
-
* - looks like "nomluc_rigpem.tg2bjNkjMh1H6M2b2EhD5V4x6XAqx9wyWddsBt"
|
|
9
|
-
* - the first bytes are shown in barname format
|
|
10
|
-
* - the rest of the data is in base58
|
|
11
|
-
* - designed to be a nice way to present 256-bit passport thumbprints
|
|
12
|
-
* - can be used for data of different lengths
|
|
13
|
-
* - preview size can be customized as 'leadCount', which defaults to 4
|
|
14
|
-
*/
|
|
15
|
-
export class Badge {
|
|
16
|
-
static readonly separator = "."
|
|
17
|
-
static readonly defaultLeadCount = 4
|
|
18
|
-
|
|
19
|
-
readonly hex: string
|
|
20
|
-
readonly string: string
|
|
21
|
-
readonly preview: string
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
public readonly bytes: Uint8Array,
|
|
25
|
-
public readonly leadCount = Badge.defaultLeadCount,
|
|
26
|
-
) {
|
|
27
|
-
|
|
28
|
-
if (leadCount < 1)
|
|
29
|
-
throw new Error(`badge leadCount must be greater than 0 (was ${leadCount})`)
|
|
30
|
-
|
|
31
|
-
this.hex = Hex.string(this.bytes)
|
|
32
|
-
this.preview = Barname.string(this.bytes.slice(0, leadCount))
|
|
33
|
-
|
|
34
|
-
this.string = (bytes.length > leadCount)
|
|
35
|
-
? `${this.preview}.${Base58.string(this.bytes.slice(leadCount))}`
|
|
36
|
-
: this.preview
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static parse(badge: string) {
|
|
40
|
-
const [barname, b58] = badge.split(Badge.separator)
|
|
41
|
-
|
|
42
|
-
// badge has a base58 component
|
|
43
|
-
if (b58) {
|
|
44
|
-
const appetizer = Barname.bytes(barname)
|
|
45
|
-
const entree = Base58.bytes(b58)
|
|
46
|
-
const bytes = new Uint8Array([...appetizer, ...entree])
|
|
47
|
-
return new this(bytes, appetizer.length)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// badge is just a barname (no base58 part)
|
|
51
|
-
else {
|
|
52
|
-
const bytes = Barname.bytes(barname)
|
|
53
|
-
return new this(bytes, bytes.length)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static fromHex(hex: string, leadCount = this.defaultLeadCount) {
|
|
58
|
-
const bytes = Hex.bytes(hex)
|
|
59
|
-
return new this(bytes, leadCount)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static string(bytes: Uint8Array, leadCount = this.defaultLeadCount) {
|
|
63
|
-
return new this(bytes, leadCount).string
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static bytes(badge: string) {
|
|
67
|
-
return this.parse(badge)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static hex(badge: string) {
|
|
71
|
-
return this.parse(badge).hex
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
toString() {
|
|
75
|
-
return this.string
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
package/s/data/barname/demo.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {Hex} from "../hex.js"
|
|
3
|
-
import {Badge} from "./badge.js"
|
|
4
|
-
import {Bytes} from "../bytes.js"
|
|
5
|
-
import {Barname} from "./barname.js"
|
|
6
|
-
|
|
7
|
-
for (const _ of Array(2)) {
|
|
8
|
-
const string = Barname.random(34)
|
|
9
|
-
const bytes = Barname.bytes(string)
|
|
10
|
-
const string2 = Barname.string(bytes)
|
|
11
|
-
console.log(string.replaceAll(" ", "\n"))
|
|
12
|
-
if (string !== string2)
|
|
13
|
-
throw new Error("barname fails equality check")
|
|
14
|
-
console.log("")
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
for (const _ of Array(10)) {
|
|
18
|
-
const bytes = Bytes.random(32)
|
|
19
|
-
const badge = new Badge(bytes)
|
|
20
|
-
const bytes2 = badge.bytes
|
|
21
|
-
console.log(badge.string)
|
|
22
|
-
if (Hex.string(bytes) !== Hex.string(bytes2))
|
|
23
|
-
throw new Error("badge fails equality check")
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
console.log("")
|
|
28
|
-
const alpha = `
|
|
29
|
-
dacsyd_labdun_fipsub_bonmel
|
|
30
|
-
fitlys_rovbud_sipnel_sonryx
|
|
31
|
-
sitrem_lasdyr_dovpun_nibwep
|
|
32
|
-
tippet_mapnub_ticnet_famset
|
|
33
|
-
wanteg
|
|
34
|
-
`
|
|
35
|
-
const bravo = `
|
|
36
|
-
dacsyd-labdun-fipsub-bonmel;
|
|
37
|
-
[fitlys rovbud sipnel sonryx]
|
|
38
|
-
sitrem/lasdyr/dovpun/nibwep
|
|
39
|
-
tippet+mapnub+ticnet+famset
|
|
40
|
-
wanteg++
|
|
41
|
-
`
|
|
42
|
-
const alphaHex = Hex.string(Barname.bytes(alpha))
|
|
43
|
-
const bravoHex = Hex.string(Barname.bytes(bravo))
|
|
44
|
-
if (alphaHex.length === 68 && alphaHex === bravoHex)
|
|
45
|
-
console.log("*barname parsing appears resilient to whitespace and garbage*")
|
|
46
|
-
else
|
|
47
|
-
throw new Error("barname resiliency failure")
|
|
48
|
-
}
|
|
49
|
-
|
package/s/data/barname/index.ts
DELETED
package/x/data/anka.d.ts
DELETED
package/x/data/anka.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
"anka" is an alternative to base64 that i totally made up.
|
|
4
|
-
- it looks cool because it features characters from the indian subcontinent.
|
|
5
|
-
- each byte is represented by one character, which makes a 256 bit id incomparably short at only 32 characters.
|
|
6
|
-
- however, it's probably a bad idea, for these negative reasons:
|
|
7
|
-
1. many of these characters are actually 2-or-3-byte sequences (so even though anka is visually more compact than base64 to the user, it's actually more data in terms of bytes).
|
|
8
|
-
2. it's horrible for url-encoding.
|
|
9
|
-
3. it's horrible for trying to manually copy by typing.
|
|
10
|
-
|
|
11
|
-
256-bit anka ids look like this:
|
|
12
|
-
|
|
13
|
-
ஒഐওଆઊসਅവஎଉखਬശயഘसചവਭଏரঊझഠடଓઐഴঠണവઞ
|
|
14
|
-
ठକநइஎਦਏஒഊটਹஜഴयભকயঙਪഉजकঝഐवઠসഏਓਡਟऋ
|
|
15
|
-
થঞठખஉધഫரਜऐફരਪਙਗഭਣഎफઇমએরଔડਉதਤஅदઘച
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
import { Bytes } from "./bytes.js";
|
|
19
|
-
const characters = [...new Set([
|
|
20
|
-
// devanagari
|
|
21
|
-
..."अआइईउऊऋएऐओऔकखगघङचछजझञटठडढणतथदधनपफबभमयरलवशषसह",
|
|
22
|
-
// tamil
|
|
23
|
-
..."அஆஇஈஉஊஎஏஐஒஓகஙசஜஞடணதநபமயரலவழளறன",
|
|
24
|
-
// bengali
|
|
25
|
-
..."অআইঈউঊএঐওকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ",
|
|
26
|
-
// gurmukhi
|
|
27
|
-
..."ਅਆਇਈਉਊਏਐਓਕਖਗਘਙਚਛਜਝਞਟਠਡਢਣਤਥਦਧਨਪਫਬਭਮਯਰਲਵਸਹ",
|
|
28
|
-
// malayalam
|
|
29
|
-
..."അആഇഈഉഊഎഏഐഒഓകഖഗഘങചഛജഝഞടഠഡഢണതഥദധനപഫബഭമയരലവശസഹളഴറ",
|
|
30
|
-
// gujarati
|
|
31
|
-
..."અઆઇઈઉઊએઐઓકખગઘઙચછજઝઞટઠડઢણતથદધનપફબભમયરલવશષસહ",
|
|
32
|
-
// odia
|
|
33
|
-
..."ଅଆଇଈଉଊଏଐଓଔକଖଗଘଙଚଛଜଝଞଟଠଡଢଣତଥଦଧନପଫବଭମଯରଲଶଷସହ",
|
|
34
|
-
])];
|
|
35
|
-
export const Anka = Object.freeze({
|
|
36
|
-
string(bytes) {
|
|
37
|
-
return [...bytes]
|
|
38
|
-
.map(int => characters.at(int))
|
|
39
|
-
.join("");
|
|
40
|
-
},
|
|
41
|
-
bytes(code) {
|
|
42
|
-
return new Uint8Array([...code].map(char => {
|
|
43
|
-
const index = characters.indexOf(char);
|
|
44
|
-
if (index === -1)
|
|
45
|
-
throw new Error(`invalid anka character "${char}"`);
|
|
46
|
-
return index;
|
|
47
|
-
}));
|
|
48
|
-
},
|
|
49
|
-
random(count = 32) {
|
|
50
|
-
return this.string(Bytes.random(count));
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
//# sourceMappingURL=anka.js.map
|
package/x/data/anka.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anka.js","sourceRoot":"","sources":["../../s/data/anka.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;EAgBE;AAEF,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAEhC,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC;QAC9B,aAAa;QACb,GAAG,8CAA8C;QAEjD,QAAQ;QACR,GAAG,gCAAgC;QAEnC,UAAU;QACV,GAAG,2CAA2C;QAE9C,WAAW;QACX,GAAG,0CAA0C;QAE7C,YAAY;QACZ,GAAG,gDAAgD;QAEnD,WAAW;QACX,GAAG,4CAA4C;QAE/C,OAAO;QACP,GAAG,4CAA4C;KAC/C,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;IAEjC,MAAM,CAAC,KAAiB;QACvB,OAAO,CAAC,GAAG,KAAK,CAAC;aACf,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;aAC9B,IAAI,CAAC,EAAE,CAAC,CAAA;IACX,CAAC;IAED,KAAK,CAAC,IAAY;QACjB,OAAO,IAAI,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YACtC,IAAI,KAAK,KAAK,CAAC,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAA;YACpD,OAAO,KAAK,CAAA;QACb,CAAC,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,GAAG,EAAE;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACxC,CAAC;CACD,CAAC,CAAA"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Badge is a human-friendly presentation format for arbitrary binary data.
|
|
3
|
-
* - looks like "nomluc_rigpem.tg2bjNkjMh1H6M2b2EhD5V4x6XAqx9wyWddsBt"
|
|
4
|
-
* - the first bytes are shown in barname format
|
|
5
|
-
* - the rest of the data is in base58
|
|
6
|
-
* - designed to be a nice way to present 256-bit passport thumbprints
|
|
7
|
-
* - can be used for data of different lengths
|
|
8
|
-
* - preview size can be customized as 'leadCount', which defaults to 4
|
|
9
|
-
*/
|
|
10
|
-
export declare class Badge {
|
|
11
|
-
readonly bytes: Uint8Array;
|
|
12
|
-
readonly leadCount: number;
|
|
13
|
-
static readonly separator = ".";
|
|
14
|
-
static readonly defaultLeadCount = 4;
|
|
15
|
-
readonly hex: string;
|
|
16
|
-
readonly string: string;
|
|
17
|
-
readonly preview: string;
|
|
18
|
-
constructor(bytes: Uint8Array, leadCount?: number);
|
|
19
|
-
static parse(badge: string): Badge;
|
|
20
|
-
static fromHex(hex: string, leadCount?: number): Badge;
|
|
21
|
-
static string(bytes: Uint8Array, leadCount?: number): string;
|
|
22
|
-
static bytes(badge: string): Badge;
|
|
23
|
-
static hex(badge: string): string;
|
|
24
|
-
toString(): string;
|
|
25
|
-
}
|