@rimbu/common 0.12.3 → 1.0.0-alpha.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 (139) hide show
  1. package/README.md +21 -4
  2. package/{src/async-optlazy.ts → dist/bun/async-optlazy.mts} +1 -1
  3. package/{src/async-reducer.ts → dist/bun/async-reducer.mts} +17 -8
  4. package/{src/collect.ts → dist/bun/collect.mts} +1 -1
  5. package/{src/comp.ts → dist/bun/comp.mts} +1 -1
  6. package/{src/index-range.ts → dist/bun/index-range.mts} +1 -1
  7. package/{src/index.ts → dist/bun/index.mts} +1 -1
  8. package/dist/bun/internal.mts +13 -0
  9. package/{src/reducer.ts → dist/bun/reducer.mts} +5 -3
  10. package/dist/cjs/async-optlazy.js +44 -0
  11. package/dist/cjs/async-reducer.js +1621 -0
  12. package/dist/cjs/collect.js +33 -0
  13. package/dist/cjs/comp.js +1621 -0
  14. package/dist/cjs/eq.js +210 -0
  15. package/dist/cjs/err.js +55 -0
  16. package/dist/cjs/index-range.js +114 -0
  17. package/dist/cjs/index.js +1685 -0
  18. package/dist/cjs/internal.js +1685 -0
  19. package/dist/cjs/optlazy.js +41 -0
  20. package/dist/cjs/range.js +52 -0
  21. package/dist/cjs/reducer.js +1621 -0
  22. package/dist/cjs/traverse-state.js +49 -0
  23. package/dist/cjs/types.js +18 -0
  24. package/dist/cjs/update.js +35 -0
  25. package/dist/{module/async-optlazy.js → esm/async-optlazy.mjs} +5 -8
  26. package/dist/esm/async-optlazy.mjs.map +1 -0
  27. package/dist/{module/async-reducer.js → esm/async-reducer.mjs} +67 -69
  28. package/dist/esm/async-reducer.mjs.map +1 -0
  29. package/dist/{module/collect.js → esm/collect.mjs} +1 -1
  30. package/dist/esm/collect.mjs.map +1 -0
  31. package/dist/{module/comp.js → esm/comp.mjs} +2 -2
  32. package/dist/esm/comp.mjs.map +1 -0
  33. package/dist/{module/eq.js → esm/eq.mjs} +1 -1
  34. package/dist/esm/eq.mjs.map +1 -0
  35. package/dist/{module/err.js → esm/err.mjs} +1 -1
  36. package/dist/esm/err.mjs.map +1 -0
  37. package/dist/{module/index-range.js → esm/index-range.mjs} +2 -3
  38. package/dist/esm/index-range.mjs.map +1 -0
  39. package/dist/esm/index.mjs +7 -0
  40. package/dist/esm/index.mjs.map +1 -0
  41. package/dist/esm/internal.mjs +14 -0
  42. package/dist/esm/internal.mjs.map +1 -0
  43. package/dist/{module/optlazy.js → esm/optlazy.mjs} +1 -1
  44. package/dist/esm/optlazy.mjs.map +1 -0
  45. package/dist/{module/range.js → esm/range.mjs} +1 -1
  46. package/dist/esm/range.mjs.map +1 -0
  47. package/dist/{module/reducer.js → esm/reducer.mjs} +10 -8
  48. package/dist/esm/reducer.mjs.map +1 -0
  49. package/dist/{module/traverse-state.js → esm/traverse-state.mjs} +1 -1
  50. package/dist/esm/traverse-state.mjs.map +1 -0
  51. package/dist/esm/types.mjs +2 -0
  52. package/dist/esm/types.mjs.map +1 -0
  53. package/dist/{module/update.js → esm/update.mjs} +1 -1
  54. package/dist/esm/update.mjs.map +1 -0
  55. package/dist/types/{async-optlazy.d.ts → async-optlazy.d.mts} +1 -1
  56. package/dist/types/{async-reducer.d.ts → async-reducer.d.mts} +2 -2
  57. package/dist/types/{collect.d.ts → collect.d.mts} +1 -1
  58. package/dist/types/{comp.d.ts → comp.d.mts} +1 -1
  59. package/dist/types/{index-range.d.ts → index-range.d.mts} +1 -1
  60. package/dist/types/{index.d.ts → index.d.mts} +1 -1
  61. package/dist/types/internal.d.mts +13 -0
  62. package/dist/types/{reducer.d.ts → reducer.d.mts} +1 -1
  63. package/package.json +27 -21
  64. package/src/async-optlazy.mts +49 -0
  65. package/src/async-reducer.mts +1157 -0
  66. package/src/collect.mts +43 -0
  67. package/src/comp.mts +625 -0
  68. package/src/eq.mts +406 -0
  69. package/src/err.mts +43 -0
  70. package/src/index-range.mts +120 -0
  71. package/{dist/module/index.js → src/index.mts} +2 -2
  72. package/src/internal.mts +13 -0
  73. package/{dist/main/optlazy.js → src/optlazy.mts} +24 -14
  74. package/src/range.mts +58 -0
  75. package/src/reducer.mts +1025 -0
  76. package/src/traverse-state.mts +59 -0
  77. package/src/types.mts +40 -0
  78. package/{dist/main/update.js → src/update.mts} +10 -10
  79. package/dist/main/async-optlazy.js +0 -48
  80. package/dist/main/async-optlazy.js.map +0 -1
  81. package/dist/main/async-reducer.js +0 -872
  82. package/dist/main/async-reducer.js.map +0 -1
  83. package/dist/main/collect.js +0 -11
  84. package/dist/main/collect.js.map +0 -1
  85. package/dist/main/comp.js +0 -542
  86. package/dist/main/comp.js.map +0 -1
  87. package/dist/main/eq.js +0 -382
  88. package/dist/main/eq.js.map +0 -1
  89. package/dist/main/err.js +0 -62
  90. package/dist/main/err.js.map +0 -1
  91. package/dist/main/index-range.js +0 -110
  92. package/dist/main/index-range.js.map +0 -1
  93. package/dist/main/index.js +0 -10
  94. package/dist/main/index.js.map +0 -1
  95. package/dist/main/internal.js +0 -17
  96. package/dist/main/internal.js.map +0 -1
  97. package/dist/main/optlazy.js.map +0 -1
  98. package/dist/main/range.js +0 -38
  99. package/dist/main/range.js.map +0 -1
  100. package/dist/main/reducer.js +0 -694
  101. package/dist/main/reducer.js.map +0 -1
  102. package/dist/main/traverse-state.js +0 -33
  103. package/dist/main/traverse-state.js.map +0 -1
  104. package/dist/main/types.js +0 -3
  105. package/dist/main/types.js.map +0 -1
  106. package/dist/main/update.js.map +0 -1
  107. package/dist/module/async-optlazy.js.map +0 -1
  108. package/dist/module/async-reducer.js.map +0 -1
  109. package/dist/module/collect.js.map +0 -1
  110. package/dist/module/comp.js.map +0 -1
  111. package/dist/module/eq.js.map +0 -1
  112. package/dist/module/err.js.map +0 -1
  113. package/dist/module/index-range.js.map +0 -1
  114. package/dist/module/index.js.map +0 -1
  115. package/dist/module/internal.js +0 -14
  116. package/dist/module/internal.js.map +0 -1
  117. package/dist/module/optlazy.js.map +0 -1
  118. package/dist/module/range.js.map +0 -1
  119. package/dist/module/reducer.js.map +0 -1
  120. package/dist/module/traverse-state.js.map +0 -1
  121. package/dist/module/types.js +0 -2
  122. package/dist/module/types.js.map +0 -1
  123. package/dist/module/update.js.map +0 -1
  124. package/dist/types/internal.d.ts +0 -13
  125. package/src/internal.ts +0 -13
  126. /package/{src/eq.ts → dist/bun/eq.mts} +0 -0
  127. /package/{src/err.ts → dist/bun/err.mts} +0 -0
  128. /package/{src/optlazy.ts → dist/bun/optlazy.mts} +0 -0
  129. /package/{src/range.ts → dist/bun/range.mts} +0 -0
  130. /package/{src/traverse-state.ts → dist/bun/traverse-state.mts} +0 -0
  131. /package/{src/types.ts → dist/bun/types.mts} +0 -0
  132. /package/{src/update.ts → dist/bun/update.mts} +0 -0
  133. /package/dist/types/{eq.d.ts → eq.d.mts} +0 -0
  134. /package/dist/types/{err.d.ts → err.d.mts} +0 -0
  135. /package/dist/types/{optlazy.d.ts → optlazy.d.mts} +0 -0
  136. /package/dist/types/{range.d.ts → range.d.mts} +0 -0
  137. /package/dist/types/{traverse-state.d.ts → traverse-state.d.mts} +0 -0
  138. /package/dist/types/{types.d.ts → types.d.mts} +0 -0
  139. /package/dist/types/{update.d.ts → update.d.mts} +0 -0
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
  <img src="https://github.com/rimbu-org/rimbu/raw/main/assets/rimbu_logo.svg" />
