Skip to content

Commit 98a4b6c

Browse files
committed
Refactor Array module: new helpers, breaking changes
Refactored the Array module with improved naming, removed isNonEmptyReadonlyArray (use isNonEmptyArray for both mutable and readonly arrays), and renamed mutation helpers to shiftFromArray and popFromArray. Added new helpers: flatMapArray, concatArrays, sortArray, reverseArray, and spliceArray, all with type-safe signatures and non-empty array preservation. Updated tests to cover new and changed APIs.
1 parent f3d2c2d commit 98a4b6c

3 files changed

Lines changed: 507 additions & 126 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
"@evolu/common": major
3+
---
4+
5+
Refactored the Array module with breaking changes, better naming, and new helpers.
6+
7+
### Breaking Changes
8+
9+
**Removed `isNonEmptyReadonlyArray`** — use `isNonEmptyArray` instead. The function now handles both mutable and readonly arrays via overloads:
10+
11+
```ts
12+
// Before
13+
if (isNonEmptyReadonlyArray(readonlyArr)) { ... }
14+
if (isNonEmptyArray(mutableArr)) { ... }
15+
16+
// After — one function for both
17+
if (isNonEmptyArray(readonlyArr)) { ... }
18+
if (isNonEmptyArray(mutableArr)) { ... }
19+
```
20+
21+
**Renamed mutation functions** for consistency with the `...Array` suffix pattern:
22+
23+
- `shiftArray``shiftFromArray`
24+
- `popArray``popFromArray`
25+
26+
### New Functions
27+
28+
- **`flatMapArray`** — maps each element to an array and flattens the result, preserving non-empty type when applicable
29+
- **`concatArrays`** — concatenates two arrays, returning non-empty when at least one input is non-empty
30+
- **`sortArray`** — returns a new sorted array (wraps `toSorted`), preserving non-empty type
31+
- **`reverseArray`** — returns a new reversed array (wraps `toReversed`), preserving non-empty type
32+
- **`spliceArray`** — returns a new array with elements removed/replaced (wraps `toSpliced`)
33+
34+
### Migration
35+
36+
```ts
37+
// isNonEmptyReadonlyArray → isNonEmptyArray
38+
-import { isNonEmptyReadonlyArray } from "@evolu/common";
39+
+import { isNonEmptyArray } from "@evolu/common";
40+
41+
// shiftArray → shiftFromArray
42+
-import { shiftArray } from "@evolu/common";
43+
+import { shiftFromArray } from "@evolu/common";
44+
45+
// popArray → popFromArray
46+
-import { popArray } from "@evolu/common";
47+
+import { popFromArray } from "@evolu/common";
48+
```

0 commit comments

Comments
 (0)