massaman 0.1.0 → 0.3.0
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/README.md +11 -11
- package/dist/array/index.d.mts +1 -1
- package/dist/control/index.d.mts +3 -2
- package/dist/control/index.mjs +2 -2
- package/dist/{control-B8mDJqXw.mjs → control-Dg2fwHB7.mjs} +81 -2
- package/dist/control-Dg2fwHB7.mjs.map +1 -0
- package/dist/conversion/index.d.mts +1 -1
- package/dist/function/index.d.mts +1 -1
- package/dist/{index-COFf0Pih.d.mts → index-BjmDP8W9.d.mts} +1 -1
- package/dist/{index-COFf0Pih.d.mts.map → index-BjmDP8W9.d.mts.map} +1 -1
- package/dist/{index-Br9PO6mU.d.mts → index-Bp3ol0vr.d.mts} +73 -42
- package/dist/index-Bp3ol0vr.d.mts.map +1 -0
- package/dist/{index-DqsBQ7Pp.d.mts → index-D5l6I7QH.d.mts} +1 -1
- package/dist/{index-DqsBQ7Pp.d.mts.map → index-D5l6I7QH.d.mts.map} +1 -1
- package/dist/index-DtnKhaAD.d.mts +39 -0
- package/dist/index-DtnKhaAD.d.mts.map +1 -0
- package/dist/{index-B5x6pJw7.d.mts → index-g2aw5tc_.d.mts} +1 -1
- package/dist/{index-B5x6pJw7.d.mts.map → index-g2aw5tc_.d.mts.map} +1 -1
- package/dist/{index-BkyNt8th.d.mts → index-keGHab-v.d.mts} +1 -1
- package/dist/{index-BkyNt8th.d.mts.map → index-keGHab-v.d.mts.map} +1 -1
- package/dist/{index-Dw_tuZdb.d.mts → index-mfIoxwxy.d.mts} +1 -1
- package/dist/{index-Dw_tuZdb.d.mts.map → index-mfIoxwxy.d.mts.map} +1 -1
- package/dist/index.d.mts +9 -8
- package/dist/index.mjs +3 -3
- package/dist/match/index.d.mts +2 -0
- package/dist/match/index.mjs +2 -0
- package/dist/match-CG_v2C4Q.mjs +44 -0
- package/dist/match-CG_v2C4Q.mjs.map +1 -0
- package/dist/object/index.d.mts +1 -1
- package/dist/predicate/index.d.mts +1 -1
- package/dist/types-X6LqLWno.d.mts +42 -0
- package/dist/types-X6LqLWno.d.mts.map +1 -0
- package/package.json +4 -4
- package/dist/control-B8mDJqXw.mjs.map +0 -1
- package/dist/index-Br9PO6mU.d.mts.map +0 -1
- package/dist/pattern/index.d.mts +0 -2
- package/dist/pattern/index.mjs +0 -2
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/zrosenbauer/massaman/main/.github/assets/banner.png" alt="massaman" width="
|
|
2
|
+
<img src="https://raw.githubusercontent.com/zrosenbauer/massaman/main/.github/assets/banner.png" alt="massaman" width="100%" />
|
|
3
3
|
<p><strong>Functional programming utilities for TypeScript. Result types, pattern matching, async pipelines. Fully typed.</strong></p>
|
|
4
4
|
|
|
5
5
|
<a href="https://github.com/zrosenbauer/massaman/actions/workflows/ci.yml"><img src="https://github.com/zrosenbauer/massaman/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI" /></a>
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
13
|
+
- Rust's `match` in TypeScript: exhaustive pattern matching via re-exported [ts-pattern](https://github.com/gvergnaud/ts-pattern).
|
|
14
|
+
- Rust's `Result` in TypeScript: compose fallible operations without throws (`attempt`, `attemptAsync`, `ok`, `err`, `isOk`, `unwrap`).
|
|
15
|
+
- Functional programming, fully typed: `flow`, `flowAsync`, `tap`, `when`, `ifElse`, and point-free combinators with end-to-end inference.
|
|
16
|
+
- The missing pieces around [es-toolkit](https://es-toolkit.dev): variadic-narrowing predicates, async composition, and consistent error normalization on top of the array/object/string/math utilities you already love.
|
|
17
|
+
- Tree-shakeable: 12 focused subpath exports, ESM-only, `sideEffects: false`. Import only what you use.
|
|
18
18
|
|
|
19
19
|
## Install
|
|
20
20
|
|
|
@@ -29,7 +29,7 @@ npm install massaman
|
|
|
29
29
|
The `pattern` subpath is a transparent re-export of [ts-pattern](https://github.com/gvergnaud/ts-pattern). Exhaustive matching with full TypeScript inference.
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
|
-
import { match, P } from 'massaman/
|
|
32
|
+
import { match, P } from 'massaman/match'
|
|
33
33
|
|
|
34
34
|
const status = match(action)
|
|
35
35
|
.with({ type: 'load' }, () => 'loading')
|
|
@@ -40,7 +40,7 @@ const status = match(action)
|
|
|
40
40
|
|
|
41
41
|
### From es-toolkit
|
|
42
42
|
|
|
43
|
-
Most of the surface (`array`, `object`, `string`, `function`, `math`) is a transparent re-export of [es-toolkit](https://es-toolkit.
|
|
43
|
+
Most of the surface (`array`, `object`, `string`, `function`, `math`) is a transparent re-export of [es-toolkit](https://es-toolkit.dev). Same names, same behavior, same docs.
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
46
|
import { chunk, groupBy } from 'massaman'
|
|
@@ -91,7 +91,7 @@ match parsed {
|
|
|
91
91
|
The equivalent in TypeScript using `massaman`:
|
|
92
92
|
|
|
93
93
|
```ts
|
|
94
|
-
import { match, P } from 'massaman/
|
|
94
|
+
import { match, P } from 'massaman/match'
|
|
95
95
|
import { attempt, isOk } from 'massaman/control'
|
|
96
96
|
|
|
97
97
|
match(action)
|
|
@@ -108,9 +108,9 @@ if (isOk(parsed)) {
|
|
|
108
108
|
}
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
`massaman` brings both patterns to TypeScript, layered over [es-toolkit](https://es-toolkit.
|
|
111
|
+
`massaman` brings both patterns to TypeScript, layered over [es-toolkit](https://es-toolkit.dev) and [ts-pattern](https://github.com/gvergnaud/ts-pattern), plus a thin set of utilities filling the gaps: async-aware composition, variadic-narrowing predicates, and consistent error normalization.
|
|
112
112
|
|
|
113
|
-
More on the philosophy at [zrosenbauer.com/blog](https://zrosenbauer.com/blog).
|
|
113
|
+
More on the philosophy at [zrosenbauer.com/gui/blog](https://zrosenbauer.com/gui/blog).
|
|
114
114
|
|
|
115
115
|
## Contributing
|
|
116
116
|
|
package/dist/array/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as unionWith, A as last, B as remove, C as initial, D as isSubset, E as intersectionWith, F as orderBy, G as tail, H as sampleSize, I as partition, J as takeRightWhile, K as take, L as pull, M as mapAsync, N as maxBy, O as isSubsetWith, P as minBy, Q as unionBy, R as pullAt, S as head, T as intersectionBy, U as shuffle, V as sample, W as sortBy, X as toFilled, Y as takeWhile, Z as union, _ as flatten, _t as scan, a as difference, at as windowed, b as forEachRight, bt as adjust, c as drop, ct as xorBy, d as dropWhile, dt as zipObject, et as uniq, f as fill, ft as zipWith, g as flatMapDeep, gt as sortWith, h as flatMapAsync, ht as descend, i as countBy, it as unzipWith, j as limitAsync, k as keyBy, l as dropRight, lt as xorWith, m as flatMap, mt as ascend, n as chunk, nt as uniqWith, o as differenceBy, ot as without, p as filterAsync, pt as unfold, q as takeRight, r as compact, rt as unzip, s as differenceWith, st as xor, t as at, tt as uniqBy, u as dropRightWhile, ut as zip, v as flattenDeep, vt as reduceWhile, w as intersection, x as groupBy, y as forEachAsync, yt as dropRepeats, z as reduceAsync } from "../index-
|
|
1
|
+
import { $ as unionWith, A as last, B as remove, C as initial, D as isSubset, E as intersectionWith, F as orderBy, G as tail, H as sampleSize, I as partition, J as takeRightWhile, K as take, L as pull, M as mapAsync, N as maxBy, O as isSubsetWith, P as minBy, Q as unionBy, R as pullAt, S as head, T as intersectionBy, U as shuffle, V as sample, W as sortBy, X as toFilled, Y as takeWhile, Z as union, _ as flatten, _t as scan, a as difference, at as windowed, b as forEachRight, bt as adjust, c as drop, ct as xorBy, d as dropWhile, dt as zipObject, et as uniq, f as fill, ft as zipWith, g as flatMapDeep, gt as sortWith, h as flatMapAsync, ht as descend, i as countBy, it as unzipWith, j as limitAsync, k as keyBy, l as dropRight, lt as xorWith, m as flatMap, mt as ascend, n as chunk, nt as uniqWith, o as differenceBy, ot as without, p as filterAsync, pt as unfold, q as takeRight, r as compact, rt as unzip, s as differenceWith, st as xor, t as at, tt as uniqBy, u as dropRightWhile, ut as zip, v as flattenDeep, vt as reduceWhile, w as intersection, x as groupBy, y as forEachAsync, yt as dropRepeats, z as reduceAsync } from "../index-mfIoxwxy.mjs";
|
|
2
2
|
export { adjust, ascend, at, chunk, compact, countBy, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, fill, filterAsync, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, forEachAsync, forEachRight, groupBy, head, initial, intersection, intersectionBy, intersectionWith, isSubset, isSubsetWith, keyBy, last, limitAsync, mapAsync, maxBy, minBy, orderBy, partition, pull, pullAt, reduceAsync, reduceWhile, remove, sample, sampleSize, scan, shuffle, sortBy, sortWith, tail, take, takeRight, takeRightWhile, takeWhile, toFilled, unfold, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, windowed, without, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/control/index.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as Ok, r as Result, t as Err } from "../types-X6LqLWno.mjs";
|
|
2
|
+
import { a as todo, c as isOk, d as attempt, f as attemptAsync, i as unimplemented, l as ok, n as invariant, o as err, r as unreachable, s as isErr, t as assert, u as unwrap } from "../index-Bp3ol0vr.mjs";
|
|
3
|
+
export { Err, Ok, Result, assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, todo, unimplemented, unreachable, unwrap };
|
package/dist/control/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, unwrap };
|
|
1
|
+
import { a as todo, c as err, d as ok, f as unwrap, i as unimplemented, l as isErr, n as invariant, o as attempt, r as unreachable, s as attemptAsync, t as assert, u as isOk } from "../control-Dg2fwHB7.mjs";
|
|
2
|
+
export { assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, todo, unimplemented, unreachable, unwrap };
|
|
@@ -159,6 +159,85 @@ async function attemptAsync(fn) {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
//#endregion
|
|
162
|
-
|
|
162
|
+
//#region src/control/todo.ts
|
|
163
|
+
/**
|
|
164
|
+
* Stub for a code path you intend to write but haven't. Throws at runtime,
|
|
165
|
+
* returns `never` so it typechecks in any position.
|
|
166
|
+
*
|
|
167
|
+
* For paths you intentionally don't support, see `unimplemented`.
|
|
168
|
+
* For paths that should be impossible, see `unreachable`.
|
|
169
|
+
*
|
|
170
|
+
* @param message - Optional context appended to the thrown error
|
|
171
|
+
* @returns Never returns — always throws
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* function parseConfig(raw: string): Config {
|
|
176
|
+
* return todo('waiting on schema decision')
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
function todo(message) {
|
|
181
|
+
if (isNil(message)) throw new Error("not yet implemented");
|
|
182
|
+
throw new Error(`not yet implemented: ${message}`);
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/control/unimplemented.ts
|
|
186
|
+
/**
|
|
187
|
+
* Marks a code path as intentionally unsupported. Throws at runtime, returns
|
|
188
|
+
* `never` so it typechecks in any position.
|
|
189
|
+
*
|
|
190
|
+
* For work you plan to finish later, see `todo`.
|
|
191
|
+
* For paths that should be impossible, see `unreachable`.
|
|
192
|
+
*
|
|
193
|
+
* @param message - Optional context appended to the thrown error
|
|
194
|
+
* @returns Never returns — always throws
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* type Driver = 'postgres' | 'sqlite' | 'mysql'
|
|
199
|
+
*
|
|
200
|
+
* function migrate(driver: Driver): void {
|
|
201
|
+
* return match(driver)
|
|
202
|
+
* .with('postgres', runPgMigration)
|
|
203
|
+
* .with('sqlite', runSqliteMigration)
|
|
204
|
+
* .with('mysql', () => unimplemented('mysql driver intentionally unsupported'))
|
|
205
|
+
* .exhaustive()
|
|
206
|
+
* }
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
function unimplemented(message) {
|
|
210
|
+
if (isNil(message)) throw new Error("not implemented");
|
|
211
|
+
throw new Error(`not implemented: ${message}`);
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/control/unreachable.ts
|
|
215
|
+
/**
|
|
216
|
+
* Marks a code path as logically impossible. Throws at runtime if execution
|
|
217
|
+
* gets there. Returns `never` so it typechecks in any position.
|
|
218
|
+
*
|
|
219
|
+
* For work you plan to finish later, see `todo`.
|
|
220
|
+
* For paths you intentionally don't support, see `unimplemented`.
|
|
221
|
+
*
|
|
222
|
+
* @param message - Optional context appended to the thrown error
|
|
223
|
+
* @returns Never returns — always throws
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* function parseDigit(input: string): number {
|
|
228
|
+
* const parsed = Number.parseInt(input, 10)
|
|
229
|
+
* if (Number.isNaN(parsed)) {
|
|
230
|
+
* return unreachable('caller pre-validated')
|
|
231
|
+
* }
|
|
232
|
+
* return parsed
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
function unreachable(message) {
|
|
237
|
+
if (isNil(message)) throw new Error("entered unreachable code");
|
|
238
|
+
throw new Error(`entered unreachable code: ${message}`);
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
export { todo as a, err as c, ok as d, unwrap as f, unimplemented as i, isErr as l, invariant as n, attempt as o, unreachable as r, attemptAsync as s, assert as t, isOk as u };
|
|
163
242
|
|
|
164
|
-
//# sourceMappingURL=control-
|
|
243
|
+
//# sourceMappingURL=control-Dg2fwHB7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-Dg2fwHB7.mjs","names":[],"sources":["../src/control/result.ts","../src/control/attempt.ts","../src/control/todo.ts","../src/control/unimplemented.ts","../src/control/unreachable.ts"],"sourcesContent":["import { isNil } from 'es-toolkit/predicate'\n\nimport type { Err, Ok, Result } from './types.js'\n\n/**\n * Minimal error coercion used internally by `err()`. Kept local to avoid\n * pulling the full conversion module into the `massaman/control` bundle.\n * For richer stringification (Maps, Sets, Errors with own props, circular\n * refs), import `toError` from `massaman/conversion`.\n */\nfunction coerceError(thrown: unknown): Error {\n if (thrown instanceof Error) {\n return thrown\n }\n if (typeof thrown === 'string') {\n return new Error(thrown)\n }\n try {\n const message = JSON.stringify(thrown) ?? String(thrown)\n return new Error(message, { cause: thrown })\n } catch {\n return new Error(String(thrown), { cause: thrown })\n }\n}\n\n/**\n * Creates a success result wrapping the given value.\n *\n * @param value - The success value\n * @returns An `Ok` result containing the value\n *\n * @example\n * ```ts\n * const result = ok(42)\n * // { ok: true, value: 42 }\n * ```\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value, error: null }\n}\n\n/**\n * Creates a failure result wrapping the given error.\n *\n * @param error - The error value\n * @returns An `Err` result containing the error\n *\n * @example\n * ```ts\n * const result = err(new Error('fail'))\n * // { ok: false, error: Error('fail') }\n * ```\n */\nexport function err(error: unknown): Err {\n return { ok: false, value: null, error: coerceError(error) }\n}\n\n/**\n * Type guard that narrows a `Result` to `Ok`.\n *\n * @param result - The result to check\n * @returns `true` if the result is `Ok`\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('{}'))\n * if (isOk(result)) {\n * console.log(result.value)\n * }\n * ```\n */\nexport function isOk<T>(result: Result<T>): result is Ok<T> {\n return result.ok === true\n}\n\n/**\n * Type guard that narrows a `Result` to `Err`.\n *\n * @param result - The result to check\n * @returns `true` if the result is `Err`\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('bad'))\n * if (isErr(result)) {\n * console.error(result.error)\n * }\n * ```\n */\nexport function isErr<T>(result: Result<T>): result is Err {\n return result.ok === false\n}\n\n/**\n * Extract the value from an `Ok` result, or throw on `Err`.\n *\n * When called without a message, throws the original error.\n * When called with a message, throws a new Error with that message\n * and the original error as `cause` (like Rust's `expect`).\n *\n * @param result - The result to unwrap\n * @param message - Optional custom error message (Rust `expect` behavior)\n * @returns The unwrapped value\n *\n * @example\n * ```ts\n * const value = unwrap(ok(42)) // 42\n * unwrap(err('fail')) // throws Error('fail')\n * unwrap(err('fail'), 'config required') // throws Error('config required', { cause: Error('fail') })\n * ```\n */\nexport function unwrap<T>(result: Result<T>, message?: string): T {\n if (result.ok) {\n return result.value\n }\n if (!isNil(message)) {\n throw new Error(message, { cause: result.error })\n }\n throw result.error\n}\n","import { err, ok } from './result.js'\nimport type { Result } from './types.js'\n\n/**\n * Executes a synchronous function and wraps the outcome in a `Result`.\n * Returns `Ok` with the return value on success, `Err` with the thrown value on failure.\n *\n * @param fn - The function to execute\n * @returns A `Result` containing either the value or the error\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('{\"a\":1}'))\n * if (isOk(result)) {\n * console.log(result.value) // { a: 1 }\n * }\n * ```\n */\nexport function attempt<T>(fn: () => T): Result<T> {\n try {\n return ok(fn())\n } catch (error) {\n return err(error)\n }\n}\n\n/**\n * Executes an asynchronous function and wraps the outcome in a `Result`.\n * Returns `Ok` with the resolved value on success, `Err` with the rejection reason on failure.\n *\n * @param fn - The async function to execute\n * @returns A promise resolving to a `Result` containing either the value or the error\n *\n * @example\n * ```ts\n * const result = await attemptAsync(() => fetch('/api/data'))\n * if (isErr(result)) {\n * console.error(result.error)\n * }\n * ```\n */\nexport async function attemptAsync<T>(fn: () => Promise<T>): Promise<Result<T>> {\n try {\n return ok(await fn())\n } catch (error) {\n return err(error)\n }\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Stub for a code path you intend to write but haven't. Throws at runtime,\n * returns `never` so it typechecks in any position.\n *\n * For paths you intentionally don't support, see `unimplemented`.\n * For paths that should be impossible, see `unreachable`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * function parseConfig(raw: string): Config {\n * return todo('waiting on schema decision')\n * }\n * ```\n */\nexport function todo(message?: string): never {\n if (isNil(message)) {\n throw new Error('not yet implemented')\n }\n throw new Error(`not yet implemented: ${message}`)\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Marks a code path as intentionally unsupported. Throws at runtime, returns\n * `never` so it typechecks in any position.\n *\n * For work you plan to finish later, see `todo`.\n * For paths that should be impossible, see `unreachable`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * type Driver = 'postgres' | 'sqlite' | 'mysql'\n *\n * function migrate(driver: Driver): void {\n * return match(driver)\n * .with('postgres', runPgMigration)\n * .with('sqlite', runSqliteMigration)\n * .with('mysql', () => unimplemented('mysql driver intentionally unsupported'))\n * .exhaustive()\n * }\n * ```\n */\nexport function unimplemented(message?: string): never {\n if (isNil(message)) {\n throw new Error('not implemented')\n }\n throw new Error(`not implemented: ${message}`)\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Marks a code path as logically impossible. Throws at runtime if execution\n * gets there. Returns `never` so it typechecks in any position.\n *\n * For work you plan to finish later, see `todo`.\n * For paths you intentionally don't support, see `unimplemented`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * function parseDigit(input: string): number {\n * const parsed = Number.parseInt(input, 10)\n * if (Number.isNaN(parsed)) {\n * return unreachable('caller pre-validated')\n * }\n * return parsed\n * }\n * ```\n */\nexport function unreachable(message?: string): never {\n if (isNil(message)) {\n throw new Error('entered unreachable code')\n }\n throw new Error(`entered unreachable code: ${message}`)\n}\n"],"mappings":";;;;;;;;;AAUA,SAAS,YAAY,QAAwB;CAC3C,IAAI,kBAAkB,OACpB,OAAO;CAET,IAAI,OAAO,WAAW,UACpB,OAAO,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ACrD,IAAI,MAAM,QAAQ,EAChB,MAAM,IAAI,MAAM,kBAAkB;CAEpC,MAAM,IAAI,MAAM,oBAAoB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;ACNhD,SAAgB,YAAY,SAAyB;CACnD,IAAI,MAAM,QAAQ,EAChB,MAAM,IAAI,MAAM,2BAA2B;CAE7C,MAAM,IAAI,MAAM,6BAA6B,UAAU"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as toFinite, c as toString, i as toError, n as toArray, o as toInteger, r as toBoolean, s as toNumber, t as stringify } from "../index-
|
|
1
|
+
import { a as toFinite, c as toString, i as toError, n as toArray, o as toInteger, r as toBoolean, s as toNumber, t as stringify } from "../index-BjmDP8W9.mjs";
|
|
2
2
|
export { stringify, toArray, toBoolean, toError, toFinite, toInteger, toNumber, toString };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as unless, C as retry, D as flowAsync, E as unary, M as call, N as callAsync, O as tap, S as rest, T as throttle, _ as negate, a as ThrottledFunction, b as partial, c as asyncNoop, d as curryRight, f as debounce, g as memoize, h as identity, i as ThrottleOptions, j as when, k as ifElse, l as before, m as flowRight, n as DebouncedFunction, o as after, p as flow, r as MemoizeCache, s as ary, t as DebounceOptions, u as curry, v as noop, w as spread, x as partialRight, y as once } from "../index-
|
|
1
|
+
import { A as unless, C as retry, D as flowAsync, E as unary, M as call, N as callAsync, O as tap, S as rest, T as throttle, _ as negate, a as ThrottledFunction, b as partial, c as asyncNoop, d as curryRight, f as debounce, g as memoize, h as identity, i as ThrottleOptions, j as when, k as ifElse, l as before, m as flowRight, n as DebouncedFunction, o as after, p as flow, r as MemoizeCache, s as ary, t as DebounceOptions, u as curry, v as noop, w as spread, x as partialRight, y as once } from "../index-D5l6I7QH.mjs";
|
|
2
2
|
export { DebounceOptions, DebouncedFunction, MemoizeCache, ThrottleOptions, ThrottledFunction, after, ary, asyncNoop, before, call, callAsync, curry, curryRight, debounce, flow, flowAsync, flowRight, identity, ifElse, memoize, negate, noop, once, partial, partialRight, rest, retry, spread, tap, throttle, unary, unless, when };
|
|
@@ -125,4 +125,4 @@ declare function toArray<T>(value: Iterable<T> | T | null | undefined): T[];
|
|
|
125
125
|
declare function toBoolean(value: unknown): boolean;
|
|
126
126
|
//#endregion
|
|
127
127
|
export { toFinite as a, toString as c, toError as i, toArray as n, toInteger as o, toBoolean as r, toNumber as s, stringify as t };
|
|
128
|
-
//# sourceMappingURL=index-
|
|
128
|
+
//# sourceMappingURL=index-BjmDP8W9.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-BjmDP8W9.d.mts","names":[],"sources":["../src/conversion/convert.ts"],"mappings":";;AAwBA;;;;;AA8BA;;;;;AAiFA;;;;;AAgBA;;;;;AAaA;iBA5IgB,OAAA,CAAQ,MAAA,YAAkB,KAAA;;;;AA2J1C;;;;;AAwBA;;;;;;;;;;;;iBArJgB,SAAA,CAAU,KAAA;;;;;AA+K1B;;;;;;;;;iBA9FgB,QAAA,CAAS,KAAA;;;;;;;;;;;;;iBAgBT,QAAA,CAAS,KAAA;;;;;;;;;;iBAaT,SAAA,CAAU,KAAA;;;;;;;;;;;;iBAeV,QAAA,CAAS,KAAA;;;;;;;;;;;;;;;;;iBAwBT,OAAA,GAAA,CAAW,KAAA,EAAO,QAAA,CAAS,CAAA,IAAK,CAAA,sBAAuB,CAAA;;;;;;;;;;;;;;iBA0BvD,SAAA,CAAU,KAAA"}
|
|
@@ -1,45 +1,6 @@
|
|
|
1
|
+
import { n as Ok, r as Result, t as Err } from "./types-X6LqLWno.mjs";
|
|
1
2
|
import { assert, invariant } from "es-toolkit/util";
|
|
2
3
|
|
|
3
|
-
//#region src/control/types.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Success result containing a value.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const result: Ok<number> = { ok: true, value: 42 }
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
interface Ok<T> {
|
|
13
|
-
readonly ok: true;
|
|
14
|
-
readonly value: T;
|
|
15
|
-
readonly error: null;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Failure result containing an error.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const result: Err = { ok: false, error: new Error('fail') }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
interface Err {
|
|
26
|
-
readonly ok: false;
|
|
27
|
-
readonly value: null;
|
|
28
|
-
readonly error: Error;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Discriminated union representing either success (`Ok`) or failure (`Err`).
|
|
32
|
-
* Inspired by Rust's `Result<T, E>`, but errors are always `Error`.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* function divide(a: number, b: number): Result<number> {
|
|
37
|
-
* return b === 0 ? err('division by zero') : ok(a / b)
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
type Result<T> = Ok<T> | Err;
|
|
42
|
-
//#endregion
|
|
43
4
|
//#region src/control/attempt.d.ts
|
|
44
5
|
/**
|
|
45
6
|
* Executes a synchronous function and wraps the outcome in a `Result`.
|
|
@@ -151,5 +112,75 @@ declare function isErr<T>(result: Result<T>): result is Err;
|
|
|
151
112
|
*/
|
|
152
113
|
declare function unwrap<T>(result: Result<T>, message?: string): T;
|
|
153
114
|
//#endregion
|
|
154
|
-
|
|
155
|
-
|
|
115
|
+
//#region src/control/todo.d.ts
|
|
116
|
+
/**
|
|
117
|
+
* Stub for a code path you intend to write but haven't. Throws at runtime,
|
|
118
|
+
* returns `never` so it typechecks in any position.
|
|
119
|
+
*
|
|
120
|
+
* For paths you intentionally don't support, see `unimplemented`.
|
|
121
|
+
* For paths that should be impossible, see `unreachable`.
|
|
122
|
+
*
|
|
123
|
+
* @param message - Optional context appended to the thrown error
|
|
124
|
+
* @returns Never returns — always throws
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* function parseConfig(raw: string): Config {
|
|
129
|
+
* return todo('waiting on schema decision')
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function todo(message?: string): never;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/control/unimplemented.d.ts
|
|
136
|
+
/**
|
|
137
|
+
* Marks a code path as intentionally unsupported. Throws at runtime, returns
|
|
138
|
+
* `never` so it typechecks in any position.
|
|
139
|
+
*
|
|
140
|
+
* For work you plan to finish later, see `todo`.
|
|
141
|
+
* For paths that should be impossible, see `unreachable`.
|
|
142
|
+
*
|
|
143
|
+
* @param message - Optional context appended to the thrown error
|
|
144
|
+
* @returns Never returns — always throws
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* type Driver = 'postgres' | 'sqlite' | 'mysql'
|
|
149
|
+
*
|
|
150
|
+
* function migrate(driver: Driver): void {
|
|
151
|
+
* return match(driver)
|
|
152
|
+
* .with('postgres', runPgMigration)
|
|
153
|
+
* .with('sqlite', runSqliteMigration)
|
|
154
|
+
* .with('mysql', () => unimplemented('mysql driver intentionally unsupported'))
|
|
155
|
+
* .exhaustive()
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare function unimplemented(message?: string): never;
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/control/unreachable.d.ts
|
|
162
|
+
/**
|
|
163
|
+
* Marks a code path as logically impossible. Throws at runtime if execution
|
|
164
|
+
* gets there. Returns `never` so it typechecks in any position.
|
|
165
|
+
*
|
|
166
|
+
* For work you plan to finish later, see `todo`.
|
|
167
|
+
* For paths you intentionally don't support, see `unimplemented`.
|
|
168
|
+
*
|
|
169
|
+
* @param message - Optional context appended to the thrown error
|
|
170
|
+
* @returns Never returns — always throws
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* function parseDigit(input: string): number {
|
|
175
|
+
* const parsed = Number.parseInt(input, 10)
|
|
176
|
+
* if (Number.isNaN(parsed)) {
|
|
177
|
+
* return unreachable('caller pre-validated')
|
|
178
|
+
* }
|
|
179
|
+
* return parsed
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function unreachable(message?: string): never;
|
|
184
|
+
//#endregion
|
|
185
|
+
export { todo as a, isOk as c, attempt as d, attemptAsync as f, unimplemented as i, ok as l, invariant as n, err as o, unreachable as r, isErr as s, assert as t, unwrap as u };
|
|
186
|
+
//# sourceMappingURL=index-Bp3ol0vr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Bp3ol0vr.d.mts","names":[],"sources":["../src/control/attempt.ts","../src/control/result.ts","../src/control/todo.ts","../src/control/unimplemented.ts","../src/control/unreachable.ts"],"mappings":";;;;;;;AAkBA;;;;;;;;;;;;iBAAgB,OAAA,GAAA,CAAW,EAAA,QAAU,CAAA,GAAI,MAAA,CAAO,CAAA;;;AAuBhD;;;;;;;;;;;;;iBAAsB,YAAA,GAAA,CAAgB,EAAA,QAAU,OAAA,CAAQ,CAAA,IAAK,OAAA,CAAQ,MAAA,CAAO,CAAA;;;;;;AAvB5E;;;;;;;;;iBCmBgB,EAAA,GAAA,CAAM,KAAA,EAAO,CAAA,GAAI,EAAA,CAAG,CAAA;;;;;;ADIpC;;;;;;;iBCYgB,GAAA,CAAI,KAAA,YAAiB,GAAA;;;;;;;;;;;;;;;iBAkBrB,IAAA,GAAA,CAAQ,MAAA,EAAQ,MAAA,CAAO,CAAA,IAAK,MAAA,IAAU,EAAA,CAAG,CAAA;;;;;;;;;;;;;;;iBAkBzC,KAAA,GAAA,CAAS,MAAA,EAAQ,MAAA,CAAO,CAAA,IAAK,MAAA,IAAU,GAAA;;;;;AAlBvD;;;;;;;;;;;;;;iBAwCgB,MAAA,GAAA,CAAU,MAAA,EAAQ,MAAA,CAAO,CAAA,GAAI,OAAA,YAAmB,CAAA;;;;;;;AD7FhE;;;;;;;;;;;;;iBECgB,IAAA,CAAK,OAAA;;;;;;;AFDrB;;;;;;;;;;;;;;;AAuBA;;;;iBGhBgB,aAAA,CAAc,OAAA;;;;;;;AHP9B;;;;;;;;;;;;;;;AAuBA;;iBIlBgB,WAAA,CAAY,OAAA"}
|
|
@@ -117,4 +117,4 @@ declare function flowAsync<A extends readonly unknown[], R1, R2, R3, R4, R5, R6>
|
|
|
117
117
|
declare function flowAsync<A extends readonly unknown[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: A) => MaybePromise<R1>, f2: (a: Awaited<R1>) => MaybePromise<R2>, f3: (a: Awaited<R2>) => MaybePromise<R3>, f4: (a: Awaited<R3>) => MaybePromise<R4>, f5: (a: Awaited<R4>) => MaybePromise<R5>, f6: (a: Awaited<R5>) => MaybePromise<R6>, f7: (a: Awaited<R6>) => MaybePromise<R7>): (...args: A) => Promise<Awaited<R7>>;
|
|
118
118
|
//#endregion
|
|
119
119
|
export { unless as A, retry as C, flowAsync as D, unary as E, call as M, callAsync as N, tap as O, rest as S, throttle as T, negate as _, ThrottledFunction as a, partial as b, asyncNoop as c, curryRight as d, debounce as f, memoize as g, identity as h, ThrottleOptions as i, when as j, ifElse as k, before as l, flowRight as m, DebouncedFunction as n, after as o, flow as p, MemoizeCache as r, ary as s, DebounceOptions as t, curry as u, noop as v, spread as w, partialRight as x, once as y };
|
|
120
|
-
//# sourceMappingURL=index-
|
|
120
|
+
//# sourceMappingURL=index-D5l6I7QH.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-D5l6I7QH.d.mts","names":[],"sources":["../src/function/call.ts","../src/function/branching.ts","../src/function/tap.ts","../src/function/flowAsync.ts"],"mappings":";;;;;;AAcA;;;;;;;;;;;iBAA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import { NonExhaustiveError, P, Pattern, isMatching, match } from "ts-pattern";
|
|
3
|
+
|
|
4
|
+
//#region src/match/match.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Extended ts-pattern `P` namespace. Carries everything ts-pattern exports
|
|
7
|
+
* (`P.string`, `P.number`, `P.array`, `P.when`, …) plus `P.ok` / `P.err`
|
|
8
|
+
* for matching `Result` values.
|
|
9
|
+
*
|
|
10
|
+
* Explicit literal-type annotations on the additions (rather than `as const`)
|
|
11
|
+
* keep the values non-`readonly`, which ts-pattern's narrowing requires —
|
|
12
|
+
* a `readonly` pattern collapses the remaining input to `never` after the
|
|
13
|
+
* first arm, breaking exhaustiveness.
|
|
14
|
+
*
|
|
15
|
+
* For the `P.Pattern<T>` type shorthand, import `Pattern` standalone from
|
|
16
|
+
* `massaman/match` — it's the form ts-pattern's own docs recommend.
|
|
17
|
+
*/
|
|
18
|
+
declare const P$1: typeof P & {
|
|
19
|
+
ok: {
|
|
20
|
+
ok: true;
|
|
21
|
+
};
|
|
22
|
+
err: {
|
|
23
|
+
ok: false;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The `Ok` variant of a `Result<T>`. Re-exported here so the value-side
|
|
28
|
+
* patterns and the type-side `Ok<T>` live in one module — any consumer
|
|
29
|
+
* import gets both type and value namespaces without cross-module merge
|
|
30
|
+
* issues (TS2300).
|
|
31
|
+
*/
|
|
32
|
+
type Ok<T> = Ok$1<T>;
|
|
33
|
+
/**
|
|
34
|
+
* The `Err` variant of a `Result<T>`. See {@link Ok} for the co-location note.
|
|
35
|
+
*/
|
|
36
|
+
type Err = Err$1;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { Err as a, match as i, Pattern as n, Ok as o, isMatching as r, P$1 as s, NonExhaustiveError as t };
|
|
39
|
+
//# sourceMappingURL=index-DtnKhaAD.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-DtnKhaAD.d.mts","names":[],"sources":["../src/match/match.ts"],"mappings":";;;;;;;;AAwDA;;;;;;;;;cAjBa,GAAA,SAAU,CAAA;EAAQ,EAAA;IAAM,EAAA;EAAA;EAAY,GAAA;IAAO,EAAA;EAAA;AAAA;;;;;;;KAY5C,EAAA,MAAQ,IAAA,CAAO,CAAA;;;;KAKf,GAAA,GAAM,KAAA"}
|
|
@@ -183,4 +183,4 @@ declare function isInteger(value: unknown): value is number;
|
|
|
183
183
|
declare function isNaN(value: unknown): value is number;
|
|
184
184
|
//#endregion
|
|
185
185
|
export { isSymbol as A, isNotEmpty as B, isNumber as C, isRegExp as D, isPromise as E, isArray as F, either as G, allPass as H, isEmpty as I, isFiniteNumber as L, isUndefined as M, isWeakMap as N, isSet$1 as O, isWeakSet as P, isInteger as R, isNull as S, isPrimitive$1 as T, anyPass as U, isObject as V, both as W, isLength as _, isBuffer as a, isNode as b, isEqual as c, isFile as d, isFunction as f, isJSONValue as g, isJSONObject as h, isBrowser as i, isTypedArray as j, isString$1 as k, isEqualWith as l, isJSONArray as m, isBlob as n, isDate as o, isJSON as p, isBoolean as r, isEmptyObject as s, isArrayBuffer as t, isError$1 as u, isMap$1 as v, isPlainObject as w, isNotNil as x, isNil$1 as y, isNaN as z };
|
|
186
|
-
//# sourceMappingURL=index-
|
|
186
|
+
//# sourceMappingURL=index-g2aw5tc_.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-g2aw5tc_.d.mts","names":[],"sources":["../src/types/internal.ts","../src/predicate/combinators.ts","../src/predicate/guards.ts"],"mappings":";;;;;;AAkBA;;;;;;;;ACEA;;;;;;KDFY,mBAAA;;;;;AAAZ;;;;;;;;ACEA;;;;;;;;iBAAgB,OAAA,GAAA,CAAW,UAAA,iBAA2B,KAAA,EAAO,CAAA;AAAA,iBAC7C,OAAA,YAAmB,aAAA,EAAe,KAAA,EAAO,mBAAA,cAAA,CACvD,UAAA,EAAY,EAAA,IACV,KAAA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AAA,SAAW,aAAA,EAAe,KAAA,yBAA8B,CAAA;AAAA,KAEzE,mBAAA,OAA0B,CAAA,oBAAqB,CAAA,EAAG,CAAA,6BACrD,CAAA,sBAEE,CAAA;;;;;;ADnGJ;;;;;;iBETgB,OAAA,CAAQ,KAAA,YAAiB,KAAA;;ADWzC;;;;;;;;;;AACA;iBCIgB,QAAA,CAAS,KAAA,YAAiB,KAAA;;;;;;;;;;;;;;;;;iBAoB1B,OAAA,CAAQ,KAAA;;;;;;;;;;iBAmBR,UAAA,CAAW,KAAA;;;;ADjB3B;;;;;;iBC8BgB,cAAA,CAAe,KAAA,YAAiB,KAAA;;;;AD7BhD;;;;;;iBC0CgB,SAAA,CAAU,KAAA,YAAiB,KAAA;;;;;;;;;;iBAa3B,KAAA,CAAM,KAAA,YAAiB,KAAA"}
|
|
@@ -17,4 +17,4 @@ import { clone, cloneDeep, cloneDeepWith, findKey, flattenObject, invert, mapKey
|
|
|
17
17
|
declare function evolve<T extends Record<string, unknown>>(obj: T, spec: { [K in keyof T]?: (value: T[K]) => T[K] }): T;
|
|
18
18
|
//#endregion
|
|
19
19
|
export { toSnakeCaseKeys as _, flattenObject as a, mapValues as c, omit as d, omitBy as f, toMerged as g, toCamelCaseKeys as h, findKey as i, merge as l, pickBy as m, cloneDeep as n, invert as o, pick as p, cloneDeepWith as r, mapKeys as s, clone as t, mergeWith as u, evolve as v };
|
|
20
|
-
//# sourceMappingURL=index-
|
|
20
|
+
//# sourceMappingURL=index-keGHab-v.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-keGHab-v.d.mts","names":[],"sources":["../src/object/evolve.ts"],"mappings":";;;;;;AAaA;;;;;;;;;;iBAAgB,MAAA,WAAiB,MAAA,kBAAA,CAC/B,GAAA,EAAK,CAAA,EACL,IAAA,gBAAoB,CAAA,KAAM,KAAA,EAAO,CAAA,CAAE,CAAA,MAAO,CAAA,CAAE,CAAA,MAC3C,CAAA"}
|
|
@@ -131,4 +131,4 @@ declare function sortWith<T>(array: readonly T[], comparators: ReadonlyArray<(a:
|
|
|
131
131
|
declare function unfold<T, R>(fn: (seed: T) => [R, T] | false, seed: T): R[];
|
|
132
132
|
//#endregion
|
|
133
133
|
export { unionWith as $, last as A, remove as B, initial as C, isSubset as D, intersectionWith as E, orderBy as F, tail as G, sampleSize as H, partition as I, takeRightWhile as J, take as K, pull as L, mapAsync as M, maxBy as N, isSubsetWith as O, minBy as P, unionBy as Q, pullAt as R, head as S, intersectionBy as T, shuffle as U, sample as V, sortBy as W, toFilled as X, takeWhile as Y, union as Z, flatten as _, scan as _t, difference as a, windowed as at, forEachRight as b, adjust as bt, drop as c, xorBy as ct, dropWhile as d, zipObject as dt, uniq as et, fill as f, zipWith as ft, flatMapDeep as g, sortWith as gt, flatMapAsync as h, descend as ht, countBy as i, unzipWith as it, limitAsync as j, keyBy as k, dropRight as l, xorWith as lt, flatMap as m, ascend as mt, chunk as n, uniqWith as nt, differenceBy as o, without as ot, filterAsync as p, unfold as pt, takeRight as q, compact as r, unzip as rt, differenceWith as s, xor as st, at as t, uniqBy as tt, dropRightWhile as u, zip as ut, flattenDeep as v, reduceWhile as vt, intersection as w, groupBy as x, forEachAsync as y, dropRepeats as yt, reduceAsync as z };
|
|
134
|
-
//# sourceMappingURL=index-
|
|
134
|
+
//# sourceMappingURL=index-mfIoxwxy.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-mfIoxwxy.d.mts","names":[],"sources":["../src/array/adjust.ts","../src/array/dropRepeats.ts","../src/array/reduceWhile.ts","../src/array/scan.ts","../src/array/sorting.ts","../src/array/unfold.ts"],"mappings":";;;;;;AAYA;;;;;;;;;iBAAgB,MAAA,GAAA,CAAU,KAAA,WAAgB,CAAA,IAAK,KAAA,UAAe,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,CAAA;;;;;;AAApF;;;;;;;;;;;;;;;iBCMgB,WAAA,GAAA,CAAe,KAAA,WAAgB,CAAA,KAAM,CAAA;;;;;;ADNrD;;;;;;;;;;;;;;;;iBEOgB,WAAA,MAAA,CACd,KAAA,WAAgB,CAAA,IAChB,SAAA,GAAY,WAAA,EAAa,CAAA,EAAG,KAAA,EAAO,CAAA,cACnC,EAAA,GAAK,WAAA,EAAa,CAAA,EAAG,KAAA,EAAO,CAAA,EAAG,KAAA,aAAkB,CAAA,EACjD,OAAA,EAAS,CAAA,GACR,CAAA;;;;;;AFZH;;;;;;;;;iBGAgB,IAAA,MAAA,CACd,KAAA,WAAgB,CAAA,IAChB,EAAA,GAAK,WAAA,EAAa,CAAA,EAAG,KAAA,EAAO,CAAA,EAAG,KAAA,aAAkB,CAAA,EACjD,OAAA,EAAS,CAAA,GACR,CAAA;;;;;;AHJH;;;;;iBIJgB,MAAA,GAAA,CAAU,EAAA,GAAK,KAAA,EAAO,CAAA,wBAAyB,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA;;;;;;;;;iBAsBxD,OAAA,GAAA,CAAW,EAAA,GAAK,KAAA,EAAO,CAAA,wBAAyB,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA;;;;;;;;;AHZzE;;;;;;iBGwCgB,QAAA,GAAA,CACd,KAAA,WAAgB,CAAA,IAChB,WAAA,EAAa,aAAA,EAAe,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,eACpC,CAAA;;;;;;AJjDH;;;;;;;;;;;;;;;;iBKOgB,MAAA,MAAA,CAAa,EAAA,GAAK,IAAA,EAAM,CAAA,MAAO,CAAA,EAAG,CAAA,WAAY,IAAA,EAAM,CAAA,GAAI,CAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { $ as unionWith, A as last, B as remove, C as initial, D as isSubset, E as intersectionWith, F as orderBy, G as tail, H as sampleSize, I as partition, J as takeRightWhile, K as take, L as pull, M as mapAsync, N as maxBy, O as isSubsetWith, P as minBy, Q as unionBy, R as pullAt, S as head, T as intersectionBy, U as shuffle, V as sample, W as sortBy, X as toFilled, Y as takeWhile, Z as union, _ as flatten, _t as scan, a as difference, at as windowed, b as forEachRight, bt as adjust, c as drop, ct as xorBy, d as dropWhile, dt as zipObject, et as uniq, f as fill, ft as zipWith, g as flatMapDeep, gt as sortWith, h as flatMapAsync, ht as descend, i as countBy, it as unzipWith, j as limitAsync, k as keyBy, l as dropRight, lt as xorWith, m as flatMap, mt as ascend, n as chunk, nt as uniqWith, o as differenceBy, ot as without, p as filterAsync, pt as unfold, q as takeRight, r as compact, rt as unzip, s as differenceWith, st as xor, t as at, tt as uniqBy, u as dropRightWhile, ut as zip, v as flattenDeep, vt as reduceWhile, w as intersection, x as groupBy, y as forEachAsync, yt as dropRepeats, z as reduceAsync } from "./index-
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
1
|
+
import { $ as unionWith, A as last, B as remove, C as initial, D as isSubset, E as intersectionWith, F as orderBy, G as tail, H as sampleSize, I as partition, J as takeRightWhile, K as take, L as pull, M as mapAsync, N as maxBy, O as isSubsetWith, P as minBy, Q as unionBy, R as pullAt, S as head, T as intersectionBy, U as shuffle, V as sample, W as sortBy, X as toFilled, Y as takeWhile, Z as union, _ as flatten, _t as scan, a as difference, at as windowed, b as forEachRight, bt as adjust, c as drop, ct as xorBy, d as dropWhile, dt as zipObject, et as uniq, f as fill, ft as zipWith, g as flatMapDeep, gt as sortWith, h as flatMapAsync, ht as descend, i as countBy, it as unzipWith, j as limitAsync, k as keyBy, l as dropRight, lt as xorWith, m as flatMap, mt as ascend, n as chunk, nt as uniqWith, o as differenceBy, ot as without, p as filterAsync, pt as unfold, q as takeRight, r as compact, rt as unzip, s as differenceWith, st as xor, t as at, tt as uniqBy, u as dropRightWhile, ut as zip, v as flattenDeep, vt as reduceWhile, w as intersection, x as groupBy, y as forEachAsync, yt as dropRepeats, z as reduceAsync } from "./index-mfIoxwxy.mjs";
|
|
2
|
+
import { r as Result } from "./types-X6LqLWno.mjs";
|
|
3
|
+
import { a as todo, c as isOk, d as attempt, f as attemptAsync, i as unimplemented, l as ok, n as invariant, o as err, r as unreachable, s as isErr, t as assert, u as unwrap } from "./index-Bp3ol0vr.mjs";
|
|
4
|
+
import { a as toFinite, c as toString, i as toError, n as toArray, o as toInteger, r as toBoolean, s as toNumber, t as stringify } from "./index-BjmDP8W9.mjs";
|
|
4
5
|
import { AbortError, TimeoutError } from "./error/index.mjs";
|
|
5
|
-
import { A as unless, C as retry, D as flowAsync, E as unary, M as call, N as callAsync, O as tap, S as rest, T as throttle, _ as negate, a as ThrottledFunction, b as partial, c as asyncNoop, d as curryRight, f as debounce, g as memoize, h as identity, i as ThrottleOptions, j as when, k as ifElse, l as before, m as flowRight, n as DebouncedFunction, o as after, p as flow, r as MemoizeCache, s as ary, t as DebounceOptions, u as curry, v as noop, w as spread, x as partialRight, y as once } from "./index-
|
|
6
|
+
import { A as unless, C as retry, D as flowAsync, E as unary, M as call, N as callAsync, O as tap, S as rest, T as throttle, _ as negate, a as ThrottledFunction, b as partial, c as asyncNoop, d as curryRight, f as debounce, g as memoize, h as identity, i as ThrottleOptions, j as when, k as ifElse, l as before, m as flowRight, n as DebouncedFunction, o as after, p as flow, r as MemoizeCache, s as ary, t as DebounceOptions, u as curry, v as noop, w as spread, x as partialRight, y as once } from "./index-D5l6I7QH.mjs";
|
|
6
7
|
import { clamp, inRange, mean, meanBy, median, medianBy, random, randomInt, range, rangeRight, round, sum, sumBy } from "./math/index.mjs";
|
|
7
|
-
import { _ as toSnakeCaseKeys, a as flattenObject, c as mapValues, d as omit, f as omitBy, g as toMerged, h as toCamelCaseKeys, i as findKey, l as merge, m as pickBy, n as cloneDeep, o as invert, p as pick, r as cloneDeepWith, s as mapKeys, t as clone, u as mergeWith, v as evolve } from "./index-
|
|
8
|
-
import { A as isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPromise, F as isArray, G as either, H as allPass, I as isEmpty, L as isFiniteNumber, M as isUndefined, N as isWeakMap, O as isSet, P as isWeakSet, R as isInteger, S as isNull, T as isPrimitive, U as anyPass, V as isObject, W as both, _ as isLength, a as isBuffer, b as isNode, c as isEqual, d as isFile, f as isFunction, g as isJSONValue, h as isJSONObject, i as isBrowser, j as isTypedArray, k as isString, l as isEqualWith, m as isJSONArray, n as isBlob, o as isDate, p as isJSON, r as isBoolean, s as isEmptyObject, t as isArrayBuffer, u as isError, v as isMap, w as isPlainObject, x as isNotNil, y as isNil, z as isNaN } from "./index-
|
|
8
|
+
import { _ as toSnakeCaseKeys, a as flattenObject, c as mapValues, d as omit, f as omitBy, g as toMerged, h as toCamelCaseKeys, i as findKey, l as merge, m as pickBy, n as cloneDeep, o as invert, p as pick, r as cloneDeepWith, s as mapKeys, t as clone, u as mergeWith, v as evolve } from "./index-keGHab-v.mjs";
|
|
9
|
+
import { A as isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPromise, F as isArray, G as either, H as allPass, I as isEmpty, L as isFiniteNumber, M as isUndefined, N as isWeakMap, O as isSet, P as isWeakSet, R as isInteger, S as isNull, T as isPrimitive, U as anyPass, V as isObject, W as both, _ as isLength, a as isBuffer, b as isNode, c as isEqual, d as isFile, f as isFunction, g as isJSONValue, h as isJSONObject, i as isBrowser, j as isTypedArray, k as isString, l as isEqualWith, m as isJSONArray, n as isBlob, o as isDate, p as isJSON, r as isBoolean, s as isEmptyObject, t as isArrayBuffer, u as isError, v as isMap, w as isPlainObject, x as isNotNil, y as isNil, z as isNaN } from "./index-g2aw5tc_.mjs";
|
|
9
10
|
import { Mutex, Semaphore, delay, timeout, withTimeout } from "./promise/index.mjs";
|
|
10
11
|
import { camelCase, capitalize, constantCase, deburr, escape, escapeRegExp, kebabCase, lowerCase, lowerFirst, pad, pascalCase, reverseString, snakeCase, startCase, trim, trimEnd, trimStart, unescape, upperCase, upperFirst, words } from "./string/index.mjs";
|
|
11
|
-
import {
|
|
12
|
-
export { AbortError, type DebounceOptions, type DebouncedFunction, type Err, type MemoizeCache, Mutex, NonExhaustiveError, type Ok, P, Pattern, type Result, Semaphore, type ThrottleOptions, type ThrottledFunction, TimeoutError, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, either, err, escape, escapeRegExp, evolve, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowAsync, flowRight, forEachAsync, forEachRight, groupBy, head, identity, ifElse, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isErr, isError, isFile, isFiniteNumber, isFunction, isInteger, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isMatching, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isOk, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, toSnakeCaseKeys, toString, trim, trimEnd, trimStart, unary, unescape, unfold, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
12
|
+
import { a as Err, i as match, n as Pattern, o as Ok, r as isMatching, s as P, t as NonExhaustiveError } from "./index-DtnKhaAD.mjs";
|
|
13
|
+
export { AbortError, type DebounceOptions, type DebouncedFunction, type Err, type MemoizeCache, Mutex, NonExhaustiveError, type Ok, P, Pattern, type Result, Semaphore, type ThrottleOptions, type ThrottledFunction, TimeoutError, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, either, err, escape, escapeRegExp, evolve, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowAsync, flowRight, forEachAsync, forEachRight, groupBy, head, identity, ifElse, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isErr, isError, isFile, isFiniteNumber, isFunction, isInteger, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isMatching, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isOk, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, toSnakeCaseKeys, toString, todo, trim, trimEnd, trimStart, unary, unescape, unfold, unimplemented, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unreachable, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,6 @@ import { A as isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPr
|
|
|
7
7
|
import { a as toFinite, c as toString, i as toError, n as toArray, o as toInteger, r as toBoolean, s as toNumber, t as stringify } from "./conversion-ByBXBR5i.mjs";
|
|
8
8
|
import { Mutex, Semaphore, delay, timeout, withTimeout } from "./promise/index.mjs";
|
|
9
9
|
import { camelCase, capitalize, constantCase, deburr, escape, escapeRegExp, kebabCase, lowerCase, lowerFirst, pad, pascalCase, reverseString, snakeCase, startCase, trim, trimEnd, trimStart, unescape, upperCase, upperFirst, words } from "./string/index.mjs";
|
|
10
|
-
import { a as
|
|
11
|
-
import {
|
|
12
|
-
export { AbortError, Mutex, NonExhaustiveError, P, Pattern, Semaphore, TimeoutError, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, either, err, escape, escapeRegExp, evolve, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowAsync, flowRight, forEachAsync, forEachRight, groupBy, head, identity, ifElse, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isErr, isError, isFile, isFiniteNumber, isFunction, isInteger, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isMatching, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isOk, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, toSnakeCaseKeys, toString, trim, trimEnd, trimStart, unary, unescape, unfold, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
10
|
+
import { a as todo, c as err, d as ok, f as unwrap, i as unimplemented, l as isErr, n as invariant, o as attempt, r as unreachable, s as attemptAsync, t as assert, u as isOk } from "./control-Dg2fwHB7.mjs";
|
|
11
|
+
import { a as P, i as match, n as Pattern, r as isMatching, t as NonExhaustiveError } from "./match-CG_v2C4Q.mjs";
|
|
12
|
+
export { AbortError, Mutex, NonExhaustiveError, P, Pattern, Semaphore, TimeoutError, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, either, err, escape, escapeRegExp, evolve, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowAsync, flowRight, forEachAsync, forEachRight, groupBy, head, identity, ifElse, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isErr, isError, isFile, isFiniteNumber, isFunction, isInteger, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isMatching, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isOk, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, toSnakeCaseKeys, toString, todo, trim, trimEnd, trimStart, unary, unescape, unfold, unimplemented, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unreachable, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { NonExhaustiveError, P, Pattern, isMatching, match } from "ts-pattern";
|
|
2
|
+
//#region src/match/match.ts
|
|
3
|
+
/**
|
|
4
|
+
* Extends ts-pattern's `P` namespace with `P.ok` and `P.err` — structural
|
|
5
|
+
* patterns for matching a `Result` inside `match()`.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors Rust's `Ok(value)` / `Err(error)` match arms, but uses the
|
|
8
|
+
* namespace-property form (`P.ok` / `P.err`) so it doesn't collide with
|
|
9
|
+
* the lowercase `ok()` / `err()` constructors from `massaman/control`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { match, P, attempt } from 'massaman'
|
|
14
|
+
*
|
|
15
|
+
* match(attempt(() => JSON.parse(raw)))
|
|
16
|
+
* .with(P.ok, ({ value }) => use(value))
|
|
17
|
+
* .with(P.err, ({ error }) => log(error))
|
|
18
|
+
* .exhaustive()
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const okPattern = { ok: true };
|
|
22
|
+
const errPattern = { ok: false };
|
|
23
|
+
/**
|
|
24
|
+
* Extended ts-pattern `P` namespace. Carries everything ts-pattern exports
|
|
25
|
+
* (`P.string`, `P.number`, `P.array`, `P.when`, …) plus `P.ok` / `P.err`
|
|
26
|
+
* for matching `Result` values.
|
|
27
|
+
*
|
|
28
|
+
* Explicit literal-type annotations on the additions (rather than `as const`)
|
|
29
|
+
* keep the values non-`readonly`, which ts-pattern's narrowing requires —
|
|
30
|
+
* a `readonly` pattern collapses the remaining input to `never` after the
|
|
31
|
+
* first arm, breaking exhaustiveness.
|
|
32
|
+
*
|
|
33
|
+
* For the `P.Pattern<T>` type shorthand, import `Pattern` standalone from
|
|
34
|
+
* `massaman/match` — it's the form ts-pattern's own docs recommend.
|
|
35
|
+
*/
|
|
36
|
+
const P$1 = {
|
|
37
|
+
...P,
|
|
38
|
+
ok: okPattern,
|
|
39
|
+
err: errPattern
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { P$1 as a, match as i, Pattern as n, isMatching as r, NonExhaustiveError as t };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=match-CG_v2C4Q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-CG_v2C4Q.mjs","names":["P","TsP"],"sources":["../src/match/match.ts"],"sourcesContent":["/**\n * Extends ts-pattern's `P` namespace with `P.ok` and `P.err` — structural\n * patterns for matching a `Result` inside `match()`.\n *\n * Mirrors Rust's `Ok(value)` / `Err(error)` match arms, but uses the\n * namespace-property form (`P.ok` / `P.err`) so it doesn't collide with\n * the lowercase `ok()` / `err()` constructors from `massaman/control`.\n *\n * @example\n * ```ts\n * import { match, P, attempt } from 'massaman'\n *\n * match(attempt(() => JSON.parse(raw)))\n * .with(P.ok, ({ value }) => use(value))\n * .with(P.err, ({ error }) => log(error))\n * .exhaustive()\n * ```\n */\n\nimport { P as TsP } from 'ts-pattern'\n\nimport type { Err as ErrType, Ok as OkType } from '../control/types.js'\n\nconst okPattern: { ok: true } = { ok: true }\nconst errPattern: { ok: false } = { ok: false }\n\n/**\n * Extended ts-pattern `P` namespace. Carries everything ts-pattern exports\n * (`P.string`, `P.number`, `P.array`, `P.when`, …) plus `P.ok` / `P.err`\n * for matching `Result` values.\n *\n * Explicit literal-type annotations on the additions (rather than `as const`)\n * keep the values non-`readonly`, which ts-pattern's narrowing requires —\n * a `readonly` pattern collapses the remaining input to `never` after the\n * first arm, breaking exhaustiveness.\n *\n * For the `P.Pattern<T>` type shorthand, import `Pattern` standalone from\n * `massaman/match` — it's the form ts-pattern's own docs recommend.\n */\nexport const P: typeof TsP & { ok: { ok: true }; err: { ok: false } } = {\n ...TsP,\n ok: okPattern,\n err: errPattern,\n}\n\n/**\n * The `Ok` variant of a `Result<T>`. Re-exported here so the value-side\n * patterns and the type-side `Ok<T>` live in one module — any consumer\n * import gets both type and value namespaces without cross-module merge\n * issues (TS2300).\n */\nexport type Ok<T> = OkType<T>\n\n/**\n * The `Err` variant of a `Result<T>`. See {@link Ok} for the co-location note.\n */\nexport type Err = ErrType\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,YAA0B,EAAE,IAAI,MAAM;AAC5C,MAAM,aAA4B,EAAE,IAAI,OAAO;;;;;;;;;;;;;;AAe/C,MAAaA,MAA2D;CACtE,GAAGC;CACH,IAAI;CACJ,KAAK;CACN"}
|
package/dist/object/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as toSnakeCaseKeys, a as flattenObject, c as mapValues, d as omit, f as omitBy, g as toMerged, h as toCamelCaseKeys, i as findKey, l as merge, m as pickBy, n as cloneDeep, o as invert, p as pick, r as cloneDeepWith, s as mapKeys, t as clone, u as mergeWith, v as evolve } from "../index-
|
|
1
|
+
import { _ as toSnakeCaseKeys, a as flattenObject, c as mapValues, d as omit, f as omitBy, g as toMerged, h as toCamelCaseKeys, i as findKey, l as merge, m as pickBy, n as cloneDeep, o as invert, p as pick, r as cloneDeepWith, s as mapKeys, t as clone, u as mergeWith, v as evolve } from "../index-keGHab-v.mjs";
|
|
2
2
|
export { clone, cloneDeep, cloneDeepWith, evolve, findKey, flattenObject, invert, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, toCamelCaseKeys, toMerged, toSnakeCaseKeys };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPromise, F as isArray, G as either, H as allPass, I as isEmpty, L as isFiniteNumber, M as isUndefined, N as isWeakMap, O as isSet, P as isWeakSet, R as isInteger, S as isNull, T as isPrimitive, U as anyPass, V as isObject, W as both, _ as isLength, a as isBuffer, b as isNode, c as isEqual, d as isFile, f as isFunction, g as isJSONValue, h as isJSONObject, i as isBrowser, j as isTypedArray, k as isString, l as isEqualWith, m as isJSONArray, n as isBlob, o as isDate, p as isJSON, r as isBoolean, s as isEmptyObject, t as isArrayBuffer, u as isError, v as isMap, w as isPlainObject, x as isNotNil, y as isNil, z as isNaN } from "../index-
|
|
1
|
+
import { A as isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPromise, F as isArray, G as either, H as allPass, I as isEmpty, L as isFiniteNumber, M as isUndefined, N as isWeakMap, O as isSet, P as isWeakSet, R as isInteger, S as isNull, T as isPrimitive, U as anyPass, V as isObject, W as both, _ as isLength, a as isBuffer, b as isNode, c as isEqual, d as isFile, f as isFunction, g as isJSONValue, h as isJSONObject, i as isBrowser, j as isTypedArray, k as isString, l as isEqualWith, m as isJSONArray, n as isBlob, o as isDate, p as isJSON, r as isBoolean, s as isEmptyObject, t as isArrayBuffer, u as isError, v as isMap, w as isPlainObject, x as isNotNil, y as isNil, z as isNaN } from "../index-g2aw5tc_.mjs";
|
|
2
2
|
export { allPass, anyPass, both, either, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFiniteNumber, isFunction, isInteger, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/control/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Success result containing a value.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const result: Ok<number> = { ok: true, value: 42 }
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
interface Ok<T> {
|
|
11
|
+
readonly ok: true;
|
|
12
|
+
readonly value: T;
|
|
13
|
+
readonly error: null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Failure result containing an error.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const result: Err = { ok: false, error: new Error('fail') }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
interface Err {
|
|
24
|
+
readonly ok: false;
|
|
25
|
+
readonly value: null;
|
|
26
|
+
readonly error: Error;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Discriminated union representing either success (`Ok`) or failure (`Err`).
|
|
30
|
+
* Inspired by Rust's `Result<T, E>`, but errors are always `Error`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* function divide(a: number, b: number): Result<number> {
|
|
35
|
+
* return b === 0 ? err('division by zero') : ok(a / b)
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
type Result<T> = Ok<T> | Err;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { Ok as n, Result as r, Err as t };
|
|
42
|
+
//# sourceMappingURL=types-X6LqLWno.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-X6LqLWno.d.mts","names":[],"sources":["../src/control/types.ts"],"mappings":";;AAQA;;;;;;;UAAiB,EAAA;EAAA,SACN,EAAA;EAAA,SACA,KAAA,EAAO,CAAA;EAAA,SACP,KAAA;AAAA;;;;;;;;;UAWM,GAAA;EAAA,SACN,EAAA;EAAA,SACA,KAAA;EAAA,SACA,KAAA,EAAO,KAAA;AAAA;;;;;;;;;;;;KAcN,MAAA,MAAY,EAAA,CAAG,CAAA,IAAK,GAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "massaman",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A comprehensive functional programming library and utilities for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"es-toolkit",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"types": "./dist/control/index.d.mts",
|
|
60
60
|
"import": "./dist/control/index.mjs"
|
|
61
61
|
},
|
|
62
|
-
"./
|
|
63
|
-
"types": "./dist/
|
|
64
|
-
"import": "./dist/
|
|
62
|
+
"./match": {
|
|
63
|
+
"types": "./dist/match/index.d.mts",
|
|
64
|
+
"import": "./dist/match/index.mjs"
|
|
65
65
|
},
|
|
66
66
|
"./math": {
|
|
67
67
|
"types": "./dist/math/index.d.mts",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"control-B8mDJqXw.mjs","names":[],"sources":["../src/control/result.ts","../src/control/attempt.ts"],"sourcesContent":["import { isNil } from 'es-toolkit/predicate'\n\nimport type { Err, Ok, Result } from './types.js'\n\n/**\n * Minimal error coercion used internally by `err()`. Kept local to avoid\n * pulling the full conversion module into the `massaman/control` bundle.\n * For richer stringification (Maps, Sets, Errors with own props, circular\n * refs), import `toError` from `massaman/conversion`.\n */\nfunction coerceError(thrown: unknown): Error {\n if (thrown instanceof Error) {\n return thrown\n }\n if (typeof thrown === 'string') {\n return new Error(thrown)\n }\n try {\n const message = JSON.stringify(thrown) ?? String(thrown)\n return new Error(message, { cause: thrown })\n } catch {\n return new Error(String(thrown), { cause: thrown })\n }\n}\n\n/**\n * Creates a success result wrapping the given value.\n *\n * @param value - The success value\n * @returns An `Ok` result containing the value\n *\n * @example\n * ```ts\n * const result = ok(42)\n * // { ok: true, value: 42 }\n * ```\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value, error: null }\n}\n\n/**\n * Creates a failure result wrapping the given error.\n *\n * @param error - The error value\n * @returns An `Err` result containing the error\n *\n * @example\n * ```ts\n * const result = err(new Error('fail'))\n * // { ok: false, error: Error('fail') }\n * ```\n */\nexport function err(error: unknown): Err {\n return { ok: false, value: null, error: coerceError(error) }\n}\n\n/**\n * Type guard that narrows a `Result` to `Ok`.\n *\n * @param result - The result to check\n * @returns `true` if the result is `Ok`\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('{}'))\n * if (isOk(result)) {\n * console.log(result.value)\n * }\n * ```\n */\nexport function isOk<T>(result: Result<T>): result is Ok<T> {\n return result.ok === true\n}\n\n/**\n * Type guard that narrows a `Result` to `Err`.\n *\n * @param result - The result to check\n * @returns `true` if the result is `Err`\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('bad'))\n * if (isErr(result)) {\n * console.error(result.error)\n * }\n * ```\n */\nexport function isErr<T>(result: Result<T>): result is Err {\n return result.ok === false\n}\n\n/**\n * Extract the value from an `Ok` result, or throw on `Err`.\n *\n * When called without a message, throws the original error.\n * When called with a message, throws a new Error with that message\n * and the original error as `cause` (like Rust's `expect`).\n *\n * @param result - The result to unwrap\n * @param message - Optional custom error message (Rust `expect` behavior)\n * @returns The unwrapped value\n *\n * @example\n * ```ts\n * const value = unwrap(ok(42)) // 42\n * unwrap(err('fail')) // throws Error('fail')\n * unwrap(err('fail'), 'config required') // throws Error('config required', { cause: Error('fail') })\n * ```\n */\nexport function unwrap<T>(result: Result<T>, message?: string): T {\n if (result.ok) {\n return result.value\n }\n if (!isNil(message)) {\n throw new Error(message, { cause: result.error })\n }\n throw result.error\n}\n","import { err, ok } from './result.js'\nimport type { Result } from './types.js'\n\n/**\n * Executes a synchronous function and wraps the outcome in a `Result`.\n * Returns `Ok` with the return value on success, `Err` with the thrown value on failure.\n *\n * @param fn - The function to execute\n * @returns A `Result` containing either the value or the error\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('{\"a\":1}'))\n * if (isOk(result)) {\n * console.log(result.value) // { a: 1 }\n * }\n * ```\n */\nexport function attempt<T>(fn: () => T): Result<T> {\n try {\n return ok(fn())\n } catch (error) {\n return err(error)\n }\n}\n\n/**\n * Executes an asynchronous function and wraps the outcome in a `Result`.\n * Returns `Ok` with the resolved value on success, `Err` with the rejection reason on failure.\n *\n * @param fn - The async function to execute\n * @returns A promise resolving to a `Result` containing either the value or the error\n *\n * @example\n * ```ts\n * const result = await attemptAsync(() => fetch('/api/data'))\n * if (isErr(result)) {\n * console.error(result.error)\n * }\n * ```\n */\nexport async function attemptAsync<T>(fn: () => Promise<T>): Promise<Result<T>> {\n try {\n return ok(await fn())\n } catch (error) {\n return err(error)\n }\n}\n"],"mappings":";;;;;;;;;AAUA,SAAS,YAAY,QAAwB;CAC3C,IAAI,kBAAkB,OACpB,OAAO;CAET,IAAI,OAAO,WAAW,UACpB,OAAO,IAAI,MAAM,OAAO;CAE1B,IAAI;EACF,MAAM,UAAU,KAAK,UAAU,OAAO,IAAI,OAAO,OAAO;EACxD,OAAO,IAAI,MAAM,SAAS,EAAE,OAAO,QAAQ,CAAC;SACtC;EACN,OAAO,IAAI,MAAM,OAAO,OAAO,EAAE,EAAE,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;AAgBvD,SAAgB,GAAM,OAAiB;CACrC,OAAO;EAAE,IAAI;EAAM;EAAO,OAAO;EAAM;;;;;;;;;;;;;;AAezC,SAAgB,IAAI,OAAqB;CACvC,OAAO;EAAE,IAAI;EAAO,OAAO;EAAM,OAAO,YAAY,MAAM;EAAE;;;;;;;;;;;;;;;;AAiB9D,SAAgB,KAAQ,QAAoC;CAC1D,OAAO,OAAO,OAAO;;;;;;;;;;;;;;;;AAiBvB,SAAgB,MAAS,QAAkC;CACzD,OAAO,OAAO,OAAO;;;;;;;;;;;;;;;;;;;;AAqBvB,SAAgB,OAAU,QAAmB,SAAqB;CAChE,IAAI,OAAO,IACT,OAAO,OAAO;CAEhB,IAAI,CAAC,MAAM,QAAQ,EACjB,MAAM,IAAI,MAAM,SAAS,EAAE,OAAO,OAAO,OAAO,CAAC;CAEnD,MAAM,OAAO;;;;;;;;;;;;;;;;;;;ACpGf,SAAgB,QAAW,IAAwB;CACjD,IAAI;EACF,OAAO,GAAG,IAAI,CAAC;UACR,OAAO;EACd,OAAO,IAAI,MAAM;;;;;;;;;;;;;;;;;;AAmBrB,eAAsB,aAAgB,IAA0C;CAC9E,IAAI;EACF,OAAO,GAAG,MAAM,IAAI,CAAC;UACd,OAAO;EACd,OAAO,IAAI,MAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-Br9PO6mU.d.mts","names":[],"sources":["../src/control/types.ts","../src/control/attempt.ts","../src/control/result.ts"],"mappings":";;;;;;AAQA;;;;;UAAiB,EAAA;EAAA,SACN,EAAA;EAAA,SACA,KAAA,EAAO,CAAA;EAAA,SACP,KAAA;AAAA;;AAWX;;;;;;;UAAiB,GAAA;EAAA,SACN,EAAA;EAAA,SACA,KAAA;EAAA,SACA,KAAA,EAAO,KAAA;AAAA;;;;;;;;;;;;KAcN,MAAA,MAAY,EAAA,CAAG,CAAA,IAAK,GAAA;;;;;AA/BhC;;;;;;;;;;;AAcA;;iBCJgB,OAAA,GAAA,CAAW,EAAA,QAAU,CAAA,GAAI,MAAA,CAAO,CAAA;;;;;;;;ADqBhD;;;;;;;;iBCEsB,YAAA,GAAA,CAAgB,EAAA,QAAU,OAAA,CAAQ,CAAA,IAAK,OAAA,CAAQ,MAAA,CAAO,CAAA;;;;;ADjC5E;;;;;;;;;;iBE6BgB,EAAA,GAAA,CAAM,KAAA,EAAO,CAAA,GAAI,EAAA,CAAG,CAAA;AFfpC;;;;;;;;;;AAiBA;;AAjBA,iBE+BgB,GAAA,CAAI,KAAA,YAAiB,GAAA;;;;;;;;;;;;;;;iBAkBrB,IAAA,GAAA,CAAQ,MAAA,EAAQ,MAAA,CAAO,CAAA,IAAK,MAAA,IAAU,EAAA,CAAG,CAAA;;;;;;;;;;;;;;;iBAkBzC,KAAA,GAAA,CAAS,MAAA,EAAQ,MAAA,CAAO,CAAA,IAAK,MAAA,IAAU,GAAA;;;;;;;;;;;;;;;;;;;iBAsBvC,MAAA,GAAA,CAAU,MAAA,EAAQ,MAAA,CAAO,CAAA,GAAI,OAAA,YAAmB,CAAA"}
|
package/dist/pattern/index.d.mts
DELETED
package/dist/pattern/index.mjs
DELETED