@e280/stz 0.2.7 → 0.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e280/stz",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "everyday ts fns for everything",
5
5
  "license": "MIT",
6
6
  "author": "Chase Moskal <chasemoskal@gmail.com>",
package/s/collect.ts ADDED
@@ -0,0 +1,7 @@
1
+
2
+ export async function collect<X>(iterable: AsyncIterable<X>) {
3
+ const array: X[] = []
4
+ for await (const item of iterable) array.push(item)
5
+ return array
6
+ }
7
+
package/s/count.ts ADDED
@@ -0,0 +1,22 @@
1
+
2
+ export function* count(n: number) {
3
+ for (let i = 0; i < n; i++)
4
+ yield i
5
+ }
6
+
7
+ export function* count2d([columns, rows]: [number, number]) {
8
+ for (let y = 0; y < rows; y++)
9
+ for (let x = 0; x < columns; x++)
10
+ yield [x, y] as [number, number]
11
+ }
12
+
13
+ export function range(n: number) {
14
+ return [...count(n)]
15
+ }
16
+
17
+ /** @deprecated renamed to `count` */
18
+ export const loop = count
19
+
20
+ /** @deprecated renamed to `count2d` */
21
+ export const loop2d = count2d
22
+
@@ -3,7 +3,7 @@
3
3
  * repeat the given async function over and over.
4
4
  * - consider using `nap` in your fn to create a delay
5
5
  */