3
3
  </p>
4
4
 
5
+ [![npm version](https://badge.fury.io/js/@rimbu%2Fcommon.svg)](https://www.npmjs.com/package/@rimbu/common) [![Deno](https://shield.deno.dev/x/rimbu)](http://deno.land/x/rimbu)
6
+
7
+ ![Licence](https://img.shields.io/github/license/rimbu-org/rimbu)
8
+
5
9
  # @rimbu/common
6
10
 
7
11
  This package exports common types and objects used in many other Rimbu packages.
@@ -30,18 +34,31 @@ Or [Try Out Rimbu](https://codesandbox.io/s/github/vitoke/rimbu-sandbox/tree/mai
30
34
 
31
35
  ## Installation
32
36
 
33
- All types are exported through `@rimbu/core`. It is recommended to use that package.
37
+ ### Compabitity
38
+
39
+ - [`Node >= 16` ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?logo=node.js&logoColor=white)](https://nodejs.org)
40
+ - [`Deno` ![Deno JS](https://img.shields.io/badge/deno%20js-000000?logo=deno&logoColor=white)](https://deno.com/runtime)
41
+ - [`Bun >= 0.6.0` ![Bun](https://img.shields.io/badge/Bun-%23000000.svg?logoColor=white)](https://bun.sh/)
42
+ - `Web` ![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?logoColor=white)
43
+
44
+ ### Yarn / NPM / Bun
34
45
 
35
- To install this package separately:
46
+ For convenience, all main types are also exported through [`@rimbu/core`](../core).
36
47
 
37
- ### Yarn/NPM
48
+ To install this package only:
49
+
50
+ For `yarn`:
38
51
 
39
52
  > `yarn add @rimbu/common`
40
53
 
41
- or
54
+ For `npm`:
42
55
 
43
56
  > `npm i @rimbu/common`
44
57
 
58
+ For `bun`:
59
+
60
+ > `bun add @rimbu/common`
61
+
45
62
  ### Deno
46
63
 
47
64
  For Deno, the following approach is recommended:
@@ -1,4 +1,4 @@
1
- import type { OptLazy } from './internal';
1
+ import type { OptLazy } from './internal.mts';
2
2
 
3
3
  /**
4
4
  * A type that is either a value T or a promise yielding a value of type T.
@@ -1,11 +1,11 @@
1
1
  import {
2
- AsyncCollectFun,
2
+ type AsyncCollectFun,
3
3
  AsyncOptLazy,
4
4
  CollectFun,
5
- MaybePromise,
5
+ type MaybePromise,
6
6
  Reducer,
7
7
  Eq,
8
- } from './internal';
8
+ } from './internal.mts';
9
9
 
10
10
  /**
11
11
  * An `AsyncReducer` is a stand-alone asynchronous calculation that takes input values of type I,
@@ -43,7 +43,7 @@ export namespace AsyncReducer {
43
43
  * @param state - the final reducer state
44
44
  * @param error - (optional) if an error has occured, it ix passed here
45
45
  */
46
- onClose?(state: S, error?: unknown): MaybePromise<void>;
46
+ onClose?: ((state: S, error?: unknown) => MaybePromise<void>) | undefined;
47
47
  /**
48
48
  * Returns an `AsyncReducer` instance that only passes values to the reducer that satisy the given `pred` predicate.
49
49
  * @param pred - a potaentially asynchronous function that returns true if the value should be passed to the reducer based on the following inputs:<br/>
@@ -270,7 +270,9 @@ export namespace AsyncReducer {
270
270
  }
271
271
 
272
272
  dropInput(amount: number): AsyncReducer<I, O> {
273
- if (amount <= 0) return this;
273
+ if (amount <= 0) {
274
+ return this as AsyncReducer<I, O>;
275
+ }
274
276
 
275
277
  return this.filterInput((_, i): boolean => i >= amount);
276
278
  }
@@ -308,7 +310,12 @@ export namespace AsyncReducer {
308
310
  stateToResult: (state: S) => MaybePromise<O>,
309
311
  onClose?: (state: S, error?: unknown) => MaybePromise<void>
310
312
  ): AsyncReducer<I, O> {
311
- return new AsyncReducer.Base(init, next, stateToResult, onClose);
313
+ return new AsyncReducer.Base(
314
+ init,
315
+ next,
316
+ stateToResult,
317
+ onClose
318
+ ) as AsyncReducer<I, O>;
312
319
  }
313
320
 
314
321
  /**
@@ -456,10 +463,11 @@ export namespace AsyncReducer {
456
463
  * // => 3
457
464
  * ```
458
465
  */
466
+ // prettier-ignore
459
467
  export const min: {
460
468
  (): AsyncReducer<number, number | undefined>;
461
469
  <O>(otherwise: AsyncOptLazy<O>): AsyncReducer<number, number | O>;
462
- } = <O>(otherwise?: AsyncOptLazy<O>) => {
470
+ } = <O,>(otherwise?: AsyncOptLazy<O>) => {
463
471
  return create<number, number | O, number | undefined>(
464
472
  undefined,
465
473
  (state, next): number =>
@@ -514,10 +522,11 @@ export namespace AsyncReducer {
514
522
  * // => 7
515
523
  * ```
516
524
  */
525
+ // prettier-ignore
517
526
  export const max: {
518
527
  (): AsyncReducer<number, number | undefined>;
519
528
  <O>(otherwise: AsyncOptLazy<O>): AsyncReducer<number, number | O>;
520
- } = <O>(otherwise?: AsyncOptLazy<O>): AsyncReducer<number, number | O> => {
529
+ } = <O,>(otherwise?: AsyncOptLazy<O>): AsyncReducer<number, number | O> => {
521
530
  return create<number, number | O, number | undefined>(
522
531
  undefined,
523
532
  (state, next): number =>
@@ -1,4 +1,4 @@
1
- import type { MaybePromise } from './internal';
1
+ import type { MaybePromise } from './internal.mts';
2
2
 
3
3
  /**
4
4
  * A function used in `collect` methods to collect values from a collection. This is basically a single-pass map and filter.
@@ -1,4 +1,4 @@
1
- import { Eq } from './internal';
1
+ import { Eq } from './internal.mts';
2
2
 
3
3
  /**
4
4
  * An object providing methods to compare two values of type `K`.
@@ -1,4 +1,4 @@
1
- import type { Range } from './internal';
1
+ import type { Range } from './internal.mts';
2
2
 
3
3
  /**
4
4
  * A flexible range specification for numeric indices.
@@ -4,4 +4,4 @@
4
4
  * The `@rimbu/common` package provides many commonly used types and utilities that can also be of use to Rimbu users.<br/>
5
5
  */
6
6
 
7
- export * from './internal';
7
+ export * from './internal.mts';
@@ -0,0 +1,13 @@
1
+ export * from './collect.mts';
2
+ export * from './comp.mts';
3
+ export * from './eq.mts';
4
+ export * from './err.mts';
5
+ export * from './index-range.mts';
6
+ export * from './optlazy.mts';
7
+ export * from './range.mts';
8
+ export * from './reducer.mts';
9
+ export * from './traverse-state.mts';
10
+ export * from './types.mts';
11
+ export * from './update.mts';
12
+ export * from './async-optlazy.mts';
13
+ export * from './async-reducer.mts';
@@ -1,4 +1,4 @@
1
- import { CollectFun, Eq, OptLazy } from './internal';
1
+ import { CollectFun, Eq, OptLazy } from './internal.mts';
2
2
 
3
3
  /**
4
4
  * A `Reducer` is a stand-alone calculation that takes input values of type I, and, when requested, produces an output value of type O.
@@ -389,10 +389,11 @@ export namespace Reducer {
389
389
  * // => 3
390
390
  * ```
391
391
  */
392
+ // prettier-ignore
392
393
  export const min: {
393
394
  (): Reducer<number, number | undefined>;
394
395
  <O>(otherwise: OptLazy<O>): Reducer<number, number | O>;
395
- } = <O>(otherwise?: OptLazy<O>) => {
396
+ } = <O,>(otherwise?: OptLazy<O>) => {
396
397
  return create<number, number | O, number | undefined>(
397
398
  undefined,
398
399
  (state, next): number =>
@@ -442,10 +443,11 @@ export namespace Reducer {
442
443
  * // => 7
443
444
  * ```
444
445
  */
446
+ // prettier-ignore
445
447
  export const max: {
446
448
  (): Reducer<number, number | undefined>;
447
449
  <O>(otherwise: OptLazy<O>): Reducer<number, number | O>;
448
- } = <O>(otherwise?: OptLazy<O>): Reducer<number, number | O> => {
450
+ } = <O,>(otherwise?: OptLazy<O>): Reducer<number, number | O> => {
449
451
  return create<number, number | O, number | undefined>(
450
452
  undefined,
451
453
  (state, next): number =>
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/async-optlazy.mts
21
+ var async_optlazy_exports = {};
22
+ __export(async_optlazy_exports, {
23
+ AsyncOptLazy: () => AsyncOptLazy
24
+ });
25
+ module.exports = __toCommonJS(async_optlazy_exports);
26
+ var AsyncOptLazy;
27
+ ((AsyncOptLazy2) => {
28
+ function toMaybePromise(optLazy) {
29
+ if (optLazy instanceof Function)
30
+ return optLazy();
31
+ return optLazy;
32
+ }
33
+ AsyncOptLazy2.toMaybePromise = toMaybePromise;
34
+ async function toPromise(optLazy) {
35
+ if (optLazy instanceof Function)
36
+ return optLazy();
37
+ return optLazy;
38
+ }
39
+ AsyncOptLazy2.toPromise = toPromise;
40
+ })(AsyncOptLazy || (AsyncOptLazy = {}));
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ AsyncOptLazy
44
+ });