@welshman/lib 0.0.1

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.
Files changed (47) hide show
  1. package/README.md +11 -0
  2. package/build/Deferred.cjs +13 -0
  3. package/build/Deferred.cjs.map +1 -0
  4. package/build/Deferred.d.ts +5 -0
  5. package/build/Deferred.mjs +9 -0
  6. package/build/Deferred.mjs.map +1 -0
  7. package/build/Emitter.cjs +13 -0
  8. package/build/Emitter.cjs.map +1 -0
  9. package/build/Emitter.d.ts +4 -0
  10. package/build/Emitter.mjs +9 -0
  11. package/build/Emitter.mjs.map +1 -0
  12. package/build/Fluent.cjs +47 -0
  13. package/build/Fluent.cjs.map +1 -0
  14. package/build/Fluent.d.ts +34 -0
  15. package/build/Fluent.mjs +43 -0
  16. package/build/Fluent.mjs.map +1 -0
  17. package/build/LRUCache.cjs +49 -0
  18. package/build/LRUCache.cjs.map +1 -0
  19. package/build/LRUCache.d.ts +19 -0
  20. package/build/LRUCache.mjs +44 -0
  21. package/build/LRUCache.mjs.map +1 -0
  22. package/build/Store.cjs +220 -0
  23. package/build/Store.cjs.map +1 -0
  24. package/build/Store.d.ts +105 -0
  25. package/build/Store.mjs +205 -0
  26. package/build/Store.mjs.map +1 -0
  27. package/build/Tools.cjs +189 -0
  28. package/build/Tools.cjs.map +1 -0
  29. package/build/Tools.d.ts +61 -0
  30. package/build/Tools.mjs +141 -0
  31. package/build/Tools.mjs.map +1 -0
  32. package/build/Worker.cjs +67 -0
  33. package/build/Worker.cjs.map +1 -0
  34. package/build/Worker.d.ts +17 -0
  35. package/build/Worker.mjs +63 -0
  36. package/build/Worker.mjs.map +1 -0
  37. package/build/index.cjs +30 -0
  38. package/build/index.cjs.map +1 -0
  39. package/build/index.d.ts +8 -0
  40. package/build/index.mjs +9 -0
  41. package/build/index.mjs.map +1 -0
  42. package/build/normalize-url/index.cjs +254 -0
  43. package/build/normalize-url/index.cjs.map +1 -0
  44. package/build/normalize-url/index.d.ts +285 -0
  45. package/build/normalize-url/index.mjs +251 -0
  46. package/build/normalize-url/index.mjs.map +1 -0
  47. package/package.json +40 -0