6
- export function repeat(fn: (stop: () => void) => Promise<void>) {
6
+ export function cycle(fn: (stop: () => void) => Promise<void>) {
7
7
  let timeout: any
8
8
  let stopped = false
9
9
 
@@ -23,3 +23,6 @@ export function repeat(fn: (stop: () => void) => Promise<void>) {
23
23
  return stop
24
24
  }
25
25
 
26
+ /** @deprecated renamed to `cycle` */
27
+ export const repeat = cycle
28
+
package/s/index.ts CHANGED
@@ -16,8 +16,11 @@ export * from "./deep/deep.js"
16
16
  export * from "./queue/queue.js"
17
17
 
18
18
  export * from "./coalesce.js"
19
+ export * from "./collect.js"
19
20
  export * from "./concurrent.js"
20
21
  export * from "./constructor.js"
22
+ export * from "./count.js"
23
+ export * from "./cycle.js"
21
24
  export * from "./deadline.js"
22
25
  export * from "./dedupe.js"
23
26
  export * from "./defer.js"
@@ -29,14 +32,13 @@ export * from "./ev.js"
29
32
  export * from "./hat.js"
30
33
  export * from "./id-counter.js"
31
34
  export * from "./is.js"
32
- export * from "./loopy.js"
33
35
  export * from "./map-g.js"
34
36
  export * from "./nap.js"
35
37
  export * from "./ob.js"
36
38
  export * from "./once.js"
37
39
  export * from "./pipe.js"
40
+ export * from "./provide.js"
38
41
  export * from "./pubsub.js"
39
- export * from "./repeat.js"
40
42
  export * from "./scope.js"
41
43
  export * from "./set-g.js"
42
44
  export * from "./templating.js"
package/s/provide.ts ADDED
@@ -0,0 +1,13 @@
1
+
2
+ import {obMap} from "./ob.js"
3
+
4
+ export function provide<
5
+ X,
6
+ Fns extends Record<string, (x: X) => any>
7
+ >(x: X, fns: Fns) {
8
+
9
+ return obMap(fns, fn => fn(x)) as {
10
+ [K in keyof Fns]: ReturnType<Fns[K]>
11
+ }
12
+ }
13
+
package/x/collect.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function collect<X>(iterable: AsyncIterable<X>): Promise<X[]>;
package/x/collect.js ADDED
@@ -0,0 +1,7 @@
1
+ export async function collect(iterable) {
2
+ const array = [];
3
+ for await (const item of iterable)
4
+ array.push(item);
5
+ return array;
6
+ }
7
+ //# sourceMappingURL=collect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect.js","sourceRoot":"","sources":["../s/collect.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,KAAK,UAAU,OAAO,CAAI,QAA0B;IAC1D,MAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnD,OAAO,KAAK,CAAA;AACb,CAAC"}
package/x/count.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare function count(n: number): Generator<number, void, unknown>;
2
+ export declare function count2d([columns, rows]: [number, number]): Generator<[number, number], void, unknown>;
3
+ export declare function range(n: number): number[];
4
+ /** @deprecated renamed to `count` */
5
+ export declare const loop: typeof count;
6
+ /** @deprecated renamed to `count2d` */
7
+ export declare const loop2d: typeof count2d;
package/x/count.js ADDED
@@ -0,0 +1,17 @@
1
+ export function* count(n) {
2
+ for (let i = 0; i < n; i++)
3
+ yield i;
4
+ }
5
+ export function* count2d([columns, rows]) {
6
+ for (let y = 0; y < rows; y++)
7
+ for (let x = 0; x < columns; x++)
8
+ yield [x, y];
9
+ }
10
+ export function range(n) {
11
+ return [...count(n)];
12
+ }
13
+ /** @deprecated renamed to `count` */
14
+ export const loop = count;
15
+ /** @deprecated renamed to `count2d` */
16
+ export const loop2d = count2d;
17
+ //# sourceMappingURL=count.js.map
package/x/count.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"count.js","sourceRoot":"","sources":["../s/count.ts"],"names":[],"mappings":"AACA,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,CAAS;IAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QACzB,MAAM,CAAC,CAAA;AACT,CAAC;AAED,MAAM,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,IAAI,CAAmB;IACzD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE;YAC/B,MAAM,CAAC,CAAC,EAAE,CAAC,CAAqB,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,CAAS;IAC9B,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AACrB,CAAC;AAED,qCAAqC;AACrC,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAA;AAEzB,uCAAuC;AACvC,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAA"}
package/x/cycle.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * repeat the given async function over and over.
3
+ * - consider using `nap` in your fn to create a delay
4
+ */
5
+ export declare function cycle(fn: (stop: () => void) => Promise<void>): () => void;
6
+ /** @deprecated renamed to `cycle` */
7
+ export declare const repeat: typeof cycle;
@@ -2,7 +2,7 @@
2
2
  * repeat the given async function over and over.
3
3
  * - consider using `nap` in your fn to create a delay
4
4
  */
5
- export function repeat(fn) {
5
+ export function cycle(fn) {
6
6
  let timeout;
7
7
  let stopped = false;
8
8
  const stop = () => {
@@ -20,4 +20,6 @@ export function repeat(fn) {
20
20
  tick();
21
21
  return stop;
22
22
  }
23
- //# sourceMappingURL=repeat.js.map
23
+ /** @deprecated renamed to `cycle` */
24
+ export const repeat = cycle;
25
+ //# sourceMappingURL=cycle.js.map
package/x/cycle.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cycle.js","sourceRoot":"","sources":["../s/cycle.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,EAAuC;IAC5D,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;AAED,qCAAqC;AACrC,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAA"}
package/x/index.d.ts CHANGED
@@ -11,8 +11,11 @@ export * from "./debounce/types.js";
11
11
  export * from "./deep/deep.js";
12
12
  export * from "./queue/queue.js";
13
13
  export * from "./coalesce.js";
14
+ export * from "./collect.js";
14
15
  export * from "./concurrent.js";
15
16
  export * from "./constructor.js";
17
+ export * from "./count.js";
18
+ export * from "./cycle.js";
16
19
  export * from "./deadline.js";
17
20
  export * from "./dedupe.js";
18
21
  export * from "./defer.js";
@@ -24,14 +27,13 @@ export * from "./ev.js";
24
27
  export * from "./hat.js";
25
28
  export * from "./id-counter.js";
26
29
  export * from "./is.js";
27
- export * from "./loopy.js";
28
30
  export * from "./map-g.js";
29
31
  export * from "./nap.js";
30
32
  export * from "./ob.js";
31
33
  export * from "./once.js";
32
34
  export * from "./pipe.js";
35
+ export * from "./provide.js";
33
36
  export * from "./pubsub.js";
34
- export * from "./repeat.js";
35
37
  export * from "./scope.js";
36
38
  export * from "./set-g.js";
37
39
  export * from "./templating.js";
package/x/index.js CHANGED
@@ -11,8 +11,11 @@ export * from "./debounce/types.js";
11
11
  export * from "./deep/deep.js";
12
12
  export * from "./queue/queue.js";
13
13
  export * from "./coalesce.js";
14
+ export * from "./collect.js";
14
15
  export * from "./concurrent.js";
15
16
  export * from "./constructor.js";
17
+ export * from "./count.js";
18
+ export * from "./cycle.js";
16
19
  export * from "./deadline.js";
17
20
  export * from "./dedupe.js";
18
21
  export * from "./defer.js";
@@ -24,14 +27,13 @@ export * from "./ev.js";
24
27
  export * from "./hat.js";
25
28
  export * from "./id-counter.js";
26
29
  export * from "./is.js";
27
- export * from "./loopy.js";
28
30
  export * from "./map-g.js";
29
31
  export * from "./nap.js";
30
32
  export * from "./ob.js";
31
33
  export * from "./once.js";
32
34
  export * from "./pipe.js";
35
+ export * from "./provide.js";
33
36
  export * from "./pubsub.js";
34
- export * from "./repeat.js";
35
37
  export * from "./scope.js";
36
38
  export * from "./set-g.js";
37
39
  export * from "./templating.js";
package/x/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../s/index.ts"],"names":[],"mappings":"AACA,cAAc,0BAA0B,CAAA;AACxC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAE7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,gBAAgB,CAAA;AAE9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../s/index.ts"],"names":[],"mappings":"AACA,cAAc,0BAA0B,CAAA;AACxC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAE7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,gBAAgB,CAAA;AAE9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
package/x/provide.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function provide<X, Fns extends Record<string, (x: X) => any>>(x: X, fns: Fns): { [K in keyof Fns]: ReturnType<Fns[K]>; };
package/x/provide.js ADDED
@@ -0,0 +1,5 @@
1
+ import { obMap } from "./ob.js";
2
+ export function provide(x, fns) {
3
+ return obMap(fns, fn => fn(x));
4
+ }
5
+ //# sourceMappingURL=provide.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provide.js","sourceRoot":"","sources":["../s/provide.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAA;AAE7B,MAAM,UAAU,OAAO,CAGpB,CAAI,EAAE,GAAQ;IAEhB,OAAO,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAE5B,CAAA;AACF,CAAC"}
package/s/loopy.ts DELETED
@@ -1,16 +0,0 @@
1
-
2
- export function* loop(n: number) {
3
- for (let i = 0; i < n; i++)
4
- yield i
5
- }
6
-
7
- export function* loop2d([columns, rows]: [number, number]) {
8
- for (let y = 0; y < rows; y++)
9
- for (let x = 0; x < columns; x++)
10
- yield [x, y] as [number, number]
11
- }
12
-
13
- export function range(n: number) {
14
- return [...loop(n)]
15
- }
16
-
package/x/loopy.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function loop(n: number): Generator<number, void, unknown>;
2
- export declare function loop2d([columns, rows]: [number, number]): Generator<[number, number], void, unknown>;
3
- export declare function range(n: number): number[];
package/x/loopy.js DELETED
@@ -1,13 +0,0 @@
1
- export function* loop(n) {
2
- for (let i = 0; i < n; i++)
3
- yield i;
4
- }
5
- export function* loop2d([columns, rows]) {
6
- for (let y = 0; y < rows; y++)
7
- for (let x = 0; x < columns; x++)
8
- yield [x, y];
9
- }
10
- export function range(n) {
11
- return [...loop(n)];
12
- }
13
- //# sourceMappingURL=loopy.js.map
package/x/loopy.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"loopy.js","sourceRoot":"","sources":["../s/loopy.ts"],"names":[],"mappings":"AACA,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAS;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QACzB,MAAM,CAAC,CAAA;AACT,CAAC;AAED,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,IAAI,CAAmB;IACxD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE;YAC/B,MAAM,CAAC,CAAC,EAAE,CAAC,CAAqB,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,CAAS;IAC9B,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AACpB,CAAC"}
package/x/repeat.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * repeat the given async function over and over.
3
- * - consider using `nap` in your fn to create a delay
4
- */
5
- export declare function repeat(fn: (stop: () => void) => Promise<void>): () => void;
package/x/repeat.js.map DELETED
@@ -1 +0,0 @@
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"}