UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

1 lines 1.39 kB
{"version":3,"file":"purryOn-wBH_q-mO.cjs","names":[],"sources":["../src/internal/purryOn.ts"],"sourcesContent":["/**\n * Utility for purrying functions based on a predicate for the first argument.\n *\n * This is useful for purrying functions with an optional parameter or a\n * variadic argument list.\n */\nexport function purryOn<T>(\n isArg: (firstArg: unknown) => firstArg is T,\n // We use `never` for the params to allow **any** function to match, this\n // works because all functions extend this shape, using `unknown` would\n // produce the opposite effect. This is better than using `any` which simply\n // avoids addressing the typing issue.\n implementation: (data: never, firstArg: T, ...args: never) => 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: never) => 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"],"mappings":"AAMA,SAAgB,EACd,EAKA,EACA,EACS,CACT,OAAO,EAAM,EAAK,EAAE,EAEf,GAAgB,EAAe,EAAM,GAAG,CAAI,EAE7C,EAAe,GAAG,CAAI,CAC5B"}