@@ -0,0 +1,105 @@
1
+ type Invalidator<T> = (value?: T) => void;
2
+ type Derivable = Readable<any> | Readable<any>[];
3
+ type Subscriber<T> = (value: T) => void;
4
+ type Unsubscriber = () => void;
5
+ type R = Record<string, any>;
6
+ type M<T> = Map<string, T>;
7
+ export interface Readable<T> {
8
+ get: () => T;
9
+ subscribe(this: void, run: Subscriber<T>, invalidate?: Invalidator<T>): Unsubscriber;
10
+ derived: <U>(f: (v: T) => U) => Readable<U>;
11
+ throttle(t: number): Readable<T>;
12
+ }
13
+ export declare class Writable<T> implements Readable<T> {
14
+ private value;
15
+ private subs;
16
+ constructor(defaultValue: T, t?: number);
17
+ notify: () => void;
18
+ get(): T;
19
+ set(newValue: T): void;
20
+ update(f: (v: T) => T): void;
21
+ updateAsync(f: (v: T) => Promise<T>): Promise<void>;
22
+ subscribe(f: Subscriber<T>): () => void;
23
+ derived<U>(f: (v: T) => U): Derived<U>;
24
+ throttle: (t: number) => Derived<T>;
25
+ }
26
+ export declare class Derived<T> implements Readable<T> {
27
+ private callerSubs;
28
+ private mySubs;
29
+ private stores;
30
+ private getValue;
31
+ private latestValue;
32
+ constructor(stores: Derivable, getValue: (values: any) => T, t?: number);
33
+ notify: () => void;
34
+ getInput(): any;
35
+ get: () => T;
36
+ subscribe(f: Subscriber<T>): () => void;
37
+ derived<U>(f: (v: T) => U): Readable<U>;
38
+ throttle: (t: number) => Readable<T>;
39
+ }
40
+ export declare class Key<T extends R> implements Readable<T> {
41
+ readonly pk: string;
42
+ readonly key: string;
43
+ private base;
44
+ private store;
45
+ constructor(base: Writable<M<T>>, pk: string, key: string);
46
+ get: () => T;
47
+ subscribe: (f: Subscriber<T>) => Unsubscriber;
48
+ derived: <U>(f: (v: T) => U) => Readable<U>;
49
+ throttle: (t: number) => Readable<T>;
50
+ exists: () => boolean;
51
+ update: (f: (v: T) => T) => void;
52
+ set: (v: T) => void;
53
+ merge: (d: Partial<T>) => void;
54
+ remove: () => void;
55
+ pop: () => T;
56
+ }
57
+ export declare class DerivedKey<T extends R> implements Readable<T> {
58
+ readonly pk: string;
59
+ readonly key: string;
60
+ private base;
61
+ private store;
62
+ constructor(base: Readable<M<T>>, pk: string, key: string);
63
+ get: () => T;
64
+ subscribe: (f: Subscriber<T>) => Unsubscriber;
65
+ derived: <U>(f: (v: T) => U) => Readable<U>;
66
+ throttle: (t: number) => Readable<T>;
67
+ exists: () => boolean;
68
+ }
69
+ export declare class Collection<T extends R> implements Readable<T[]> {
70
+ readonly pk: string;
71
+ readonly mapStore: Writable<M<T>>;
72
+ readonly listStore: Readable<T[]>;
73
+ constructor(pk: string, t?: number);
74
+ get: () => T[];
75
+ getMap: () => M<T>;
76
+ subscribe: (f: Subscriber<T[]>) => Unsubscriber;
77
+ derived: <U>(f: (v: T[]) => U) => Readable<U>;
78
+ throttle: (t: number) => Readable<T[]>;
79
+ key: (k: string) => Key<T>;
80
+ set: (xs: T[]) => void;
81
+ update: (f: (v: T[]) => T[]) => void;
82
+ updateAsync: (f: (v: T[]) => Promise<T[]>) => Promise<void>;
83
+ reject: (f: (v: T) => boolean) => void;
84
+ filter: (f: (v: T) => boolean) => void;
85
+ map: (f: (v: T) => T) => void;
86
+ }
87
+ export declare class DerivedCollection<T extends R> implements Readable<T[]> {
88
+ readonly pk: string;
89
+ readonly listStore: Derived<T[]>;
90
+ readonly mapStore: Readable<M<T>>;
91
+ constructor(pk: string, stores: Derivable, getValue: (values: any) => T[], t?: number);
92
+ get: () => T[];
93
+ getMap: () => M<T>;
94
+ subscribe: (f: Subscriber<T[]>) => () => void;
95
+ derived: <U>(f: (v: T[]) => U) => Readable<U>;
96
+ throttle: (t: number) => Readable<T[]>;
97
+ key: (k: string) => DerivedKey<T>;
98
+ }
99
+ export declare const writable: <T>(v: T) => Writable<T>;
100
+ export declare const derived: <T>(stores: Derivable, getValue: (values: any) => T) => Derived<T>;
101
+ export declare const readable: <T>(v: T) => Readable<T>;
102
+ export declare const derivedCollection: <T extends R>(pk: string, stores: Derivable, getValue: (values: any) => T[]) => DerivedCollection<T>;
103
+ export declare const key: <T extends R>(base: Writable<M<T>>, pk: string, key: string) => Key<T>;
104
+ export declare const collection: <T extends R>(pk: string) => Collection<T>;
105
+ export {};
@@ -0,0 +1,205 @@
1
+ import { throttle } from "throttle-debounce";
2
+ import { ensurePlural, identity } from "./Tools.mjs";
3
+ export class Writable {
4
+ constructor(defaultValue, t) {
5
+ this.subs = [];
6
+ this.notify = () => {
7
+ for (const sub of this.subs) {
8
+ sub(this.value);
9
+ }
10
+ };
11
+ this.throttle = (t) => {
12
+ return new Derived(this, identity, t);
13
+ };
14
+ this.value = defaultValue;
15
+ if (t) {
16
+ this.notify = throttle(t, this.notify);
17
+ }
18
+ }
19
+ get() {
20
+ return this.value;
21
+ }
22
+ set(newValue) {
23
+ this.value = newValue;
24
+ this.notify();
25
+ }
26
+ update(f) {
27
+ this.set(f(this.value));
28
+ }
29
+ async updateAsync(f) {
30
+ this.set(await f(this.value));
31
+ }
32
+ subscribe(f) {
33
+ this.subs.push(f);
34
+ f(this.value);
35
+ return () => {
36
+ this.subs.splice(this.subs.findIndex(x => x === f), 1);
37
+ };
38
+ }
39
+ derived(f) {
40
+ return new Derived(this, f);
41
+ }
42
+ }
43
+ export class Derived {
44
+ constructor(stores, getValue, t = 0) {
45
+ this.callerSubs = [];
46
+ this.mySubs = [];
47
+ this.notify = () => {
48
+ this.latestValue = undefined;
49
+ this.callerSubs.forEach(f => f(this.get()));
50
+ };
51
+ this.get = () => {
52
+ // Recalculate if we're not subscribed, because we won't get notified when deps change
53
+ if (this.latestValue === undefined || this.mySubs.length === 0) {
54
+ this.latestValue = this.getValue(this.getInput());
55
+ }
56
+ return this.latestValue;
57
+ };
58
+ this.throttle = (t) => {
59
+ return new Derived(this, identity, t);
60
+ };
61
+ this.stores = stores;
62
+ this.getValue = getValue;
63
+ if (t) {
64
+ this.notify = throttle(t, this.notify);
65
+ }
66
+ }
67
+ getInput() {
68
+ if (Array.isArray(this.stores)) {
69
+ return this.stores.map(s => s.get());
70
+ }
71
+ else {
72
+ return this.stores.get();
73
+ }
74
+ }
75
+ subscribe(f) {
76
+ if (this.callerSubs.length === 0) {
77
+ for (const s of ensurePlural(this.stores)) {
78
+ this.mySubs.push(s.subscribe(this.notify));
79
+ }
80
+ }
81
+ this.callerSubs.push(f);
82
+ f(this.get());
83
+ return () => {
84
+ this.callerSubs.splice(this.callerSubs.findIndex(x => x === f), 1);
85
+ if (this.callerSubs.length === 0) {
86
+ for (const unsub of this.mySubs.splice(0)) {
87
+ unsub();
88
+ }
89
+ }
90
+ };
91
+ }
92
+ derived(f) {
93
+ return new Derived(this, f);
94
+ }
95
+ }
96
+ export class Key {
97
+ constructor(base, pk, key) {
98
+ this.get = () => this.base.get().get(this.key);
99
+ this.subscribe = (f) => this.store.subscribe(f);
100
+ this.derived = (f) => this.store.derived(f);
101
+ this.throttle = (t) => this.store.throttle(t);
102
+ this.exists = () => this.base.get().has(this.key);
103
+ this.update = (f) => this.base.update((m) => {
104
+ if (!this.key) {
105
+ throw new Error(`Cannot set key: "${this.key}"`);
106
+ }
107
+ // Make sure the pk always get set on the record
108
+ const { pk, key } = this;
109
+ const oldValue = { ...m.get(key), [pk]: key };
110
+ const newValue = { ...f(oldValue), [pk]: key };
111
+ m.set(this.key, newValue);
112
+ return m;
113
+ });
114
+ this.set = (v) => this.update(() => v);
115
+ this.merge = (d) => this.update(v => ({ ...v, ...d }));
116
+ this.remove = () => this.base.update(m => {
117
+ m.delete(this.key);
118
+ return m;
119
+ });
120
+ this.pop = () => {
121
+ const v = this.get();
122
+ this.remove();
123
+ return v;
124
+ };
125
+ if (!(base.get() instanceof Map)) {
126
+ throw new Error("`key` can only be used on map collections");
127
+ }
128
+ this.pk = pk;
129
+ this.key = key;
130
+ this.base = base;
131
+ this.store = base.derived(m => m.get(key));
132
+ }
133
+ }
134
+ export class DerivedKey {
135
+ constructor(base, pk, key) {
136
+ this.get = () => this.base.get().get(this.key);
137
+ this.subscribe = (f) => this.store.subscribe(f);
138
+ this.derived = (f) => this.store.derived(f);
139
+ this.throttle = (t) => this.store.throttle(t);
140
+ this.exists = () => this.base.get().has(this.key);
141
+ if (!(base.get() instanceof Map)) {
142
+ throw new Error("`key` can only be used on map collections");
143
+ }
144
+ this.pk = pk;
145
+ this.key = key;
146
+ this.base = base;
147
+ this.store = base.derived(m => m.get(key));
148
+ }
149
+ }
150
+ export class Collection {
151
+ constructor(pk, t) {
152
+ this.get = () => this.listStore.get();
153
+ this.getMap = () => this.mapStore.get();
154
+ this.subscribe = (f) => this.listStore.subscribe(f);
155
+ this.derived = (f) => this.listStore.derived(f);
156
+ this.throttle = (t) => this.listStore.throttle(t);
157
+ this.key = (k) => new Key(this.mapStore, this.pk, k);
158
+ this.set = (xs) => {
159
+ const m = new Map();
160
+ for (const x of xs) {
161
+ if (!x) {
162
+ console.error("Empty value passed to collection store");
163
+ }
164
+ else if (!x[this.pk]) {
165
+ console.error(`Value with empty ${this.pk} passed to collection store`, x);
166
+ }
167
+ else {
168
+ m.set(x[this.pk], x);
169
+ }
170
+ }
171
+ this.mapStore.set(m);
172
+ };
173
+ this.update = (f) => this.set(f(this.get()));
174
+ this.updateAsync = async (f) => this.set(await f(this.get()));
175
+ this.reject = (f) => this.update((xs) => xs.filter(x => !f(x)));
176
+ this.filter = (f) => this.update((xs) => xs.filter(f));
177
+ this.map = (f) => this.update((xs) => xs.map(f));
178
+ this.pk = pk;
179
+ this.mapStore = writable(new Map());
180
+ this.listStore = this.mapStore.derived((m) => Array.from(m.values()));
181
+ if (t) {
182
+ this.mapStore.notify = throttle(t, this.mapStore.notify);
183
+ }
184
+ }
185
+ }
186
+ export class DerivedCollection {
187
+ constructor(pk, stores, getValue, t = 0) {
188
+ this.pk = pk;
189
+ this.get = () => this.listStore.get();
190
+ this.getMap = () => this.mapStore.get();
191
+ this.subscribe = (f) => this.listStore.subscribe(f);
192
+ this.derived = (f) => this.listStore.derived(f);
193
+ this.throttle = (t) => this.listStore.throttle(t);
194
+ this.key = (k) => new DerivedKey(this.mapStore, this.pk, k);
195
+ this.listStore = new Derived(stores, getValue, t);
196
+ this.mapStore = new Derived(this.listStore, xs => new Map(xs.map((x) => [x[pk], x])));
197
+ }
198
+ }
199
+ export const writable = (v) => new Writable(v);
200
+ export const derived = (stores, getValue) => new Derived(stores, getValue);
201
+ export const readable = (v) => derived(new Writable(v), identity);
202
+ export const derivedCollection = (pk, stores, getValue) => new DerivedCollection(pk, stores, getValue);
203
+ export const key = (base, pk, key) => new Key(base, pk, key);
204
+ export const collection = (pk) => new Collection(pk);
205
+ //# sourceMappingURL=Store.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Store.mjs","sourceRoot":"","sources":["../Store.ts"],"names":[],"mappings":"OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB;OACnC,EAAC,YAAY,EAAE,QAAQ,EAAC;AAgB/B,MAAM,OAAO,QAAQ;IAInB,YAAY,YAAe,EAAE,CAAU;QAF/B,SAAI,GAAoB,EAAE,CAAA;QAUlC,WAAM,GAAG,GAAG,EAAE;YACZ,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE;gBAC3B,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;aAChB;QACH,CAAC,CAAA;QAiCD,aAAQ,GAAG,CAAC,CAAS,EAAc,EAAE;YACnC,OAAO,IAAI,OAAO,CAAI,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;QAC1C,CAAC,CAAA;QA9CC,IAAI,CAAC,KAAK,GAAG,YAAY,CAAA;QAEzB,IAAI,CAAC,EAAE;YACL,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;SACvC;IACH,CAAC;IAQD,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CA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AAG,CAAI,CAAI,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAA;AAEpD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAI,MAAiB,EAAE,QAA4B,EAAE,EAAE,CAC5E,IAAI,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAE/B,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAI,CAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAgB,CAAA;AAEtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,EAAU,EACV,MAAiB,EACjB,QAA8B,EAC9B,EAAE,CAAC,IAAI,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;AAEhD,MAAM,CAAC,MAAM,GAAG,GAAG,CAAc,IAAoB,EAAE,EAAU,EAAE,GAAW,EAAE,EAAE,CAChF,IAAI,GAAG,CAAI,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,CAAA;AAE3B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAc,EAAU,EAAE,EAAE,CAAC,IAAI,UAAU,CAAI,EAAE,CAAC,CAAA"}
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bech32ToHex = exports.hexToBech32 = exports.pushToMapKey = exports.addToMapKey = exports.batch = exports.chunks = exports.chunk = exports.initArray = exports.sample = exports.groupBy = exports.sortBy = exports.uniqBy = exports.uniq = exports.flatten = exports.ensurePlural = exports.toIterable = exports.isIterable = exports.shuffle = exports.choice = exports.splitAt = exports.hash = exports.prop = exports.ne = exports.eq = exports.nthEq = exports.nth = exports.stripProtocol = exports.randomId = exports.between = exports.range = exports.pick = exports.omit = exports.take = exports.drop = exports.avg = exports.sum = exports.min = exports.max = exports.dec = exports.inc = exports.identity = exports.last = exports.first = exports.now = exports.isNil = void 0;
4
+ const throttle_debounce_1 = require("throttle-debounce");
5
+ const base_1 = require("@scure/base");
6
+ const isNil = (x) => [null, undefined].includes(x);
7
+ exports.isNil = isNil;
8
+ // Regular old utils
9
+ const now = () => Math.round(Date.now() / 1000);
10
+ exports.now = now;
11
+ const first = (xs, ...args) => xs[0];
12
+ exports.first = first;
13
+ const last = (xs, ...args) => xs[xs.length - 1];
14
+ exports.last = last;
15
+ const identity = (x) => x;
16
+ exports.identity = identity;
17
+ const inc = (x) => (x || 0) + 1;
18
+ exports.inc = inc;
19
+ const dec = (x) => (x || 0) - 1;
20
+ exports.dec = dec;
21
+ const max = (xs) => xs.reduce((a, b) => Math.max(a, b), 0);
22
+ exports.max = max;
23
+ const min = (xs) => xs.reduce((a, b) => Math.min(a, b), 0);
24
+ exports.min = min;
25
+ const sum = (xs) => xs.reduce((a, b) => a + b, 0);
26
+ exports.sum = sum;
27
+ const avg = (xs) => (0, exports.sum)(xs) / xs.length;
28
+ exports.avg = avg;
29
+ const drop = (n, xs) => xs.slice(n);
30
+ exports.drop = drop;
31
+ const take = (n, xs) => xs.slice(0, n);
32
+ exports.take = take;
33
+ const omit = (ks, x) => {
34
+ const r = { ...x };
35
+ for (const k of ks) {
36
+ delete r[k];
37
+ }
38
+ return r;
39
+ };
40
+ exports.omit = omit;
41
+ const pick = (ks, x) => {
42
+ const r = { ...x };
43
+ for (const k of Object.keys(x)) {
44
+ if (!ks.includes(k)) {
45
+ delete r[k];
46
+ }
47
+ }
48
+ return r;
49
+ };
50
+ exports.pick = pick;
51
+ function* range(a, b, step = 1) {
52
+ for (let i = a; i < b; i += step) {
53
+ yield i;
54
+ }
55
+ }
56
+ exports.range = range;
57
+ const between = (low, high, n) => n > low && n < high;
58
+ exports.between = between;
59
+ const randomId = () => Math.random().toString().slice(2);
60
+ exports.randomId = randomId;
61
+ const stripProtocol = (url) => url.replace(/.*:\/\//, "");
62
+ exports.stripProtocol = stripProtocol;
63
+ // Curried utils
64
+ const nth = (i) => (xs, ...args) => xs[i];
65
+ exports.nth = nth;
66
+ const nthEq = (i, v) => (xs, ...args) => xs[i] === v;
67
+ exports.nthEq = nthEq;
68
+ const eq = (v) => (x) => x === v;
69
+ exports.eq = eq;
70
+ const ne = (v) => (x) => x !== v;
71
+ exports.ne = ne;
72
+ const prop = (k) => (x) => x[k];
73
+ exports.prop = prop;
74
+ const hash = (s) => Math.abs(s.split("").reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0)).toString();
75
+ exports.hash = hash;
76
+ // Collections
77
+ const splitAt = (n, xs) => [xs.slice(0, n), xs.slice(n)];
78
+ exports.splitAt = splitAt;
79
+ const choice = (xs) => xs[Math.floor(xs.length * Math.random())];
80
+ exports.choice = choice;
81
+ const shuffle = (xs) => Array.from(xs).sort(() => Math.random() > 0.5 ? 1 : -1);
82
+ exports.shuffle = shuffle;
83
+ const isIterable = (x) => Symbol.iterator in Object(x);
84
+ exports.isIterable = isIterable;
85
+ const toIterable = (x) => (0, exports.isIterable)(x) ? x : [x];
86
+ exports.toIterable = toIterable;
87
+ const ensurePlural = (x) => (x instanceof Array ? x : [x]);
88
+ exports.ensurePlural = ensurePlural;
89
+ const flatten = (xs) => xs.flatMap(exports.identity);
90
+ exports.flatten = flatten;
91
+ const uniq = (xs) => Array.from(new Set(xs));
92
+ exports.uniq = uniq;
93
+ const uniqBy = (f, xs) => {
94
+ const s = new Set();
95
+ const r = [];
96
+ for (const x of xs) {
97
+ const k = f(x);
98
+ if (s.has(k)) {
99
+ continue;
100
+ }
101
+ s.add(k);
102
+ r.push(x);
103
+ }
104
+ return r;
105
+ };
106
+ exports.uniqBy = uniqBy;
107
+ const sortBy = (f, xs) => xs.sort((a, b) => f(a) - f(b));
108
+ exports.sortBy = sortBy;
109
+ const groupBy = (f, xs) => {
110
+ const r = {};
111
+ for (const x of xs) {
112
+ const k = f(x);
113
+ if (!r[k]) {
114
+ r[k] = [];
115
+ }
116
+ r[k].push(x);
117
+ }
118
+ return r;
119
+ };
120
+ exports.groupBy = groupBy;
121
+ const sample = (n, xs) => {
122
+ const result = [];
123
+ const limit = Math.min(n, xs.length);
124
+ for (let i = 0; i < limit; i++) {
125
+ result.push(xs.splice(Math.floor(xs.length * Math.random()), 1)[0]);
126
+ }
127
+ return result;
128
+ };
129
+ exports.sample = sample;
130
+ const initArray = (n, f) => {
131
+ const result = [];
132
+ for (let i = 0; i < n; i++) {
133
+ result.push(f());
134
+ }
135
+ return result;
136
+ };
137
+ exports.initArray = initArray;
138
+ const chunk = (chunkLength, xs) => {
139
+ const result = [];
140
+ const current = [];
141
+ for (const item of xs) {
142
+ if (current.length < chunkLength) {
143
+ current.push(item);
144
+ }
145
+ else {
146
+ result.push(current.splice(0));
147
+ }
148
+ }
149
+ if (current.length > 0) {
150
+ result.push(current);
151
+ }
152
+ return result;
153
+ };
154
+ exports.chunk = chunk;
155
+ const chunks = (n, xs) => {
156
+ const result = (0, exports.initArray)(n, () => []);
157
+ for (let i = 0; i < xs.length; i++) {
158
+ result[i % n].push(xs[i]);
159
+ }
160
+ return result;
161
+ };
162
+ exports.chunks = chunks;
163
+ const batch = (t, f) => {
164
+ const xs = [];
165
+ const cb = (0, throttle_debounce_1.throttle)(t, () => xs.length > 0 && f(xs.splice(0)));
166
+ return (x) => {
167
+ xs.push(x);
168
+ cb();
169
+ };
170
+ };
171
+ exports.batch = batch;
172
+ const addToMapKey = (m, k, v) => {
173
+ const a = m.get(k) || new Set();
174
+ a.add(v);
175
+ m.set(k, a);
176
+ };
177
+ exports.addToMapKey = addToMapKey;
178
+ const pushToMapKey = (m, k, v) => {
179
+ const a = m.get(k) || [];
180
+ a.push(v);
181
+ m.set(k, a);
182
+ };
183
+ exports.pushToMapKey = pushToMapKey;
184
+ // Random obscure stuff
185
+ const hexToBech32 = (prefix, url) => base_1.bech32.encode(prefix, base_1.bech32.toWords(base_1.utf8.decode(url)), false);
186
+ exports.hexToBech32 = hexToBech32;
187
+ const bech32ToHex = (b32) => base_1.utf8.encode(base_1.bech32.fromWords(base_1.bech32.decode(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IAAI,EAAE,CAAA;IAExB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACT,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACb,CAAC,CAAA;AALY,QAAA,YAAY,gBAKxB;AAED,uBAAuB;AAEhB,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,GAAW,EAAE,EAAE,CACzD,aAAM,CAAC,MAAM,CAAC,MAAM,EAAE,aAAM,CAAC,OAAO,CAAC,WAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;AADnD,QAAA,WAAW,eACwC;AAEzD,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE,CACzC,WAAI,CAAC,MAAM,CAAC,aAAM,CAAC,SAAS,CAAC,aAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;AADnD,QAAA,WAAW,eACwC"}
@@ -0,0 +1,61 @@
1
+ export type Nil = null | undefined;
2
+ export declare const isNil: (x: any) => boolean;
3
+ export declare const now: () => number;
4
+ export declare const first: <T>(xs: T[], ...args: unknown[]) => T;
5
+ export declare const last: <T>(xs: T[], ...args: unknown[]) => T;
6
+ export declare const identity: <T>(x: T) => T;
7
+ export declare const inc: (x: number | Nil) => number;
8
+ export declare const dec: (x: number | Nil) => number;
9
+ export declare const max: (xs: number[]) => number;
10
+ export declare const min: (xs: number[]) => number;
11
+ export declare const sum: (xs: number[]) => number;
12
+ export declare const avg: (xs: number[]) => number;
13
+ export declare const drop: <T>(n: number, xs: T[]) => T[];
14
+ export declare const take: <T>(n: number, xs: T[]) => T[];
15
+ export declare const omit: <T extends Record<string, any>>(ks: string[], x: T) => T;
16
+ export declare const pick: <T extends Record<string, any>>(ks: string[], x: T) => T;
17
+ export declare function range(a: number, b: number, step?: number): Generator<number, void, unknown>;
18
+ export declare const between: (low: number, high: number, n: number) => boolean;
19
+ export declare const randomId: () => string;
20
+ export declare const stripProtocol: (url: string) => string;
21
+ export declare const nth: (i: number) => <T>(xs: T[], ...args: unknown[]) => T;
22
+ export declare const nthEq: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
23
+ export declare const eq: <T>(v: T) => (x: T) => boolean;
24
+ export declare const ne: <T>(v: T) => (x: T) => boolean;
25
+ export declare const prop: (k: string) => <T>(x: Record<string, T>) => T;
26
+ export declare const hash: (s: string) => string;
27
+ export declare const splitAt: <T>(n: number, xs: T[]) => T[][];
28
+ export declare const choice: <T>(xs: T[]) => T;
29
+ export declare const shuffle: <T>(xs: Iterable<T>) => T[];
30
+ export declare const isIterable: (x: any) => boolean;
31
+ export declare const toIterable: (x: any) => any;
32
+ export declare const ensurePlural: <T>(x: T | T[]) => T[];
33
+ export declare const flatten: <T>(xs: T[]) => T[];
34
+ export declare const uniq: <T>(xs: T[]) => T[];
35
+ export declare const uniqBy: <T>(f: (x: T) => any, xs: T[]) => T[];
36
+ export declare const sortBy: <T>(f: (x: T) => number, xs: T[]) => T[];
37
+ export declare const groupBy: <T>(f: (x: T) => string, xs: T[]) => Record<string, T[]>;
38
+ export declare const sample: <T>(n: number, xs: T[]) => T[];
39
+ export declare const initArray: <T>(n: number, f: () => T) => T[];
40
+ export declare const chunk: <T>(chunkLength: number, xs: T[]) => T[][];
41
+ export declare const chunks: <T>(n: number, xs: T[]) => T[][];
42
+ export declare const batch: <T>(t: number, f: (xs: T[]) => void) => (x: T) => void;
43
+ export declare const addToMapKey: <K, T>(m: Map<K, Set<T>>, k: K, v: T) => void;
44
+ export declare const pushToMapKey: <K, T>(m: Map<K, T[]>, k: K, v: T) => void;
45
+ export declare const hexToBech32: (prefix: string, url: string) => `${Lowercase<string>}1${string}`;
46
+ export declare const bech32ToHex: (b32: string) => string;
47
+ export type OmitStatics<T, S extends string> = T extends {
48
+ new (...args: infer A): infer R;
49
+ } ? {
50
+ new (...args: A): R;
51
+ } & Omit<T, S> : Omit<T, S>;
52
+ export type OmitAllStatics<T extends {
53
+ new (...args: any[]): any;
54
+ prototype: any;
55
+ }> = T extends {
56
+ new (...args: infer A): infer R;
57
+ prototype: infer P;
58
+ } ? {
59
+ new (...args: A): R;
60
+ prototype: P;
61
+ } : never;