UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

1 lines 2.45 kB
{"version":3,"file":"findIndex.cjs","names":["purry"],"sources":["../src/findIndex.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Returns the index of the first element in an array that satisfies the\n * provided testing function. If no elements satisfy the testing function, -1 is\n * returned.\n *\n * See also the `find` method, which returns the first element that satisfies\n * the testing function (rather than its index).\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return a `true` to indicate a matching element has been found, and a\n * `false` otherwise.\n * @returns The index of the first element in the array that passes the test.\n * Otherwise, -1.\n * @signature\n * R.findIndex(data, predicate)\n * @example\n * R.findIndex([1, 3, 4, 6], n => n % 2 === 0) // => 2\n * @dataFirst\n * @category Array\n */\nexport function findIndex<T>(\n data: ReadonlyArray<T>,\n predicate: (value: T, index: number, obj: ReadonlyArray<T>) => boolean,\n): number;\n\n/**\n * Returns the index of the first element in an array that satisfies the\n * provided testing function. If no elements satisfy the testing function, -1 is\n * returned.\n *\n * See also the `find` method, which returns the first element that satisfies\n * the testing function (rather than its index).\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return a `true` to indicate a matching element has been found, and a\n * `false` otherwise.\n * @returns The index of the first element in the array that passes the test.\n * Otherwise, -1.\n * @signature\n * R.findIndex(predicate)(data)\n * @example\n * R.pipe(\n * [1, 3, 4, 6],\n * R.findIndex(n => n % 2 === 0)\n * ); // => 2\n * @dataLast\n * @category Array\n */\nexport function findIndex<T>(\n predicate: (value: T, index: number, obj: ReadonlyArray<T>) => boolean,\n): (data: ReadonlyArray<T>) => number;\n\nexport function findIndex(...args: ReadonlyArray<unknown>): unknown {\n return purry(findIndexImplementation, args);\n}\n\nconst findIndexImplementation = <T>(\n data: ReadonlyArray<T>,\n predicate: (value: T, index: number, obj: ReadonlyArray<T>) => boolean,\n): number => data.findIndex(predicate);\n"],"mappings":"wCAuDA,SAAgB,EAAU,GAAG,EAAuC,CAClE,OAAOA,EAAAA,EAAM,EAAyB,EAAK,CAG7C,MAAM,GACJ,EACA,IACW,EAAK,UAAU,EAAU"}