@rimbu/base 2.0.3 → 2.0.4

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 (2) hide show
  1. package/README.md +38 -63
  2. package/package.json +4 -9
package/README.md CHANGED
@@ -6,7 +6,6 @@
6
6
  ![License](https://img.shields.io/github/license/rimbu-org/rimbu)
7
7
  ![Types Included](https://img.shields.io/badge/TypeScript-ready-blue)
8
8
  ![Node](https://img.shields.io/badge/Node-18+-6DA55F?logo=node.js&logoColor=white)
9
- ![Deno](https://shield.deno.dev/x/rimbu)
10
9
  ![Bun](https://img.shields.io/badge/Bun-%23000000.svg)
11
10
  ![ESM + CJS](https://img.shields.io/badge/modules-ESM%20%2B%20CJS-informational)
12
11
 
@@ -77,10 +76,10 @@ import { Arr } from '@rimbu/base';
77
76
  const base = [1, 2, 3];
78
77
 
79
78
  // Pure modification: only clones when the value actually changes
80
- const incremented = Arr.mod(base, 1, v => v + 1); // [1, 3, 3]
79
+ const incremented = Arr.mod(base, 1, (v) => v + 1); // [1, 3, 3]
81
80
 
82
81
  // Structural no-op returns original reference for efficiency
83
- const same = Arr.mod(base, 5, v => v); // index out of range → original
82
+ const same = Arr.mod(base, 5, (v) => v); // index out of range → original
84
83
 
85
84
  // Append without mutating
86
85
  const appended = Arr.append(incremented, 4); // [1, 3, 3, 4]
@@ -97,22 +96,22 @@ console.log(base); // [1, 2, 3]
97
96
 
98
97
  All functions accept a `readonly T[]` input and return either the original array (when unchanged) or an optimized clone.
99
98
 
100
- | Function | Purpose |
101
- | -------- | ------- |
102
- | `append` | Add element at end (non-empty array optimization). |
103
- | `prepend` | Add element at start efficiently. |
104
- | `concat` | Smart concat – reuses original when one side empty. |
105
- | `reverse` | Fast reversed copy (range slice optional). |
106
- | `forEach` | Controlled traversal with optional reverse + halt state. |
107
- | `map` / `reverseMap` | Indexed transformation forward or backward. |
108
- | `last` | O(1) last element access (uses `.at(-1)` when available). |
109
- | `update` | Apply `Update<T>` logic at index (no-op preserved). |
110
- | `mod` | Lightweight element modification via `(value)=>value'`. |
111
- | `insert` | Insert at index. |
112
- | `tail` / `init` | Drop first / last element. |
113
- | `splice` | Immutable variant of native splice. |
114
- | `copySparse` | Preserve holes in sparse arrays. |
115
- | `mapSparse` | Transform only present indices, keeping sparsity. |
99
+ | Function | Purpose |
100
+ | -------------------- | --------------------------------------------------------- |
101
+ | `append` | Add element at end (non-empty array optimization). |
102
+ | `prepend` | Add element at start efficiently. |
103
+ | `concat` | Smart concat – reuses original when one side empty. |
104
+ | `reverse` | Fast reversed copy (range slice optional). |
105
+ | `forEach` | Controlled traversal with optional reverse + halt state. |
106
+ | `map` / `reverseMap` | Indexed transformation forward or backward. |
107
+ | `last` | O(1) last element access (uses `.at(-1)` when available). |
108
+ | `update` | Apply `Update<T>` logic at index (no-op preserved). |
109
+ | `mod` | Lightweight element modification via `(value)=>value'`. |
110
+ | `insert` | Insert at index. |
111
+ | `tail` / `init` | Drop first / last element. |
112
+ | `splice` | Immutable variant of native splice. |
113
+ | `copySparse` | Preserve holes in sparse arrays. |
114
+ | `mapSparse` | Transform only present indices, keeping sparsity. |
116
115
 
117
116
  Design details:
118
117
 
@@ -132,7 +131,9 @@ Entry.first(pair); // 'age'
132
131
  Entry.second(pair); // 42
133
132
 
134
133
  // Shared sentinel for internal tagging / identity
135
- if (someValue === Token) { /* special branch */ }
134
+ if (someValue === Token) {
135
+ /* special branch */
136
+ }
136
137
  ```
137
138
 
138
139
  ---
@@ -141,14 +142,14 @@ if (someValue === Token) { /* special branch */ }
141
142
 
142
143
  Compile-time predicates for discriminating plain data objects from complex / functional structures:
143
144
 
144
- | Type | Description |
145
- | ---- | ----------- |
146
- | `IsPlainObj<T>` | True only for non-iterable, non-function object types without function properties. |
147
- | `PlainObj<T>` | Narrows to T if `IsPlainObj<T>`; otherwise `never`. |
148
- | `IsArray<T>` | Resolves to `true` if T is a (readonly) array type. |
149
- | `IsAny<T>` | Detects `any`. |
150
- | `isPlainObj(obj)` | Runtime guard for plain data objects. |
151
- | `isIterable(obj)` | Runtime guard for `Iterable`. |
145
+ | Type | Description |
146
+ | ----------------- | ---------------------------------------------------------------------------------- |
147
+ | `IsPlainObj<T>` | True only for non-iterable, non-function object types without function properties. |
148
+ | `PlainObj<T>` | Narrows to T if `IsPlainObj<T>`; otherwise `never`. |
149
+ | `IsArray<T>` | Resolves to `true` if T is a (readonly) array type. |
150
+ | `IsAny<T>` | Detects `any`. |
151
+ | `isPlainObj(obj)` | Runtime guard for plain data objects. |
152
+ | `isIterable(obj)` | Runtime guard for `Iterable`. |
152
153
 
153
154
  Use these when building APIs that must reject iterables or functions while retaining strong type discrimination.
154
155
 
@@ -158,12 +159,12 @@ Use these when building APIs that must reject iterables or functions while retai
158
159
 
159
160
  Structured error classes provide meaningful failure contexts internally and externally:
160
161
 
161
- | Error Class | Trigger Scenario |
162
- | ----------- | ---------------- |
163
- | `EmptyCollectionAssumedNonEmptyError` | An operation expected a non-empty collection. |
164
- | `ModifiedBuilderWhileLoopingOverItError` | Mutating a builder mid-iteration. |
165
- | `InvalidStateError` | Internal invariant breach (should not happen). |
166
- | `InvalidUsageError` | Consumer used an API incorrectly. |
162
+ | Error Class | Trigger Scenario |
163
+ | ---------------------------------------- | ---------------------------------------------- |
164
+ | `EmptyCollectionAssumedNonEmptyError` | An operation expected a non-empty collection. |
165
+ | `ModifiedBuilderWhileLoopingOverItError` | Mutating a builder mid-iteration. |
166
+ | `InvalidStateError` | Internal invariant breach (should not happen). |
167
+ | `InvalidUsageError` | Consumer used an API incorrectly. |
167
168
 
168
169
  Helper throw functions exist for concise signaling (`throwInvalidStateError()`, etc.). Prefer them for consistency.
169
170
 
@@ -174,7 +175,6 @@ Helper throw functions exist for concise signaling (`throwInvalidStateError()`,
174
175
  ### Compabitity
175
176
 
176
177
  - [`Node` ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?logo=node.js&logoColor=white)](https://nodejs.org)
177
- - [`Deno` ![Deno JS](https://img.shields.io/badge/deno%20js-000000?logo=deno&logoColor=white)](https://deno.com/runtime)
178
178
  - [`Bun` ![Bun](https://img.shields.io/badge/Bun-%23000000.svg?logoColor=white)](https://bun.sh/)
179
179
  - `Web` ![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?logoColor=white)
180
180
 
@@ -198,37 +198,12 @@ npm install @rimbu/base
198
198
  bun add @rimbu/base
199
199
  ```
200
200
 
201
- ### Deno Setup
202
-
203
- Create or edit `import_map.json` in your project root:
204
-
205
- ```json
206
- {
207
- "imports": {
208
- "@rimbu/": "https://deno.land/x/rimbu@x.y.z/"
209
- }
210
- }
211
- ```
212
-
213
- _Replace `x.y.z` with the desired version._
201
+ **Deno:**
214
202
 
215
- In this way you can use relative imports from Rimbu in your code, like so:
216
-
217
- ```ts
218
- import { List } from '@rimbu/core/mod.ts';
219
- import { HashMap } from '@rimbu/hashed/mod.ts';
220
- ```
221
-
222
- Note that for sub-packages, due to conversion limitations it is needed to import the `index.ts` instead of `mod.ts`, like so:
223
-
224
- ```ts
225
- import { HashMap } from '@rimbu/hashed/map/index.ts';
203
+ ```sh
204
+ deno add npm:@rimbu/base
226
205
  ```
227
206
 
228
- To run your script (let's assume the entry point is in `src/main.ts`):
229
-
230
- `deno run --import-map import_map.json src/main.ts`
231
-
232
207
  ## Usage
233
208
 
234
209
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimbu/base",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Utilities to implement Rimbu collections",
5
5
  "keywords": [
6
6
  "array",
@@ -32,7 +32,7 @@
32
32
  "types": "./dist/cjs/index.d.cts",
33
33
  "exports": {
34
34
  ".": {
35
- "bun": "./dist/bun/main/index.mts",
35
+ "bun": "./dist/bun/index.mts",
36
36
  "import": {
37
37
  "types": "./dist/esm/index.d.mts",
38
38
  "default": "./dist/esm/index.mjs"
@@ -49,17 +49,12 @@
49
49
  ],
50
50
  "scripts": {
51
51
  "build": "yarn clean && yarn bundle",
52
- "build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
53
52
  "bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
54
53
  "bundle:bun": "node ../../config/bunnify.mjs -mode bun",
55
54
  "bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
56
55
  "bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
57
56
  "bundle:cjs-build": "tsc -p tsconfig.cjs.json",
58
57
  "bundle:cjs-clean": "rimraf _cjs_prepare",
59
- "bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
60
- "bundle:deno-convert": "denoify --src _deno_prepare/src",
61
- "bundle:deno-move": "rimraf ../../deno_dist/base && mv deno_dist ../../deno_dist/base",
62
- "bundle:deno-clean": "rimraf _deno_prepare",
63
58
  "bundle:esm": "tsc --p tsconfig.esm.json",
64
59
  "clean": "rimraf dist",
65
60
  "format": "yarn format:base --write",
@@ -73,10 +68,10 @@
73
68
  "typecheck": "tsc"
74
69
  },
75
70
  "dependencies": {
76
- "@rimbu/common": "^2.0.3"
71
+ "@rimbu/common": "^2.0.4"
77
72
  },
78
73
  "publishConfig": {
79
74
  "access": "public"
80
75
  },
81
- "gitHead": "1c35dbdd9ce13aeba818b41eb20bab1e826b3e16"
76
+ "gitHead": "bc6bc82af86461c423ba459d6d9809efdd5ffd61"
82
77
  }