massaman 0.0.1-rc.2 → 0.1.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 CHANGED
@@ -1,138 +1,121 @@
1
- # massaman
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/zrosenbauer/massaman/main/.github/assets/banner.png" alt="massaman" width="90%" />
3
+ <p><strong>Functional programming utilities for TypeScript. Result types, pattern matching, async pipelines. Fully typed.</strong></p>
2
4
 
3
- [![npm](https://img.shields.io/npm/v/massaman/rc?label=npm%40rc&color=B45309)](https://www.npmjs.com/package/massaman)
4
- [![types](https://img.shields.io/npm/types/massaman?color=3178c6)](https://www.typescriptlang.org/)
5
- [![license](https://img.shields.io/npm/l/massaman?color=475569)](./LICENSE)
6
- [![status](https://img.shields.io/badge/status-release%20candidate-B45309)](#status)
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>
6
+ <a href="https://www.npmjs.com/package/massaman"><img src="https://img.shields.io/npm/v/massaman" alt="npm version" /></a>
7
+ <a href="https://github.com/zrosenbauer/massaman/blob/main/LICENSE"><img src="https://img.shields.io/github/license/zrosenbauer/massaman" alt="License" /></a>
7
8
 
8
- Functional programming utilities for TypeScript — a curated unified surface over [es-toolkit](https://es-toolkit.slash.page) and [ts-pattern](https://github.com/gvergnaud/ts-pattern), with Result-style error handling, variadic-narrowing predicates, async-aware composition, and pattern matching.
9
+ </div>
9
10
 
10
- ## Status
11
+ ## Features
11
12
 
12
- Release candidate. The public API is frozen no breaking changes will land before `1.0.0`. Feedback welcome via [issues](https://github.com/zrosenbauer/massaman/issues).
13
+ - Functional-esque toolkit for writing close to pure FP in TypeScript.
14
+ - Built on two great libraries: [es-toolkit](https://es-toolkit.slash.page) and [ts-pattern](https://github.com/gvergnaud/ts-pattern).
15
+ - Result-style errors with `attempt`/`ok`/`err`. Never throw across a boundary.
16
+ - Variadic-narrowing predicates: `allPass([isString, isNotEmpty])` narrows to `string`.
17
+ - 100% test coverage, enforced by CI on every commit.
13
18
 
14
19
  ## Install
15
20
 
16
21
  ```bash
17
- npm install massaman@rc
18
- # or
19
- pnpm add massaman@rc
20
- # or
21
- yarn add massaman@rc
22
+ npm install massaman
22
23
  ```
23
24
 
24
- ## Quick start
25
+ ## Usage
25
26
 
26
- ```ts
27
- import { flow, attempt, isOk } from 'massaman'
27
+ ### From ts-pattern
28
28
 
29
- const parseUser = flow(JSON.parse, (u) => u.name.trim())
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
- const result = attempt(() => parseUser(rawInput))
32
- if (isOk(result)) {
33
- return result.value
34
- }
35
- return 'unknown'
36
- ```
31
+ ```ts
32
+ import { match, P } from 'massaman/pattern'
37
33
 
38
- ## Features
34
+ const status = match(action)
35
+ .with({ type: 'load' }, () => 'loading')
36
+ .with({ type: 'success' }, () => 'done')
37
+ .with({ type: 'error', msg: P.string }, ({ msg }) => `failed: ${msg}`)
38
+ .exhaustive()
39
+ ```
39
40
 
40
- | Feature | Description |
41
- | ---------------------------------- | -------------------------------------------------------------------------------------------------------- |
42
- | **Unified FP surface** | Array, object, string, function, math, predicate, promise — one curated import root, tree-shakeable. |
43
- | **Result-style error handling** | `attempt` / `attemptAsync` / `ok` / `err` / `isOk` / `isErr` / `unwrap` — no thrown exceptions. |
44
- | **Pattern matching** | Full [ts-pattern](https://github.com/gvergnaud/ts-pattern) re-export under `massaman/pattern`. |
45
- | **Variadic type-guard narrowing** | `allPass([isString, isNotEmpty])` returns a guard that narrows to `string` — composes any arity. |
46
- | **Async-aware pipelines** | `flowAsync` chains promise-returning functions with end-to-end type inference (up to 7 steps). |
47
- | **Safe error normalization** | `toError` + `stringify` handle non-`Error` throws, circular refs, Maps/Sets — no more `[object Object]`. |
48
- | **Branching combinators** | `when` / `unless` / `ifElse` for point-free conditionals inside `flow` pipelines. |
49
- | **100% test coverage** | Enforced by CI — every line, branch, and function is verified. |
50
- | **ESM-only, `sideEffects: false`** | 12 subpath exports, tree-shakeable, zero side effects. |
41
+ ### From es-toolkit
51
42
 
52
- ## Usage
43
+ Most of the surface (`array`, `object`, `string`, `function`, `math`) is a transparent re-export of [es-toolkit](https://es-toolkit.slash.page). Same names, same behavior, same docs.
53
44
 
54
45
  ```ts
55
- import { flow, compact, uniq, toArray } from 'massaman'
46
+ import { chunk, groupBy } from 'massaman'
56
47
 
57
- const normalize = flow(toArray, compact, uniq)
58
- normalize([1, null, 2, 1, null]) // [1, 2]
48
+ chunk([1, 2, 3, 4, 5], 2)
49
+ // [[1, 2], [3, 4], [5]]
50
+
51
+ groupBy(['apple', 'avocado', 'banana', 'blueberry'], (s) => s[0])
52
+ // { a: ['apple', 'avocado'], b: ['banana', 'blueberry'] }
59
53
  ```
60
54
 
61
- ```ts
62
- import { match, P } from 'massaman/pattern'
55
+ ### Custom: Result and async composition
63
56
 
64
- const label = match(status)
65
- .with('active', () => 'Live')
66
- .with('draft', () => 'Draft')
67
- .with(P._, () => 'N/A')
68
- .exhaustive()
69
- ```
57
+ Built on top of those re-exports, `massaman/control` adds Result-style error handling that never throws across a boundary.
70
58
 
71
59
  ```ts
72
- import { attempt, isOk } from 'massaman/control'
60
+ import { attemptAsync, isOk } from 'massaman/control'
61
+
62
+ const result = await attemptAsync(() => fetch('/api/user').then((r) => r.json()))
73
63
 
74
- const result = attempt(() => JSON.parse(raw))
75
64
  if (isOk(result)) {
76
65
  console.log(result.value)
77
66
  } else {
78
- console.error(result.error)
67
+ console.error(result.error.message)
68
+ }
69
+ ```
70
+
71
+ ## Why?
72
+
73
+ Two Rust patterns I keep wanting in TypeScript: `match` for exhaustive branching, and `Result` for errors that compose without throws.
74
+
75
+ In Rust:
76
+
77
+ ```rust
78
+ match action {
79
+ Action::Load => "loading",
80
+ Action::Success => "done",
81
+ Action::Error(msg) => &format!("failed: {}", msg),
82
+ }
83
+
84
+ let parsed: Result<User, Error> = serde_json::from_str(raw);
85
+ match parsed {
86
+ Ok(user) => println!("got: {}", user.name),
87
+ Err(err) => eprintln!("failed: {}", err),
79
88
  }
80
89
  ```
81
90
 
91
+ The equivalent in TypeScript using `massaman`:
92
+
82
93
  ```ts
83
- import { allPass } from 'massaman/predicate'
84
- import { isString } from 'es-toolkit/predicate'
85
- import { isNotEmpty } from 'massaman/predicate'
94
+ import { match, P } from 'massaman/pattern'
95
+ import { attempt, isOk } from 'massaman/control'
96
+
97
+ match(action)
98
+ .with({ type: 'load' }, () => 'loading')
99
+ .with({ type: 'success' }, () => 'done')
100
+ .with({ type: 'error', msg: P.string }, ({ msg }) => `failed: ${msg}`)
101
+ .exhaustive()
86
102
 
87
- const isNonEmptyString = allPass([isString, isNotEmpty])
88
- if (isNonEmptyString(x)) {
89
- // x is narrowed to string
103
+ const parsed = attempt(() => JSON.parse(raw) as User)
104
+ if (isOk(parsed)) {
105
+ console.log(`got: ${parsed.value.name}`)
106
+ } else {
107
+ console.error(`failed: ${parsed.error.message}`)
90
108
  }
91
109
  ```
92
110
 
93
- ## Modules
94
-
95
- | Subpath | Description |
96
- | --------------------- | -------------------------------------------------------------------------- |
97
- | `massaman` | Root barrel — re-exports everything below |
98
- | `massaman/array` | Array utilities (chunk, groupBy, sortWith, scan, unfold, …) |
99
- | `massaman/object` | Object utilities (evolve, pick, omit, merge, mapKeys, …) |
100
- | `massaman/function` | Composition (flow, flowAsync, tap, call, curry, when, unless, ifElse, …) |
101
- | `massaman/predicate` | Type guards, combinators with variadic narrowing |
102
- | `massaman/conversion` | Coercion + safe stringification (toError, stringify, toNumber, toArray, …) |
103
- | `massaman/string` | String transforms (camelCase, kebabCase, trim, …) |
104
- | `massaman/math` | Numeric utilities (clamp, sum, mean, range, …) |
105
- | `massaman/promise` | Async helpers (delay, timeout, Mutex, Semaphore) |
106
- | `massaman/control` | Result-style error handling (attempt, ok, err, isOk, isErr, unwrap, …) |
107
- | `massaman/pattern` | Pattern matching (match, P, isMatching) |
108
- | `massaman/error` | Error types (AbortError, TimeoutError) |
109
-
110
- ## Custom utilities
111
-
112
- Utilities not in es-toolkit or ts-pattern — implemented in this package:
113
-
114
- | Module | Utility | Description |
115
- | ------------ | ------------------------------------------------ | -------------------------------------------------------------- |
116
- | `array` | `adjust`, `scan`, `unfold`, `dropRepeats` | Index update, accumulator scan, seed unfold, consecutive dedup |
117
- | `array` | `reduceWhile`, `ascend`, `descend`, `sortWith` | Short-circuit reduce, comparator factories, multi-key sort |
118
- | `function` | `flowAsync`, `tap` | Async composition, side-effect-in-pipeline |
119
- | `function` | `when`, `unless`, `ifElse`, `call`, `callAsync` | Point-free conditionals, named application |
120
- | `object` | `evolve` | Apply transforms per key |
121
- | `predicate` | `allPass`, `anyPass`, `both`, `either` | Variadic-narrowing predicate combinators |
122
- | `predicate` | `isArray`, `isObject`, `isEmpty`, `isNotEmpty` | Type guards + emptiness |
123
- | `predicate` | `isFiniteNumber`, `isInteger`, `isNaN` | Strict numeric guards (shadowing the broken global `isNaN`) |
124
- | `control` | `attempt`, `attemptAsync` | Wrap throwing/rejecting code into a `Result` |
125
- | `control` | `ok`, `err`, `isOk`, `isErr`, `unwrap` | Construct, narrow, and unwrap a `Result` |
126
- | `conversion` | `toError`, `stringify` | Normalize unknown thrown values + safe JSON of any value |
127
- | `conversion` | `toNumber`, `toString`, `toBoolean`, `toInteger` | Stable coercion primitives |
128
- | `conversion` | `toFinite`, `toArray` | Safe coercion with fallback semantics |
129
-
130
- ## Requirements
131
-
132
- - Node.js >= 24.0.0
133
- - ESM only (`require()` / CommonJS is not supported)
134
- - TypeScript >= 5.9 recommended (variadic narrowing benefits from recent inference)
111
+ `massaman` brings both patterns to TypeScript, layered over [es-toolkit](https://es-toolkit.slash.page) 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
+
113
+ More on the philosophy at [zrosenbauer.com/blog](https://zrosenbauer.com/blog).
114
+
115
+ ## Contributing
116
+
117
+ See [CONTRIBUTING.md](https://github.com/zrosenbauer/massaman/blob/main/CONTRIBUTING.md) for development setup, conventions, and PR process.
135
118
 
136
119
  ## License
137
120
 
138
- MIT © Zac Rosenbauer
121
+ [MIT](LICENSE)
@@ -1 +1 @@
1
- {"version":3,"file":"array-C8MqjyiP.mjs","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"],"sourcesContent":["/**\n * Applies a function to the element at the given index, returning a new array.\n *\n * The original array is not modified. If the index is out of bounds, the\n * array is returned unchanged.\n *\n * @example\n * ```ts\n * adjust([1, 2, 3], 1, (n) => n * 10)\n * // [1, 20, 3]\n * ```\n */\nexport function adjust<T>(array: readonly T[], index: number, fn: (value: T) => T): T[] {\n const result = [...array]\n if (index >= 0 && index < array.length) {\n // oxlint-disable-next-line security/detect-object-injection -- Numeric array index parameter, not user-controlled key\n result[index] = fn(result[index])\n }\n return result\n}\n","/**\n * Removes consecutively repeated elements from an array using strict\n * equality (`===`).\n *\n * Only adjacent duplicates are removed — non-adjacent duplicates are kept.\n * Use {@link uniq} from es-toolkit to remove all duplicates regardless of position.\n *\n * Quirks (inherent to `===`):\n * - `NaN !== NaN`, so adjacent `NaN`s are *not* collapsed.\n * - `-0 === 0`, so adjacent `-0` and `0` *are* collapsed.\n * - Object/array elements compare by reference, not structure.\n *\n * @example\n * ```ts\n * dropRepeats([1, 1, 2, 3, 3, 2, 1])\n * // [1, 2, 3, 2, 1]\n * ```\n */\nexport function dropRepeats<T>(array: readonly T[]): T[] {\n return array.reduce<T[]>((acc, item, index) => {\n if (index === 0 || item !== array[index - 1]) {\n acc.push(item)\n }\n return acc\n }, [])\n}\n","/* oxlint-disable functional/no-let -- iterative impl avoids stack overflow on large arrays */\n\n/**\n * Like `reduce` but stops early when the predicate returns `false`.\n *\n * The predicate receives the current accumulator and element. When it\n * returns `false`, the current accumulator is returned without processing\n * the remaining elements.\n *\n * @example\n * ```ts\n * // Sum until we hit a negative number\n * reduceWhile(\n * [1, 2, 3, -1, 5],\n * (acc, n) => n >= 0,\n * (acc, n) => acc + n,\n * 0,\n * )\n * // 6\n * ```\n */\nexport function reduceWhile<T, R>(\n array: readonly T[],\n predicate: (accumulator: R, value: T) => boolean,\n fn: (accumulator: R, value: T, index: number) => R,\n initial: R\n): R {\n let acc = initial\n for (let index = 0; index < array.length; index += 1) {\n // oxlint-disable-next-line security/detect-object-injection -- Locally computed numeric array index\n const value = array[index]\n if (!predicate(acc, value)) {\n return acc\n }\n acc = fn(acc, value, index)\n }\n return acc\n}\n","/**\n * Like `reduce` but returns an array of all intermediate accumulator values.\n *\n * The result array starts with the initial value and ends with the final\n * accumulator, so its length is `array.length + 1`.\n *\n * @example\n * ```ts\n * scan([1, 2, 3, 4], (acc, n) => acc + n, 0)\n * // [0, 1, 3, 6, 10]\n * ```\n */\nexport function scan<T, R>(\n array: readonly T[],\n fn: (accumulator: R, value: T, index: number) => R,\n initial: R\n): R[] {\n return array.reduce<R[]>(\n (result, item, index) => {\n const prev = result[result.length - 1]\n result.push(fn(prev, item, index))\n return result\n },\n [initial]\n )\n}\n","/**\n * Creates an ascending comparator from an accessor function.\n *\n * @example\n * ```ts\n * users.sort(ascend(u => u.name))\n * ```\n */\nexport function ascend<T>(fn: (value: T) => number | string): (a: T, b: T) => number {\n return (a: T, b: T) => {\n const aa = fn(a)\n const bb = fn(b)\n if (aa < bb) {\n return -1\n }\n if (aa > bb) {\n return 1\n }\n return 0\n }\n}\n\n/**\n * Creates a descending comparator from an accessor function.\n *\n * @example\n * ```ts\n * users.sort(descend(u => u.age))\n * ```\n */\nexport function descend<T>(fn: (value: T) => number | string): (a: T, b: T) => number {\n return (a: T, b: T) => {\n const aa = fn(a)\n const bb = fn(b)\n if (aa > bb) {\n return -1\n }\n if (aa < bb) {\n return 1\n }\n return 0\n }\n}\n\n/**\n * Sorts an array using multiple comparators in priority order.\n *\n * The first comparator has highest priority. When it returns 0 (tie),\n * the next comparator is used, and so on.\n *\n * @example\n * ```ts\n * sortWith(users, [\n * ascend(u => u.department),\n * descend(u => u.age),\n * ])\n * ```\n */\nexport function sortWith<T>(\n array: readonly T[],\n comparators: ReadonlyArray<(a: T, b: T) => number>\n): T[] {\n return [...array].toSorted((a, b) => {\n for (const cmp of comparators) {\n const result = cmp(a, b)\n if (result !== 0) {\n return result\n }\n }\n return 0\n })\n}\n","/* oxlint-disable functional/no-let -- iterative impl avoids stack overflow on large outputs */\n\n/**\n * Builds an array from a seed value using an iterator function.\n *\n * The iterator receives the current seed and returns either a `[value, nextSeed]`\n * tuple to continue, or `false` to stop.\n *\n * Dual of `reduce` — reduce collapses a list into a value, unfold expands\n * a value into a list.\n *\n * **Termination is the caller's responsibility.** If `fn` never returns\n * `false`, `unfold` will run until memory is exhausted. For bounded\n * generation, encode a counter or limit into the seed.\n *\n * @example\n * ```ts\n * unfold((n) => (n > 0 ? [n, n - 1] : false), 5)\n * // [5, 4, 3, 2, 1]\n * ```\n */\nexport function unfold<T, R>(fn: (seed: T) => [R, T] | false, seed: T): R[] {\n const result: R[] = []\n let current = seed\n let pair = fn(current)\n while (pair !== false) {\n result.push(pair[0])\n current = pair[1]\n pair = fn(current)\n }\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAgB,OAAU,OAAqB,OAAe,IAA0B;CACtF,MAAM,SAAS,CAAC,GAAG,MAAM;CACzB,IAAI,SAAS,KAAK,QAAQ,MAAM,QAE9B,OAAO,SAAS,GAAG,OAAO,OAAO;CAEnC,OAAO;;;;;;;;;;;;;;;;;;;;;;ACAT,SAAgB,YAAe,OAA0B;CACvD,OAAO,MAAM,QAAa,KAAK,MAAM,UAAU;EAC7C,IAAI,UAAU,KAAK,SAAS,MAAM,QAAQ,IACxC,IAAI,KAAK,KAAK;EAEhB,OAAO;IACN,EAAE,CAAC;;;;;;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ACrB,OAAO,KAAK,KAAK,GAAG;EACpB,UAAU,KAAK;EACf,OAAO,GAAG,QAAQ;;CAEpB,OAAO"}
1
+ {"version":3,"file":"array-C8MqjyiP.mjs","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"],"sourcesContent":["/**\n * Applies a function to the element at the given index, returning a new array.\n *\n * The original array is not modified. If the index is out of bounds, the\n * array is returned unchanged.\n *\n * @example\n * ```ts\n * adjust([1, 2, 3], 1, (n) => n * 10)\n * // [1, 20, 3]\n * ```\n */\nexport function adjust<T>(array: readonly T[], index: number, fn: (value: T) => T): T[] {\n const result = [...array]\n if (index >= 0 && index < array.length) {\n // oxlint-disable-next-line security/detect-object-injection -- Numeric array index parameter, not user-controlled key\n result[index] = fn(result[index])\n }\n return result\n}\n","/**\n * Removes consecutively repeated elements from an array using strict\n * equality (`===`).\n *\n * Only adjacent duplicates are removed — non-adjacent duplicates are kept.\n * Use {@link uniq} from es-toolkit to remove all duplicates regardless of position.\n *\n * Quirks (inherent to `===`):\n * - `NaN !== NaN`, so adjacent `NaN`s are *not* collapsed.\n * - `-0 === 0`, so adjacent `-0` and `0` *are* collapsed.\n * - Object/array elements compare by reference, not structure.\n *\n * @example\n * ```ts\n * dropRepeats([1, 1, 2, 3, 3, 2, 1])\n * // [1, 2, 3, 2, 1]\n * ```\n */\nexport function dropRepeats<T>(array: readonly T[]): T[] {\n return array.reduce<T[]>((acc, item, index) => {\n if (index === 0 || item !== array[index - 1]) {\n acc.push(item)\n }\n return acc\n }, [])\n}\n","/**\n * Like `reduce` but stops early when the predicate returns `false`.\n *\n * The predicate receives the current accumulator and element. When it\n * returns `false`, the current accumulator is returned without processing\n * the remaining elements.\n *\n * @example\n * ```ts\n * // Sum until we hit a negative number\n * reduceWhile(\n * [1, 2, 3, -1, 5],\n * (acc, n) => n >= 0,\n * (acc, n) => acc + n,\n * 0,\n * )\n * // 6\n * ```\n */\nexport function reduceWhile<T, R>(\n array: readonly T[],\n predicate: (accumulator: R, value: T) => boolean,\n fn: (accumulator: R, value: T, index: number) => R,\n initial: R\n): R {\n // oxlint-disable-next-line functional/no-let -- iterative impl avoids stack overflow on large arrays\n let acc = initial\n // oxlint-disable-next-line functional/no-let -- iterative impl avoids stack overflow on large arrays\n for (let index = 0; index < array.length; index += 1) {\n // oxlint-disable-next-line security/detect-object-injection -- Locally computed numeric array index\n const value = array[index]\n if (!predicate(acc, value)) {\n return acc\n }\n acc = fn(acc, value, index)\n }\n return acc\n}\n","/**\n * Like `reduce` but returns an array of all intermediate accumulator values.\n *\n * The result array starts with the initial value and ends with the final\n * accumulator, so its length is `array.length + 1`.\n *\n * @example\n * ```ts\n * scan([1, 2, 3, 4], (acc, n) => acc + n, 0)\n * // [0, 1, 3, 6, 10]\n * ```\n */\nexport function scan<T, R>(\n array: readonly T[],\n fn: (accumulator: R, value: T, index: number) => R,\n initial: R\n): R[] {\n return array.reduce<R[]>(\n (result, item, index) => {\n const prev = result[result.length - 1]\n result.push(fn(prev, item, index))\n return result\n },\n [initial]\n )\n}\n","/**\n * Creates an ascending comparator from an accessor function.\n *\n * @example\n * ```ts\n * users.sort(ascend(u => u.name))\n * ```\n */\nexport function ascend<T>(fn: (value: T) => number | string): (a: T, b: T) => number {\n return (a: T, b: T) => {\n const aa = fn(a)\n const bb = fn(b)\n if (aa < bb) {\n return -1\n }\n if (aa > bb) {\n return 1\n }\n return 0\n }\n}\n\n/**\n * Creates a descending comparator from an accessor function.\n *\n * @example\n * ```ts\n * users.sort(descend(u => u.age))\n * ```\n */\nexport function descend<T>(fn: (value: T) => number | string): (a: T, b: T) => number {\n return (a: T, b: T) => {\n const aa = fn(a)\n const bb = fn(b)\n if (aa > bb) {\n return -1\n }\n if (aa < bb) {\n return 1\n }\n return 0\n }\n}\n\n/**\n * Sorts an array using multiple comparators in priority order.\n *\n * The first comparator has highest priority. When it returns 0 (tie),\n * the next comparator is used, and so on.\n *\n * @example\n * ```ts\n * sortWith(users, [\n * ascend(u => u.department),\n * descend(u => u.age),\n * ])\n * ```\n */\nexport function sortWith<T>(\n array: readonly T[],\n comparators: ReadonlyArray<(a: T, b: T) => number>\n): T[] {\n return [...array].toSorted((a, b) => {\n for (const cmp of comparators) {\n const result = cmp(a, b)\n if (result !== 0) {\n return result\n }\n }\n return 0\n })\n}\n","/**\n * Builds an array from a seed value using an iterator function.\n *\n * The iterator receives the current seed and returns either a `[value, nextSeed]`\n * tuple to continue, or `false` to stop.\n *\n * Dual of `reduce` — reduce collapses a list into a value, unfold expands\n * a value into a list.\n *\n * **Termination is the caller's responsibility.** If `fn` never returns\n * `false`, `unfold` will run until memory is exhausted. For bounded\n * generation, encode a counter or limit into the seed.\n *\n * @example\n * ```ts\n * unfold((n) => (n > 0 ? [n, n - 1] : false), 5)\n * // [5, 4, 3, 2, 1]\n * ```\n */\nexport function unfold<T, R>(fn: (seed: T) => [R, T] | false, seed: T): R[] {\n const result: R[] = []\n // oxlint-disable-next-line functional/no-let -- iterative impl avoids stack overflow on large outputs\n let current = seed\n // oxlint-disable-next-line functional/no-let -- iterative impl avoids stack overflow on large outputs\n let pair = fn(current)\n while (pair !== false) {\n result.push(pair[0])\n current = pair[1]\n pair = fn(current)\n }\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAgB,OAAU,OAAqB,OAAe,IAA0B;CACtF,MAAM,SAAS,CAAC,GAAG,MAAM;CACzB,IAAI,SAAS,KAAK,QAAQ,MAAM,QAE9B,OAAO,SAAS,GAAG,OAAO,OAAO;CAEnC,OAAO;;;;;;;;;;;;;;;;;;;;;;ACAT,SAAgB,YAAe,OAA0B;CACvD,OAAO,MAAM,QAAa,KAAK,MAAM,UAAU;EAC7C,IAAI,UAAU,KAAK,SAAS,MAAM,QAAQ,IACxC,IAAI,KAAK,KAAK;EAEhB,OAAO;IACN,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;ACLR,SAAgB,YACd,OAC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AAU,KAAK;EACf,OAAO,GAAG,QAAQ;;CAEpB,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"conversion-ByBXBR5i.mjs","names":[],"sources":["../src/conversion/convert.ts"],"sourcesContent":["import { isError, isMap, isNil, isPrimitive, isSet, isString } from 'es-toolkit/predicate'\n\n/**\n * Coerces an unknown thrown value into a proper `Error` instance.\n *\n * Handles the common cases where libraries throw non-`Error` values\n * (e.g. plain API response bodies, arrays, Maps) that would otherwise\n * serialize as `[object Object]` in error messages.\n *\n * @param thrown - The caught value from a `catch` block.\n * @returns An `Error` with a meaningful `.message`. If `thrown` is\n * already an `Error`, it is returned as-is. The original value is\n * preserved as `.cause` for debugging.\n *\n * @example\n * ```ts\n * try {\n * await riskyCall()\n * } catch (thrown) {\n * const error = toError(thrown)\n * console.error(error.message)\n * }\n * ```\n */\nexport function toError(thrown: unknown): Error {\n if (isError(thrown)) {\n return thrown\n }\n if (isString(thrown)) {\n return new Error(thrown)\n }\n return new Error(stringify(thrown), { cause: thrown })\n}\n\n/**\n * Produces a human-readable string from any unknown value.\n *\n * Uses `JSON.stringify` for structured types (plain objects, arrays)\n * so the message contains actual content instead of `[object Object]`.\n * Maps and Sets are converted to their array representation first.\n * Falls back to `String()` for primitives or when serialization fails\n * (e.g. circular references).\n *\n * @param value - The value to stringify.\n * @returns A meaningful string representation.\n *\n * @example\n * ```ts\n * stringify({ status: 400 }) // '{\"status\":400}'\n * stringify(new Map([['k', 'v']])) // '[[\"k\",\"v\"]]'\n * stringify(null) // 'null'\n * stringify(42) // '42'\n * ```\n */\nexport function stringify(value: unknown): string {\n if (isNil(value) || isPrimitive(value)) {\n return String(value)\n }\n try {\n return JSON.stringify(toSerializable(value))\n } catch {\n return String(value)\n }\n}\n\n// ---------------------------------------------------------------------------\n// private helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Convert types that `JSON.stringify` handles poorly into\n * serializable equivalents, recursively walking objects and arrays.\n *\n * - `Map` -> array of `[key, value]` entries (recursed)\n * - `Set` -> array of values (recursed)\n * - `Error` -> plain object with `name`, `message`, `stack`, and enumerable props\n * - Arrays and plain objects are recursed\n * - Uses a `WeakSet` to detect and break circular references\n */\nfunction toSerializable(value: unknown, seen: WeakSet<object> = new WeakSet()): unknown {\n if (isNil(value) || isPrimitive(value)) {\n return value\n }\n\n const obj = value as object\n if (seen.has(obj)) {\n return '[Circular]'\n }\n seen.add(obj)\n\n if (isError(value)) {\n const errorObj: Record<string, unknown> = {\n name: value.name,\n message: value.message,\n stack: value.stack,\n }\n for (const key of Object.keys(value)) {\n // oxlint-disable-next-line security/detect-object-injection -- safe: key from Object.keys\n errorObj[key] = toSerializable((value as unknown as Record<string, unknown>)[key], seen)\n }\n return errorObj\n }\n\n if (isMap(value)) {\n return Array.from(value.entries()).map(([k, v]) => [\n toSerializable(k, seen),\n toSerializable(v, seen),\n ])\n }\n\n if (isSet(value)) {\n return Array.from(value).map((v) => toSerializable(v, seen))\n }\n\n if (Array.isArray(value)) {\n return value.map((v) => toSerializable(v, seen))\n }\n\n const result: Record<string, unknown> = {}\n for (const key of Object.keys(value as Record<string, unknown>)) {\n // oxlint-disable-next-line security/detect-object-injection -- safe: key from Object.keys\n result[key] = toSerializable((value as Record<string, unknown>)[key], seen)\n }\n return result\n}\n\n/**\n * Converts a value to a number.\n *\n * Thin wrapper over `Number(value)` — kept as a stable surface so callers\n * don't depend directly on the global constructor's semantics (which have\n * shifted in the past, e.g. `Number(BigInt)`, and may again).\n *\n * @example\n * ```ts\n * toNumber('42') // 42\n * toNumber(null) // 0\n * ```\n */\nexport function toNumber(value: unknown): number {\n return Number(value)\n}\n\n/**\n * Converts a value to a string.\n *\n * Thin wrapper over `String(value)` — kept as a stable surface against\n * future global-constructor changes.\n *\n * @example\n * ```ts\n * toString(42) // '42'\n * toString(null) // 'null'\n * ```\n */\nexport function toString(value: unknown): string {\n return String(value)\n}\n\n/**\n * Converts a value to an integer by calling {@link toNumber} and truncating.\n *\n * @example\n * ```ts\n * toInteger('4.9') // 4\n * toInteger(null) // 0\n * ```\n */\nexport function toInteger(value: unknown): number {\n return Math.trunc(toNumber(value))\n}\n\n/**\n * Converts a value to a finite number.\n *\n * Returns `0` for non-finite results (`NaN`, `Infinity`, `-Infinity`).\n *\n * @example\n * ```ts\n * toFinite('3.14') // 3.14\n * toFinite(Infinity) // 0\n * ```\n */\nexport function toFinite(value: unknown): number {\n const n = Number(value)\n if (Number.isFinite(n)) {\n return n\n }\n return 0\n}\n\n/**\n * Converts a value to an array.\n *\n * - Arrays are returned as-is.\n * - Iterables (strings, Sets, Maps) are spread into an array.\n * - `null` / `undefined` return `[]`.\n * - All other values are wrapped in a single-element array.\n *\n * @example\n * ```ts\n * toArray(new Set([1, 2])) // [1, 2]\n * toArray('abc') // ['a', 'b', 'c']\n * toArray(null) // []\n * toArray(42) // [42]\n * ```\n */\nexport function toArray<T>(value: Iterable<T> | T | null | undefined): T[] {\n if (value == null) {\n return []\n }\n if (Array.isArray(value)) {\n return value as T[]\n }\n if (typeof (value as unknown as Record<symbol, unknown>)[Symbol.iterator] === 'function') {\n return Array.from(value as Iterable<T>)\n }\n return [value as T]\n}\n\n/**\n * Converts a value to a boolean.\n *\n * Thin wrapper over `Boolean(value)` — kept as a stable surface against\n * future global-constructor changes.\n *\n * @example\n * ```ts\n * toBoolean(1) // true\n * toBoolean(0) // false\n * toBoolean('') // false\n * ```\n */\nexport function toBoolean(value: unknown): boolean {\n return Boolean(value)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,QAAQ,QAAwB;CAC9C,IAAI,QAAQ,OAAO,EACjB,OAAO;CAET,IAAI,SAAS,OAAO,EAClB,OAAO,IAAI,MAAM,OAAO;CAE1B,OAAO,IAAI,MAAM,UAAU,OAAO,EAAE,EAAE,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;AAuBxD,SAAgB,UAAU,OAAwB;CAChD,IAAI,MAAM,MAAM,IAAI,YAAY,MAAM,EACpC,OAAO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AAwB;CAC/C,MAAM,IAAI,OAAO,MAAM;CACvB,IAAI,OAAO,SAAS,EAAE,EACpB,OAAO;CAET,OAAO;;;;;;;;;;;;;;;;;;AAmBT,SAAgB,QAAW,OAAgD;CACzE,IAAI,SAAS,MACX,OAAO,EAAE;CAEX,IAAI,MAAM,QAAQ,MAAM,EACtB,OAAO;CAET,IAAI,OAAQ,MAA6C,OAAO,cAAc,YAC5E,OAAO,MAAM,KAAK,MAAqB;CAEzC,OAAO,CAAC,MAAW;;;;;;;;;;;;;;;AAgBrB,SAAgB,UAAU,OAAyB;CACjD,OAAO,QAAQ,MAAM"}
1
+ {"version":3,"file":"conversion-ByBXBR5i.mjs","names":[],"sources":["../src/conversion/convert.ts"],"sourcesContent":["import { isError, isMap, isNil, isPrimitive, isSet, isString } from 'es-toolkit/predicate'\n\n/**\n * Coerces an unknown thrown value into a proper `Error` instance.\n *\n * Handles the common cases where libraries throw non-`Error` values\n * (e.g. plain API response bodies, arrays, Maps) that would otherwise\n * serialize as `[object Object]` in error messages.\n *\n * @param thrown - The caught value from a `catch` block.\n * @returns An `Error` with a meaningful `.message`. If `thrown` is\n * already an `Error`, it is returned as-is. The original value is\n * preserved as `.cause` for debugging.\n *\n * @example\n * ```ts\n * try {\n * await riskyCall()\n * } catch (thrown) {\n * const error = toError(thrown)\n * console.error(error.message)\n * }\n * ```\n */\nexport function toError(thrown: unknown): Error {\n if (isError(thrown)) {\n return thrown\n }\n if (isString(thrown)) {\n return new Error(thrown)\n }\n return new Error(stringify(thrown), { cause: thrown })\n}\n\n/**\n * Produces a human-readable string from any unknown value.\n *\n * Uses `JSON.stringify` for structured types (plain objects, arrays)\n * so the message contains actual content instead of `[object Object]`.\n * Maps and Sets are converted to their array representation first.\n * Falls back to `String()` for primitives or when serialization fails\n * (e.g. circular references).\n *\n * @param value - The value to stringify.\n * @returns A meaningful string representation.\n *\n * @example\n * ```ts\n * stringify({ status: 400 }) // '{\"status\":400}'\n * stringify(new Map([['k', 'v']])) // '[[\"k\",\"v\"]]'\n * stringify(null) // 'null'\n * stringify(42) // '42'\n * ```\n */\nexport function stringify(value: unknown): string {\n if (isNil(value) || isPrimitive(value)) {\n return String(value)\n }\n try {\n return JSON.stringify(toSerializable(value))\n } catch {\n return String(value)\n }\n}\n\n/**\n * Convert types that `JSON.stringify` handles poorly into\n * serializable equivalents, recursively walking objects and arrays.\n *\n * - `Map` -> array of `[key, value]` entries (recursed)\n * - `Set` -> array of values (recursed)\n * - `Error` -> plain object with `name`, `message`, `stack`, and enumerable props\n * - Arrays and plain objects are recursed\n * - Uses a `WeakSet` to detect and break circular references\n */\nfunction toSerializable(value: unknown, seen: WeakSet<object> = new WeakSet()): unknown {\n if (isNil(value) || isPrimitive(value)) {\n return value\n }\n\n const obj = value as object\n if (seen.has(obj)) {\n return '[Circular]'\n }\n seen.add(obj)\n\n if (isError(value)) {\n const errorObj: Record<string, unknown> = {\n name: value.name,\n message: value.message,\n stack: value.stack,\n }\n for (const key of Object.keys(value)) {\n // oxlint-disable-next-line security/detect-object-injection -- safe: key from Object.keys\n errorObj[key] = toSerializable((value as unknown as Record<string, unknown>)[key], seen)\n }\n return errorObj\n }\n\n if (isMap(value)) {\n return Array.from(value.entries()).map(([k, v]) => [\n toSerializable(k, seen),\n toSerializable(v, seen),\n ])\n }\n\n if (isSet(value)) {\n return Array.from(value).map((v) => toSerializable(v, seen))\n }\n\n if (Array.isArray(value)) {\n return value.map((v) => toSerializable(v, seen))\n }\n\n const result: Record<string, unknown> = {}\n for (const key of Object.keys(value as Record<string, unknown>)) {\n // oxlint-disable-next-line security/detect-object-injection -- safe: key from Object.keys\n result[key] = toSerializable((value as Record<string, unknown>)[key], seen)\n }\n return result\n}\n\n/**\n * Converts a value to a number.\n *\n * Thin wrapper over `Number(value)` — kept as a stable surface so callers\n * don't depend directly on the global constructor's semantics (which have\n * shifted in the past, e.g. `Number(BigInt)`, and may again).\n *\n * @example\n * ```ts\n * toNumber('42') // 42\n * toNumber(null) // 0\n * ```\n */\nexport function toNumber(value: unknown): number {\n return Number(value)\n}\n\n/**\n * Converts a value to a string.\n *\n * Thin wrapper over `String(value)` — kept as a stable surface against\n * future global-constructor changes.\n *\n * @example\n * ```ts\n * toString(42) // '42'\n * toString(null) // 'null'\n * ```\n */\nexport function toString(value: unknown): string {\n return String(value)\n}\n\n/**\n * Converts a value to an integer by calling {@link toNumber} and truncating.\n *\n * @example\n * ```ts\n * toInteger('4.9') // 4\n * toInteger(null) // 0\n * ```\n */\nexport function toInteger(value: unknown): number {\n return Math.trunc(toNumber(value))\n}\n\n/**\n * Converts a value to a finite number.\n *\n * Returns `0` for non-finite results (`NaN`, `Infinity`, `-Infinity`).\n *\n * @example\n * ```ts\n * toFinite('3.14') // 3.14\n * toFinite(Infinity) // 0\n * ```\n */\nexport function toFinite(value: unknown): number {\n const n = Number(value)\n if (Number.isFinite(n)) {\n return n\n }\n return 0\n}\n\n/**\n * Converts a value to an array.\n *\n * - Arrays are returned as-is.\n * - Iterables (strings, Sets, Maps) are spread into an array.\n * - `null` / `undefined` return `[]`.\n * - All other values are wrapped in a single-element array.\n *\n * @example\n * ```ts\n * toArray(new Set([1, 2])) // [1, 2]\n * toArray('abc') // ['a', 'b', 'c']\n * toArray(null) // []\n * toArray(42) // [42]\n * ```\n */\nexport function toArray<T>(value: Iterable<T> | T | null | undefined): T[] {\n if (value == null) {\n return []\n }\n if (Array.isArray(value)) {\n return value as T[]\n }\n if (typeof (value as unknown as Record<symbol, unknown>)[Symbol.iterator] === 'function') {\n return Array.from(value as Iterable<T>)\n }\n return [value as T]\n}\n\n/**\n * Converts a value to a boolean.\n *\n * Thin wrapper over `Boolean(value)` — kept as a stable surface against\n * future global-constructor changes.\n *\n * @example\n * ```ts\n * toBoolean(1) // true\n * toBoolean(0) // false\n * toBoolean('') // false\n * ```\n */\nexport function toBoolean(value: unknown): boolean {\n return Boolean(value)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,QAAQ,QAAwB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AE7E,OAAO;;;;;;;;;;;;;;;AAgBT,SAAgB,SAAS,OAAwB;CAC/C,OAAO,OAAO,MAAM;;;;;;;;;;;;;;AAetB,SAAgB,SAAS,OAAwB;CAC/C,OAAO,OAAO,MAAM;;;;;;;;;;;AAYtB,SAAgB,UAAU,OAAwB;CAChD,OAAO,KAAK,MAAM,SAAS,MAAM,CAAC;;;;;;;;;;;;;AAcpC,SAAgB,SAAS,OAAwB;CAC/C,MAAM,IAAI,OAAO,MAAM;CACvB,IAAI,OAAO,SAAS,EAAE,EACpB,OAAO;CAET,OAAO;;;;;;;;;;;;;;;;;;AAmBT,SAAgB,QAAW,OAAgD;CACzE,IAAI,SAAS,MACX,OAAO,EAAE;CAEX,IAAI,MAAM,QAAQ,MAAM,EACtB,OAAO;CAET,IAAI,OAAQ,MAA6C,OAAO,cAAc,YAC5E,OAAO,MAAM,KAAK,MAAqB;CAEzC,OAAO,CAAC,MAAW;;;;;;;;;;;;;;;AAgBrB,SAAgB,UAAU,OAAyB;CACjD,OAAO,QAAQ,MAAM"}
@@ -21,28 +21,6 @@ import { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyO
21
21
  type DangerouslyAllowAny = any;
22
22
  //#endregion
23
23
  //#region src/predicate/combinators.d.ts
24
- /**
25
- * Extracts the narrowed target type from a type-guard predicate.
26
- * Returns `never` for plain `boolean` predicates so they don't pollute
27
- * the union/intersection downstream.
28
- *
29
- * `DangerouslyAllowAny` is required here: this conditional needs to match
30
- * predicate signatures with arbitrary input types (`(n: number) => …`,
31
- * `(s: string) => …`, etc.). `unknown` would reject those by contravariance.
32
- */
33
- type Guarded<P> = P extends ((value: DangerouslyAllowAny) => value is infer X) ? X : never;
34
- /**
35
- * Extracts the input type from a tuple of predicates. Uses `infer V` in
36
- * contravariant position so multiple predicates with the same input type
37
- * collapse to that type. Return-position is `unknown` (covariant, accepts
38
- * any return value).
39
- */
40
- type InferInput<Ps> = Ps extends ReadonlyArray<(value: infer V) => unknown> ? V : never;
41
- /**
42
- * Converts a union `A | B | C` to an intersection `A & B & C`.
43
- * Standard contravariant-position trick.
44
- */
45
- type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
46
24
  /**
47
25
  * Returns a predicate that checks if a value satisfies ALL predicates.
48
26
  *
@@ -110,6 +88,17 @@ declare function both<T>(f: (value: T) => boolean, g: (value: T) => boolean): (v
110
88
  */
111
89
  declare function either<T, A extends T, B extends T>(f: (value: T) => value is A, g: (value: T) => value is B): (value: T) => value is A | B;
112
90
  declare function either<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean;
91
+ /**
92
+ * `DangerouslyAllowAny` is required: this conditional needs to match predicate
93
+ * signatures with arbitrary input types. `unknown` would reject them by contravariance.
94
+ */
95
+ type Guarded<P> = P extends ((value: DangerouslyAllowAny) => value is infer X) ? X : never;
96
+ /**
97
+ * `infer V` is contravariant here, so multiple predicates with the same input
98
+ * type collapse to that single type.
99
+ */
100
+ type InferInput<Ps> = Ps extends ReadonlyArray<(value: infer V) => unknown> ? V : never;
101
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
113
102
  //#endregion
114
103
  //#region src/predicate/guards.d.ts
115
104
  /**
@@ -121,7 +110,7 @@ declare function either<T>(f: (value: T) => boolean, g: (value: T) => boolean):
121
110
  * isArray('hello') // false
122
111
  * ```
123
112
  */
124
- declare const isArray: (arg: any) => arg is any[];
113
+ declare function isArray(value: unknown): value is unknown[];
125
114
  /**
126
115
  * Checks if a value is a non-null object.
127
116
  *
@@ -171,7 +160,7 @@ declare function isNotEmpty(value: string | object): boolean;
171
160
  * isFiniteNumber(Infinity) // false
172
161
  * ```
173
162
  */
174
- declare const isFiniteNumber: (value: unknown) => boolean;
163
+ declare function isFiniteNumber(value: unknown): value is number;
175
164
  /**
176
165
  * Checks if a value is an integer.
177
166
  *
@@ -181,7 +170,7 @@ declare const isFiniteNumber: (value: unknown) => boolean;
181
170
  * isInteger(4.2) // false
182
171
  * ```
183
172
  */
184
- declare const isInteger: (value: unknown) => boolean;
173
+ declare function isInteger(value: unknown): value is number;
185
174
  /**
186
175
  * Checks if a value is NaN.
187
176
  *
@@ -191,7 +180,7 @@ declare const isInteger: (value: unknown) => boolean;
191
180
  * isNaN(42) // false
192
181
  * ```
193
182
  */
194
- declare const isNaN: (value: unknown) => boolean;
183
+ declare function isNaN(value: unknown): value is number;
195
184
  //#endregion
196
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 };
197
- //# sourceMappingURL=index-BuBpCB73.d.mts.map
186
+ //# sourceMappingURL=index-B5x6pJw7.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-B5x6pJw7.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,EAAO,UAAA,CAAW,EAAA,MAAQ,KAAA,IAAS,UAAA,CAAW,EAAA,IA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AA0B,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"index-BkyNt8th.d.mts","names":[],"sources":["../src/object/evolve.ts"],"mappings":";;;;;;AAeA;;;;;;;;;;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"}
1
+ {"version":3,"file":"index-BkyNt8th.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"}
@@ -1 +1 @@
1
- {"version":3,"file":"index-COFf0Pih.d.mts","names":[],"sources":["../src/conversion/convert.ts"],"mappings":";;AAwBA;;;;;AA8BA;;;;;AAqFA;;;;;AAgBA;;;;;AAaA;iBAhJgB,OAAA,CAAQ,MAAA,YAAkB,KAAA;;;;AA+J1C;;;;;AAwBA;;;;;;;;;;;;iBAzJgB,SAAA,CAAU,KAAA;;;;;AAmL1B;;;;;;;;;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
+ {"version":3,"file":"index-COFf0Pih.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 +1 @@
1
- {"version":3,"file":"index-Dw_tuZdb.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;;;;;;;;;;;;;;;;iBESgB,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;;;;;;AFdH;;;;;;;;;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;;;;;;;;;;;;;;;;iBKSgB,MAAA,MAAA,CAAa,EAAA,GAAK,IAAA,EAAM,CAAA,MAAO,CAAA,EAAG,CAAA,WAAY,IAAA,EAAM,CAAA,GAAI,CAAA"}
1
+ {"version":3,"file":"index-Dw_tuZdb.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
@@ -5,7 +5,7 @@ import { AbortError, TimeoutError } from "./error/index.mjs";
5
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-DqsBQ7Pp.mjs";
6
6
  import { clamp, inRange, mean, meanBy, median, medianBy, random, randomInt, range, rangeRight, round, sum, sumBy } from "./math/index.mjs";
7
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-BkyNt8th.mjs";
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-BuBpCB73.mjs";
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-B5x6pJw7.mjs";
9
9
  import { Mutex, Semaphore, delay, timeout, withTimeout } from "./promise/index.mjs";
10
10
  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
11
  import { NonExhaustiveError, P, Pattern, isMatching, match } from "./pattern/index.mjs";
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { AbortError, TimeoutError } from "./error/index.mjs";
3
3
  import { C as tap, D as call, E as when, O as callAsync, S as flowAsync, T as unless, _ as rest, a as curry, b as throttle, c as flow, d as memoize, f as negate, g as partialRight, h as partial, i as before, l as flowRight, m as once, n as ary, o as curryRight, p as noop, r as asyncNoop, s as debounce, t as after, u as identity, v as retry, w as ifElse, x as unary, y as spread } from "./function-2-6QB4m7.mjs";
4
4
  import { clamp, inRange, mean, meanBy, median, medianBy, random, randomInt, range, rangeRight, round, sum, sumBy } from "./math/index.mjs";
5
5
  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 "./object-BHnp9Sr9.mjs";
6
- 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 "./predicate-CYzSOMLW.mjs";
6
+ 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 "./predicate-DtTBffBT.mjs";
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";
@@ -1 +1 @@
1
- {"version":3,"file":"object-BHnp9Sr9.mjs","names":[],"sources":["../src/object/evolve.ts"],"sourcesContent":["/* oxlint-disable security/detect-object-injection -- keys sourced from Object.keys(spec), not user input */\n\n/**\n * Applies a spec of transformation functions to matching keys of an object,\n * returning a new object. Keys not in the spec are copied as-is.\n *\n * @example\n * ```ts\n * evolve({ name: ' Alice ', age: 29, role: 'admin' }, {\n * name: (s) => s.trim(),\n * age: (n) => n + 1,\n * })\n * // { name: 'Alice', age: 30, role: 'admin' }\n * ```\n */\nexport function evolve<T extends Record<string, unknown>>(\n obj: T,\n spec: { [K in keyof T]?: (value: T[K]) => T[K] }\n): T {\n const result = { ...obj }\n for (const key of Object.keys(spec) as Array<keyof T>) {\n const transform = spec[key]\n if (transform != null && key in result) {\n result[key] = transform(result[key])\n }\n }\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,OACd,KACA,MACG;CACH,MAAM,SAAS,EAAE,GAAG,KAAK;CACzB,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,EAAoB;EACrD,MAAM,YAAY,KAAK;EACvB,IAAI,aAAa,QAAQ,OAAO,QAC9B,OAAO,OAAO,UAAU,OAAO,KAAK;;CAGxC,OAAO"}
1
+ {"version":3,"file":"object-BHnp9Sr9.mjs","names":[],"sources":["../src/object/evolve.ts"],"sourcesContent":["/**\n * Applies a spec of transformation functions to matching keys of an object,\n * returning a new object. Keys not in the spec are copied as-is.\n *\n * @example\n * ```ts\n * evolve({ name: ' Alice ', age: 29, role: 'admin' }, {\n * name: (s) => s.trim(),\n * age: (n) => n + 1,\n * })\n * // { name: 'Alice', age: 30, role: 'admin' }\n * ```\n */\nexport function evolve<T extends Record<string, unknown>>(\n obj: T,\n spec: { [K in keyof T]?: (value: T[K]) => T[K] }\n): T {\n const result = { ...obj }\n for (const key of Object.keys(spec) as Array<keyof T>) {\n // oxlint-disable-next-line security/detect-object-injection -- key sourced from Object.keys(spec), not user input\n const transform = spec[key]\n if (transform != null && key in result) {\n // oxlint-disable-next-line security/detect-object-injection -- key sourced from Object.keys(spec), not user input\n result[key] = transform(result[key])\n }\n }\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;AAaA,SAAgB,OACd,KACA,MACG;CACH,MAAM,SAAS,EAAE,GAAG,KAAK;CACzB,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,EAAoB;EAErD,MAAM,YAAY,KAAK;EACvB,IAAI,aAAa,QAAQ,OAAO,QAE9B,OAAO,OAAO,UAAU,OAAO,KAAK;;CAGxC,OAAO"}
@@ -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-BuBpCB73.mjs";
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-B5x6pJw7.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 };
@@ -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 "../predicate-CYzSOMLW.mjs";
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 "../predicate-DtTBffBT.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 };
@@ -23,7 +23,9 @@ function either(f, g) {
23
23
  * isArray('hello') // false
24
24
  * ```
25
25
  */
26
- const isArray = Array.isArray;
26
+ function isArray(value) {
27
+ return Array.isArray(value);
28
+ }
27
29
  /**
28
30
  * Checks if a value is a non-null object.
29
31
  *
@@ -81,7 +83,9 @@ function isNotEmpty(value) {
81
83
  * isFiniteNumber(Infinity) // false
82
84
  * ```
83
85
  */
84
- const isFiniteNumber = Number.isFinite;
86
+ function isFiniteNumber(value) {
87
+ return Number.isFinite(value);
88
+ }
85
89
  /**
86
90
  * Checks if a value is an integer.
87
91
  *
@@ -91,7 +95,9 @@ const isFiniteNumber = Number.isFinite;
91
95
  * isInteger(4.2) // false
92
96
  * ```
93
97
  */
94
- const isInteger = Number.isInteger;
98
+ function isInteger(value) {
99
+ return Number.isInteger(value);
100
+ }
95
101
  /**
96
102
  * Checks if a value is NaN.
97
103
  *
@@ -101,8 +107,10 @@ const isInteger = Number.isInteger;
101
107
  * isNaN(42) // false
102
108
  * ```
103
109
  */
104
- const isNaN = Number.isNaN;
110
+ function isNaN(value) {
111
+ return Number.isNaN(value);
112
+ }
105
113
  //#endregion
106
114
  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 };
107
115
 
108
- //# sourceMappingURL=predicate-CYzSOMLW.mjs.map
116
+ //# sourceMappingURL=predicate-DtTBffBT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicate-DtTBffBT.mjs","names":[],"sources":["../src/predicate/combinators.ts","../src/predicate/guards.ts"],"sourcesContent":["import type { DangerouslyAllowAny } from '../types/internal.js'\n\n/**\n * Returns a predicate that checks if a value satisfies ALL predicates.\n *\n * When every input is a type guard, the result narrows to the intersection\n * of every guard's target type. Plain `boolean` predicates contribute nothing\n * to the narrowing (they fall back to no-op).\n *\n * @example\n * ```ts\n * const isPositiveEven = allPass([(n: number) => n > 0, (n: number) => n % 2 === 0])\n * isPositiveEven(4) // true\n *\n * const isNonEmptyString = allPass([isString, isNotEmpty])\n * if (isNonEmptyString(x)) {\n * // x is narrowed to string here\n * }\n * ```\n */\nexport function allPass<T>(predicates: readonly []): (value: T) => true\nexport function allPass<Ps extends ReadonlyArray<(value: DangerouslyAllowAny) => boolean>>(\n predicates: Ps\n): (value: InferInput<Ps>) => value is InferInput<Ps> & UnionToIntersection<Guarded<Ps[number]>>\nexport function allPass(\n predicates: ReadonlyArray<(value: unknown) => boolean>\n): (value: unknown) => boolean {\n return (value: unknown) => predicates.every((pred) => pred(value))\n}\n\n/**\n * Returns a predicate that checks if a value satisfies ANY predicate.\n *\n * When every input is a type guard, the result narrows to the union of every\n * guard's target type (since only one needs to match).\n *\n * @example\n * ```ts\n * const isAdminOrOwner = anyPass([isAdmin, isOwner])\n * isAdminOrOwner(user)\n *\n * const isStringOrNumber = anyPass([isString, isNumber])\n * if (isStringOrNumber(x)) {\n * // x is narrowed to string | number here\n * }\n * ```\n */\nexport function anyPass<T>(predicates: readonly []): (value: T) => false\nexport function anyPass<Ps extends ReadonlyArray<(value: DangerouslyAllowAny) => boolean>>(\n predicates: Ps\n): (value: InferInput<Ps>) => value is InferInput<Ps> & Guarded<Ps[number]>\nexport function anyPass(\n predicates: ReadonlyArray<(value: unknown) => boolean>\n): (value: unknown) => boolean {\n return (value: unknown) => predicates.some((pred) => pred(value))\n}\n\n/**\n * Returns a predicate that checks if a value satisfies both predicates.\n *\n * Binary AND combinator — shorthand for `allPass([f, g])`. When both inputs\n * are type guards, the result narrows to the intersection of their target types.\n *\n * @example\n * ```ts\n * const isPositiveEven = both((n: number) => n > 0, (n: number) => n % 2 === 0)\n * isPositiveEven(4)\n * ```\n */\nexport function both<T, A extends T, B extends T>(\n f: (value: T) => value is A,\n g: (value: T) => value is B\n): (value: T) => value is A & B\nexport function both<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean\nexport function both<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean {\n return (value: T) => f(value) && g(value)\n}\n\n/**\n * Returns a predicate that checks if a value satisfies either predicate.\n *\n * Binary OR combinator — shorthand for `anyPass([f, g])`. When both inputs\n * are type guards, the result narrows to the union of their target types.\n *\n * @example\n * ```ts\n * const isNilOrEmpty = either(isNil, (s: string) => s === '')\n * isNilOrEmpty(null)\n * ```\n */\nexport function either<T, A extends T, B extends T>(\n f: (value: T) => value is A,\n g: (value: T) => value is B\n): (value: T) => value is A | B\nexport function either<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean\nexport function either<T>(\n f: (value: T) => boolean,\n g: (value: T) => boolean\n): (value: T) => boolean {\n return (value: T) => f(value) || g(value)\n}\n\n/**\n * `DangerouslyAllowAny` is required: this conditional needs to match predicate\n * signatures with arbitrary input types. `unknown` would reject them by contravariance.\n */\ntype Guarded<P> = P extends ((value: DangerouslyAllowAny) => value is infer X) ? X : never\n\n/**\n * `infer V` is contravariant here, so multiple predicates with the same input\n * type collapse to that single type.\n */\ntype InferInput<Ps> = Ps extends ReadonlyArray<(value: infer V) => unknown> ? V : never\n\ntype UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (\n k: infer I\n) => void\n ? I\n : never\n","/**\n * Checks if a value is an array.\n *\n * @example\n * ```ts\n * isArray([1, 2]) // true\n * isArray('hello') // false\n * ```\n */\nexport function isArray(value: unknown): value is unknown[] {\n return Array.isArray(value)\n}\n\n/**\n * Checks if a value is a non-null object.\n *\n * Returns `true` for plain objects, arrays, class instances, etc.\n * Returns `false` for `null`, primitives, and functions.\n *\n * @example\n * ```ts\n * isObject({}) // true\n * isObject(null) // false\n * ```\n */\nexport function isObject(value: unknown): value is object {\n return value !== null && typeof value === 'object'\n}\n\n/**\n * Checks if a value is empty.\n *\n * - Strings: `''`\n * - Arrays: `length === 0`\n * - Maps/Sets: `size === 0`\n * - Objects: no own enumerable keys\n *\n * @example\n * ```ts\n * isEmpty('') // true\n * isEmpty([]) // true\n * isEmpty({}) // true\n * isEmpty(new Map()) // true\n * ```\n */\nexport function isEmpty(value: string | object): boolean {\n if (typeof value === 'string' || Array.isArray(value)) {\n return value.length === 0\n }\n if (value instanceof Map || value instanceof Set) {\n return value.size === 0\n }\n return Object.keys(value).length === 0\n}\n\n/**\n * Checks if a value is not empty. Complement of {@link isEmpty}.\n *\n * @example\n * ```ts\n * isNotEmpty('hello') // true\n * isNotEmpty([]) // false\n * ```\n */\nexport function isNotEmpty(value: string | object): boolean {\n return !isEmpty(value)\n}\n\n/**\n * Checks if a value is a finite number.\n *\n * @example\n * ```ts\n * isFiniteNumber(42) // true\n * isFiniteNumber(Infinity) // false\n * ```\n */\nexport function isFiniteNumber(value: unknown): value is number {\n return Number.isFinite(value)\n}\n\n/**\n * Checks if a value is an integer.\n *\n * @example\n * ```ts\n * isInteger(42) // true\n * isInteger(4.2) // false\n * ```\n */\nexport function isInteger(value: unknown): value is number {\n return Number.isInteger(value)\n}\n\n/**\n * Checks if a value is NaN.\n *\n * @example\n * ```ts\n * isNaN(NaN) // true\n * isNaN(42) // false\n * ```\n */\nexport function isNaN(value: unknown): value is number {\n return Number.isNaN(value)\n}\n"],"mappings":";;AAwBA,SAAgB,QACd,YAC6B;CAC7B,QAAQ,UAAmB,WAAW,OAAO,SAAS,KAAK,MAAM,CAAC;;AAwBpE,SAAgB,QACd,YAC6B;CAC7B,QAAQ,UAAmB,WAAW,MAAM,SAAS,KAAK,MAAM,CAAC;;AAoBnE,SAAgB,KAAQ,GAA0B,GAAiD;CACjG,QAAQ,UAAa,EAAE,MAAM,IAAI,EAAE,MAAM;;AAoB3C,SAAgB,OACd,GACA,GACuB;CACvB,QAAQ,UAAa,EAAE,MAAM,IAAI,EAAE,MAAM;;;;;;;;;;;;;AC1F3C,SAAgB,QAAQ,OAAoC;CAC1D,OAAO,MAAM,QAAQ,MAAM;;;;;;;;;;;;;;AAe7B,SAAgB,SAAS,OAAiC;CACxD,OAAO,UAAU,QAAQ,OAAO,UAAU;;;;;;;;;;;;;;;;;;AAmB5C,SAAgB,QAAQ,OAAiC;CACvD,IAAI,OAAO,UAAU,YAAY,MAAM,QAAQ,MAAM,EACnD,OAAO,MAAM,WAAW;CAE1B,IAAI,iBAAiB,OAAO,iBAAiB,KAC3C,OAAO,MAAM,SAAS;CAExB,OAAO,OAAO,KAAK,MAAM,CAAC,WAAW;;;;;;;;;;;AAYvC,SAAgB,WAAW,OAAiC;CAC1D,OAAO,CAAC,QAAQ,MAAM;;;;;;;;;;;AAYxB,SAAgB,eAAe,OAAiC;CAC9D,OAAO,OAAO,SAAS,MAAM;;;;;;;;;;;AAY/B,SAAgB,UAAU,OAAiC;CACzD,OAAO,OAAO,UAAU,MAAM;;;;;;;;;;;AAYhC,SAAgB,MAAM,OAAiC;CACrD,OAAO,OAAO,MAAM,MAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "massaman",
3
- "version": "0.0.1-rc.2",
3
+ "version": "0.1.0",
4
4
  "description": "A comprehensive functional programming library and utilities for TypeScript",
5
5
  "keywords": [
6
6
  "es-toolkit",
@@ -81,7 +81,8 @@
81
81
  }
82
82
  },
83
83
  "publishConfig": {
84
- "access": "public"
84
+ "access": "public",
85
+ "provenance": true
85
86
  },
86
87
  "dependencies": {
87
88
  "es-toolkit": "1.46.1",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-BuBpCB73.d.mts","names":[],"sources":["../src/types/internal.ts","../src/predicate/combinators.ts","../src/predicate/guards.ts"],"mappings":";;;;;;AAmBA;;;;;;;;ACnB+D;;;;;;KDmBnD,mBAAA;;;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,cAAoB,CAAA,YAAa,CAAA,CAAA,CAC/C,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,KAAA,IAAS,CAAA,EAC1B,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,KAAA,IAAS,CAAA,IACxB,KAAA,EAAO,CAAA,KAAM,KAAA,IAAS,CAAA,GAAI,CAAA;AAAA,iBACd,MAAA,GAAA,CAAU,CAAA,GAAI,KAAA,EAAO,CAAA,cAAe,CAAA,GAAI,KAAA,EAAO,CAAA,gBAAiB,KAAA,EAAO,CAAA;;;;;;ADxGvF;;;;;;cEVa,OAAA,GAAO,GAAA,UAAA,GAAA;;ADT2C;;;;;;;;;;;iBCuB/C,QAAA,CAAS,KAAA,YAAiB,KAAA;;ADZwC;;;;;;;;;;;;AAQH;;;iBCwB/D,OAAA,CAAQ,KAAA;;;;;;;;;;iBAmBR,UAAA,CAAW,KAAA;;;;;;;;;;cAad,cAAA,GAAiB,KAAA;;;;;;;;;;cAWjB,SAAA,GAAY,KAAA;;;;;;;;;;cAWZ,KAAA,GAAQ,KAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"predicate-CYzSOMLW.mjs","names":[],"sources":["../src/predicate/combinators.ts","../src/predicate/guards.ts"],"sourcesContent":["import type { DangerouslyAllowAny } from '../types/internal.js'\n\n/**\n * Extracts the narrowed target type from a type-guard predicate.\n * Returns `never` for plain `boolean` predicates so they don't pollute\n * the union/intersection downstream.\n *\n * `DangerouslyAllowAny` is required here: this conditional needs to match\n * predicate signatures with arbitrary input types (`(n: number) => …`,\n * `(s: string) => …`, etc.). `unknown` would reject those by contravariance.\n */\ntype Guarded<P> = P extends ((value: DangerouslyAllowAny) => value is infer X) ? X : never\n\n/**\n * Extracts the input type from a tuple of predicates. Uses `infer V` in\n * contravariant position so multiple predicates with the same input type\n * collapse to that type. Return-position is `unknown` (covariant, accepts\n * any return value).\n */\ntype InferInput<Ps> = Ps extends ReadonlyArray<(value: infer V) => unknown> ? V : never\n\n/**\n * Converts a union `A | B | C` to an intersection `A & B & C`.\n * Standard contravariant-position trick.\n */\ntype UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (\n k: infer I\n) => void\n ? I\n : never\n\n/**\n * Returns a predicate that checks if a value satisfies ALL predicates.\n *\n * When every input is a type guard, the result narrows to the intersection\n * of every guard's target type. Plain `boolean` predicates contribute nothing\n * to the narrowing (they fall back to no-op).\n *\n * @example\n * ```ts\n * const isPositiveEven = allPass([(n: number) => n > 0, (n: number) => n % 2 === 0])\n * isPositiveEven(4) // true\n *\n * const isNonEmptyString = allPass([isString, isNotEmpty])\n * if (isNonEmptyString(x)) {\n * // x is narrowed to string here\n * }\n * ```\n */\nexport function allPass<T>(predicates: readonly []): (value: T) => true\nexport function allPass<Ps extends ReadonlyArray<(value: DangerouslyAllowAny) => boolean>>(\n predicates: Ps\n): (value: InferInput<Ps>) => value is InferInput<Ps> & UnionToIntersection<Guarded<Ps[number]>>\nexport function allPass(\n predicates: ReadonlyArray<(value: unknown) => boolean>\n): (value: unknown) => boolean {\n return (value: unknown) => predicates.every((pred) => pred(value))\n}\n\n/**\n * Returns a predicate that checks if a value satisfies ANY predicate.\n *\n * When every input is a type guard, the result narrows to the union of every\n * guard's target type (since only one needs to match).\n *\n * @example\n * ```ts\n * const isAdminOrOwner = anyPass([isAdmin, isOwner])\n * isAdminOrOwner(user)\n *\n * const isStringOrNumber = anyPass([isString, isNumber])\n * if (isStringOrNumber(x)) {\n * // x is narrowed to string | number here\n * }\n * ```\n */\nexport function anyPass<T>(predicates: readonly []): (value: T) => false\nexport function anyPass<Ps extends ReadonlyArray<(value: DangerouslyAllowAny) => boolean>>(\n predicates: Ps\n): (value: InferInput<Ps>) => value is InferInput<Ps> & Guarded<Ps[number]>\nexport function anyPass(\n predicates: ReadonlyArray<(value: unknown) => boolean>\n): (value: unknown) => boolean {\n return (value: unknown) => predicates.some((pred) => pred(value))\n}\n\n/**\n * Returns a predicate that checks if a value satisfies both predicates.\n *\n * Binary AND combinator — shorthand for `allPass([f, g])`. When both inputs\n * are type guards, the result narrows to the intersection of their target types.\n *\n * @example\n * ```ts\n * const isPositiveEven = both((n: number) => n > 0, (n: number) => n % 2 === 0)\n * isPositiveEven(4)\n * ```\n */\nexport function both<T, A extends T, B extends T>(\n f: (value: T) => value is A,\n g: (value: T) => value is B\n): (value: T) => value is A & B\nexport function both<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean\nexport function both<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean {\n return (value: T) => f(value) && g(value)\n}\n\n/**\n * Returns a predicate that checks if a value satisfies either predicate.\n *\n * Binary OR combinator — shorthand for `anyPass([f, g])`. When both inputs\n * are type guards, the result narrows to the union of their target types.\n *\n * @example\n * ```ts\n * const isNilOrEmpty = either(isNil, (s: string) => s === '')\n * isNilOrEmpty(null)\n * ```\n */\nexport function either<T, A extends T, B extends T>(\n f: (value: T) => value is A,\n g: (value: T) => value is B\n): (value: T) => value is A | B\nexport function either<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean\nexport function either<T>(\n f: (value: T) => boolean,\n g: (value: T) => boolean\n): (value: T) => boolean {\n return (value: T) => f(value) || g(value)\n}\n","/**\n * Checks if a value is an array.\n *\n * @example\n * ```ts\n * isArray([1, 2]) // true\n * isArray('hello') // false\n * ```\n */\nexport const isArray = Array.isArray\n\n/**\n * Checks if a value is a non-null object.\n *\n * Returns `true` for plain objects, arrays, class instances, etc.\n * Returns `false` for `null`, primitives, and functions.\n *\n * @example\n * ```ts\n * isObject({}) // true\n * isObject(null) // false\n * ```\n */\nexport function isObject(value: unknown): value is object {\n return value !== null && typeof value === 'object'\n}\n\n/**\n * Checks if a value is empty.\n *\n * - Strings: `''`\n * - Arrays: `length === 0`\n * - Maps/Sets: `size === 0`\n * - Objects: no own enumerable keys\n *\n * @example\n * ```ts\n * isEmpty('') // true\n * isEmpty([]) // true\n * isEmpty({}) // true\n * isEmpty(new Map()) // true\n * ```\n */\nexport function isEmpty(value: string | object): boolean {\n if (typeof value === 'string' || Array.isArray(value)) {\n return value.length === 0\n }\n if (value instanceof Map || value instanceof Set) {\n return value.size === 0\n }\n return Object.keys(value).length === 0\n}\n\n/**\n * Checks if a value is not empty. Complement of {@link isEmpty}.\n *\n * @example\n * ```ts\n * isNotEmpty('hello') // true\n * isNotEmpty([]) // false\n * ```\n */\nexport function isNotEmpty(value: string | object): boolean {\n return !isEmpty(value)\n}\n\n/**\n * Checks if a value is a finite number.\n *\n * @example\n * ```ts\n * isFiniteNumber(42) // true\n * isFiniteNumber(Infinity) // false\n * ```\n */\nexport const isFiniteNumber: (value: unknown) => boolean = Number.isFinite\n\n/**\n * Checks if a value is an integer.\n *\n * @example\n * ```ts\n * isInteger(42) // true\n * isInteger(4.2) // false\n * ```\n */\nexport const isInteger: (value: unknown) => boolean = Number.isInteger\n\n/**\n * Checks if a value is NaN.\n *\n * @example\n * ```ts\n * isNaN(NaN) // true\n * isNaN(42) // false\n * ```\n */\nexport const isNaN: (value: unknown) => boolean = Number.isNaN\n"],"mappings":";;AAqDA,SAAgB,QACd,YAC6B;CAC7B,QAAQ,UAAmB,WAAW,OAAO,SAAS,KAAK,MAAM,CAAC;;AAwBpE,SAAgB,QACd,YAC6B;CAC7B,QAAQ,UAAmB,WAAW,MAAM,SAAS,KAAK,MAAM,CAAC;;AAoBnE,SAAgB,KAAQ,GAA0B,GAAiD;CACjG,QAAQ,UAAa,EAAE,MAAM,IAAI,EAAE,MAAM;;AAoB3C,SAAgB,OACd,GACA,GACuB;CACvB,QAAQ,UAAa,EAAE,MAAM,IAAI,EAAE,MAAM;;;;;;;;;;;;;ACvH3C,MAAa,UAAU,MAAM;;;;;;;;;;;;;AAc7B,SAAgB,SAAS,OAAiC;CACxD,OAAO,UAAU,QAAQ,OAAO,UAAU;;;;;;;;;;;;;;;;;;AAmB5C,SAAgB,QAAQ,OAAiC;CACvD,IAAI,OAAO,UAAU,YAAY,MAAM,QAAQ,MAAM,EACnD,OAAO,MAAM,WAAW;CAE1B,IAAI,iBAAiB,OAAO,iBAAiB,KAC3C,OAAO,MAAM,SAAS;CAExB,OAAO,OAAO,KAAK,MAAM,CAAC,WAAW;;;;;;;;;;;AAYvC,SAAgB,WAAW,OAAiC;CAC1D,OAAO,CAAC,QAAQ,MAAM;;;;;;;;;;;AAYxB,MAAa,iBAA8C,OAAO;;;;;;;;;;AAWlE,MAAa,YAAyC,OAAO;;;;;;;;;;AAW7D,MAAa,QAAqC,OAAO"}