TreasureTrails/node_modules/remeda/dist/conditional-DAH-6cGE.cjs.map

1 line
23 KiB
Text
Raw Normal View History

2026-03-18 09:02:21 -05:00
{"version":3,"file":"conditional-DAH-6cGE.cjs","names":[],"sources":["../src/internal/purryOn.ts","../src/conditional.ts"],"sourcesContent":["/**\n * Utility for purrying functions based on a predicate for the first argument.\n *\n * This is useful for purrying functions with a variadic argument list.\n */\nexport function purryOn<T>(\n isArg: (firstArg: unknown) => firstArg is T,\n implementation: (\n data: unknown,\n firstArg: T,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Function inference in typescript relies on `any` to work, it doesn't work with `unknown`\n ...args: any\n ) => unknown,\n args: readonly unknown[],\n): unknown {\n return isArg(args[0])\n ? // @ts-expect-error [ts2556] - This is a low-level function that assumes the function declaration and setup is correct and won't result in typing issues when called dynamically.\n (data: unknown) => implementation(data, ...args)\n : // @ts-expect-error [ts2556] - This is a low-level function that assumes the function declaration and setup is correct and won't result in typing issues when called dynamically.\n implementation(...args);\n}\n","/* eslint-disable jsdoc/check-param-names, jsdoc/require-param --\n * We don't document each `case` param, instead we document the concept more\n * generally, but these eslint rules can't detect that.\n */\n\nimport { purryOn } from \"./internal/purryOn\";\nimport type { GuardType } from \"./internal/types/GuardType\";\n\ntype Case<\n In,\n Out,\n When extends (x: In) => boolean = (x: In) => boolean,\n> = readonly [when: When, then: (x: GuardType<When, In> & In) => Out];\n\ntype DefaultCase<In, Out> = (x: In) => Out;\n\n/**\n * Executes a transformer function based on the first matching predicate,\n * functioning like a series of `if...else if...` statements. It sequentially\n * evaluates each case and, upon finding a truthy predicate, runs the\n * corresponding transformer, and returns, ignoring any further cases, even if\n * they would match.\n *\n * *NOTE*: Some type-predicates may fail to narrow the param type of their\n * transformer; in such cases wrap your type-predicate in an anonymous arrow\n * function: e.g., instead of\n * `conditional(..., [myTypePredicate, myTransformer], ...)`, use\n * `conditional(..., [($) => myTypePredicate($), myTransformer], ...)`.\n *\n * To add a a default, catch-all, case you can provide a single callback\n * function (instead of a 2-tuple) as the last case. This is equivalent to\n * adding a case with a trivial always-true predicate as it's condition (see\n * example).\n *\n * For simpler cases you should also consider using `when` instead.\n *\n * Due to TypeScript's inability to infer the result of negating a type-\n * predicate we can't refine the types used in subsequent cases based on\n * previous conditions. Using a `switch (true)` statement or ternary operators\n * is recommended for more precise type control when such type narrowing is\n * needed.\n *\n * !IMPORTANT! - Unlike similar implementations in Lodash and Ramda, the Remeda\n * implementation **doesn't** implicitly return `undefined` as a fallback when\n * when none of the cases match; and instead **throws** an exception in those\n * cases! You have to explicitly provide a default case, and can use\n * `constant(undefined)` as your last case to replicate that behavior.\n *\n * @param cases - A list of (up to 10) cases. Each case can be either:\n * - A 2-tuple consisting of a predicate (or type-predicate) and a transformer\n * function that processes the data if the predicate matches.\n * - A single callback function that acts as a default fallback case.\n * @returns The output of the matched transformer. If no cases match, an\n * exception is thrown. The return type is a union of the return types of all\n * provided transformers.\n * @signature\n * R.conditional(...cases)(data);\n * @example\n * const nameOrId = 3 as string | number | boolean;\n *\n * R.pipe(\n * nameOrId,\n * R.conditional(\n * [R.isString, (name) => `Hello ${name}`],\n *