@nunofyobiz/effect-extras 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.
- package/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/index.d.ts +3703 -0
- package/dist/index.js +1006 -0
- package/dist/index.js.map +1 -0
- package/package.json +103 -0
- package/src/ArrayX/ArrayX.ts +818 -0
- package/src/ArrayX/index.ts +1 -0
- package/src/BigIntX/BigIntX.ts +35 -0
- package/src/BigIntX/index.ts +1 -0
- package/src/BooleanX/BooleanX.ts +24 -0
- package/src/BooleanX/index.ts +1 -0
- package/src/DurationX/DurationX.ts +178 -0
- package/src/DurationX/index.ts +1 -0
- package/src/EffectX/EffectX.ts +183 -0
- package/src/EffectX/index.ts +1 -0
- package/src/FormDataX/FormDataX.ts +57 -0
- package/src/FormDataX/index.ts +1 -0
- package/src/MapX/MapX.ts +54 -0
- package/src/MapX/index.ts +1 -0
- package/src/NonNullableX/NonNullableX.ts +290 -0
- package/src/NonNullableX/index.ts +2 -0
- package/src/NumberX/NumberX.ts +282 -0
- package/src/NumberX/index.ts +1 -0
- package/src/OptionX/OptionX.ts +234 -0
- package/src/OptionX/index.ts +1 -0
- package/src/OrderX/OrderX.ts +35 -0
- package/src/OrderX/index.ts +1 -0
- package/src/PredicateX/PredicateX.ts +98 -0
- package/src/PredicateX/index.ts +1 -0
- package/src/PromiseX/PromiseX.ts +32 -0
- package/src/PromiseX/index.ts +1 -0
- package/src/RecordX/RecordX.ts +478 -0
- package/src/RecordX/index.ts +1 -0
- package/src/ResultX/ResultX.ts +53 -0
- package/src/ResultX/index.ts +1 -0
- package/src/SchemaX/SchemaX.ts +324 -0
- package/src/SchemaX/index.ts +1 -0
- package/src/SetX/SetX.ts +160 -0
- package/src/SetX/index.ts +1 -0
- package/src/StringX/StringX.ts +97 -0
- package/src/StringX/index.ts +1 -0
- package/src/StructX/StructX.ts +310 -0
- package/src/StructX/index.ts +1 -0
- package/src/These/These.ts +1173 -0
- package/src/These/index.ts +1 -0
- package/src/index.ts +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kapil Easwar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# @nunofyobiz/effect-extras
|
|
2
|
+
|
|
3
|
+
Generic, framework-agnostic extensions of the [Effect](https://effect.website)
|
|
4
|
+
standard library. These are the `*X` utility modules — `ArrayX`, `OptionX`,
|
|
5
|
+
`RecordX`, `StructX`, and friends — that extend Effect's own modules with small,
|
|
6
|
+
universal patterns used repeatedly across projects.
|
|
7
|
+
|
|
8
|
+
Each module is named after the Effect (or native) module it extends, suffixed
|
|
9
|
+
with `X`: `ArrayX` extends `Array`, `OptionX` extends `Option`, and so on. They
|
|
10
|
+
are pure, generic, and carry **no** domain or framework knowledge — that is the
|
|
11
|
+
whole point, and the bar every addition has to clear (see
|
|
12
|
+
[What belongs here](#what-belongs-here)).
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { ArrayX, OptionX, RecordX, StructX, nn } from "@nunofyobiz/effect-extras";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpm add @nunofyobiz/effect-extras
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`effect` is a **peer dependency** — your project must already depend on a
|
|
25
|
+
compatible version of `effect`. This package extends Effect; it does not bundle
|
|
26
|
+
it.
|
|
27
|
+
|
|
28
|
+
## What belongs here
|
|
29
|
+
|
|
30
|
+
This package has exactly one job: hold the generic `*X` helpers that extend
|
|
31
|
+
Effect with patterns worth reusing **everywhere**. The danger with a "utils"
|
|
32
|
+
package is scope creep, so the bar for adding something is deliberately high.
|
|
33
|
+
|
|
34
|
+
A utility belongs here only if **all** of these hold:
|
|
35
|
+
|
|
36
|
+
1. **It is not already in Effect.** If `effect` (or an `@effect/*` package)
|
|
37
|
+
already does it, use that directly. Check the [Effect docs](https://effect.website)
|
|
38
|
+
first — the built-in modules (`Array`, `Option`, `Record`, `Predicate`,
|
|
39
|
+
`String`, `Number`, `Order`, `Result`, `Match`, `Struct`, …) are wide and
|
|
40
|
+
well-tested, and most "manipulate this shape" needs already exist there.
|
|
41
|
+
2. **It is generic and pure.** It operates on type parameters (`<A>`), has no
|
|
42
|
+
side effects, no mutations, and would make sense in a project that shares
|
|
43
|
+
nothing with yours.
|
|
44
|
+
3. **It carries zero app knowledge.** It never references a specific business
|
|
45
|
+
domain or data model (no `Project`, `User`, `Timeline`, …), and never encodes
|
|
46
|
+
product rules. Domain-shaped helpers live in the app that owns the domain —
|
|
47
|
+
not here. **This is the hard line.**
|
|
48
|
+
4. **If it is a thin wrapper around Effect built-ins, it earns its place.** A
|
|
49
|
+
small convenience wrapper is only worth adding when it is _meaningfully
|
|
50
|
+
useful_ **and** _universal_. If a one-liner at the call site is just as clear,
|
|
51
|
+
don't wrap it — the indirection costs more than it saves.
|
|
52
|
+
|
|
53
|
+
### Decision flowchart
|
|
54
|
+
|
|
55
|
+
```mermaid
|
|
56
|
+
flowchart TD
|
|
57
|
+
A([Candidate utility]) --> B{Does Effect already<br/>provide it?}
|
|
58
|
+
B -- Yes --> R1[/Use Effect directly —<br/>do not add it here/]
|
|
59
|
+
B -- No --> C{Does it encode any app's<br/>business logic or data model?}
|
|
60
|
+
C -- Yes --> R2[/Belongs in that app —<br/>this package is domain-free/]
|
|
61
|
+
C -- No --> D{Generic over <A>, pure,<br/>and reusable across<br/>unrelated projects?}
|
|
62
|
+
D -- No --> R2
|
|
63
|
+
D -- Yes --> E{Just a thin wrapper around<br/>an Effect built-in?}
|
|
64
|
+
E -- No --> OK([Add it: a real gap in<br/>Effect's surface])
|
|
65
|
+
E -- Yes --> F{Meaningfully useful<br/>AND universal?}
|
|
66
|
+
F -- No --> R3[/Skip it: a call-site<br/>one-liner is clearer/]
|
|
67
|
+
F -- Yes --> OK
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Does NOT belong here
|
|
71
|
+
|
|
72
|
+
- Anything tied to a domain model, a database row, an API shape, or product copy.
|
|
73
|
+
- Anything that imports a framework (React, Next, a UI kit) or `node:*` built-ins
|
|
74
|
+
in a way that assumes a runtime — these helpers must work anywhere Effect works.
|
|
75
|
+
- A wrapper that exists only to rename an Effect function, or to save a single
|
|
76
|
+
obvious line. Reach for it at the call site instead.
|
|
77
|
+
- A control-flow combinator Effect already ships (`sequence`, `when`, `unless`,
|
|
78
|
+
…). Extend Effect's _data_ surface, don't re-implement its control flow.
|
|
79
|
+
|
|
80
|
+
When you are unsure, leave it at the call site. A helper graduates into this
|
|
81
|
+
package the moment a **second, unrelated** call site wants the same generic
|
|
82
|
+
shape — not before.
|
|
83
|
+
|
|
84
|
+
## Modules
|
|
85
|
+
|
|
86
|
+
Each module is exported as a namespace from the package root:
|
|
87
|
+
|
|
88
|
+
| Module | Extends / purpose |
|
|
89
|
+
| -------------- | -------------------------------------------------------------------------- |
|
|
90
|
+
| `ArrayX` | Array helpers (grouping, ordered insertion, `These`-zip) |
|
|
91
|
+
| `BigIntX` | BigInt helpers (`toNumberOrThrow`) |
|
|
92
|
+
| `BooleanX` | Boolean helpers |
|
|
93
|
+
| `DurationX` | Duration / DateTime diff helpers |
|
|
94
|
+
| `EffectX` | Effect bridges (`flattenOption`, `fromOptionOrElse`, `tryUntil`) |
|
|
95
|
+
| `FormDataX` | Schema-based `FormData` parsing |
|
|
96
|
+
| `MapX` | Native `Map` helpers |
|
|
97
|
+
| `NonNullableX` | Non-nullable assertions (`fromNullableOrThrow`, exported as `nn`) |
|
|
98
|
+
| `NumberX` | Number helpers |
|
|
99
|
+
| `OptionX` | Option helpers and rendering bridges |
|
|
100
|
+
| `OrderX` | `Order` helpers (`rankedEnum`) |
|
|
101
|
+
| `PredicateX` | Compound predicates (`isNonEmptyString`, `matchRefine`) |
|
|
102
|
+
| `PromiseX` | Promise helpers |
|
|
103
|
+
| `RecordX` | Record manipulation (`modifyIfExists`, `upsert`, `collectBy`) |
|
|
104
|
+
| `ResultX` | `Result` bridges (`fromOption`) |
|
|
105
|
+
| `SchemaX` | Effect Schema extensions (`pick`/`omit`/`partial`, branded strings) |
|
|
106
|
+
| `SetX` | Native `Set` helpers |
|
|
107
|
+
| `StringX` | String helpers |
|
|
108
|
+
| `StructX` | Conditional object-field construction (`defined`, `filterDefined`, `some`) |
|
|
109
|
+
| `These` | `These` data type (both / this / that) |
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
pnpm install
|
|
115
|
+
pnpm tc # typecheck (src + tests)
|
|
116
|
+
pnpm lint # ESLint (formatting included via eslint-plugin-prettier)
|
|
117
|
+
pnpm test # vitest run
|
|
118
|
+
pnpm build # emit dist/ (ESM + bundled .d.ts) via tsup
|
|
119
|
+
pnpm knip # unused code / deps
|
|
120
|
+
pnpm check-all # all of the above, in CI order
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Every public function needs exhaustive tests — every branch and edge case
|
|
124
|
+
(empty, single-element, boundary), plus type-level correctness where the whole
|
|
125
|
+
point of the helper is type narrowing. Generic utilities are consumed by every
|
|
126
|
+
layer above them and have no domain context to specify them other than their
|
|
127
|
+
tests, so the tests _are_ the spec.
|
|
128
|
+
|
|
129
|
+
See [AGENTS.md](./AGENTS.md) for the full contributor/agent guide (Effect
|
|
130
|
+
conventions, the `*X` module + barrel pattern, no `as` casts, commit/PR/release
|
|
131
|
+
workflow).
|
|
132
|
+
|
|
133
|
+
## Releasing
|
|
134
|
+
|
|
135
|
+
This package uses [Changesets](https://github.com/changesets/changesets).
|
|
136
|
+
|
|
137
|
+
1. Add a changeset describing your change: `pnpm changeset`.
|
|
138
|
+
2. Commit it and push/merge to `main`.
|
|
139
|
+
3. The **Release** workflow opens a "Version Packages" PR. Merging it publishes
|
|
140
|
+
to npm (with provenance) and creates a GitHub release.
|