UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

1 lines 1.5 kB
{"version":3,"file":"lazyDataLastImpl-DdpJofHC.cjs","names":[],"sources":["../src/internal/lazyDataLastImpl.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { LazyEvaluator } from \"./types/LazyEvaluator\";\nimport type { StrictFunction } from \"./types/StrictFunction\";\n\n/**\n * Use this helper function to build the data last implementation together with\n * a lazy implementation. Use this when you need to build your own purrying\n * logic when you want to decide between dataFirst and dataLast on something\n * that isn't the number of arguments provided. This is useful for implementing\n * functions with optional or variadic arguments.\n */\nexport function lazyDataLastImpl(\n fn: StrictFunction,\n args: ReadonlyArray<unknown>,\n lazy?: (...args: any) => LazyEvaluator,\n // TODO: We can probably provide better typing to the return type...\n): unknown {\n // @ts-expect-error [ts2345] -- This error is accurate because we don't know\n // anything about `fn` so can't ensure that we are passing the correct\n // arguments to it, we just have to trust that the caller knows what they are\n // doing.\n const dataLast = (data: unknown): unknown => fn(data, ...args);\n\n return lazy === undefined\n ? dataLast\n : Object.assign(dataLast, { lazy, lazyArgs: args });\n}\n"],"mappings":"AAYA,SAAgB,EACd,EACA,EACA,EAES,CAKT,IAAM,EAAY,GAA2B,EAAG,EAAM,GAAG,EAAK,CAE9D,OAAO,IAAS,IAAA,GACZ,EACA,OAAO,OAAO,EAAU,CAAE,OAAM,SAAU,EAAM,CAAC"}