{"_attachments":{},"_id":"p-locate","_rev":"1886-61f147f623990e8a812f20d0","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"description":"Get the first fulfilled promise that satisfies the provided testing function","dist-tags":{"latest":"7.0.0"},"license":"MIT","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"name":"p-locate","readme":"# p-locate\n\n> Get the first fulfilled promise that satisfies the provided testing function\n\nThink of it like an async version of [`Array#find`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find).\n\n## Install\n\n```sh\nnpm install p-locate\n```\n\n## Usage\n\nHere we find the first file that exists on disk, in array order.\n\n```js\nimport {pathExists} from 'path-exists';\nimport pLocate from 'p-locate';\n\nconst files = [\n\t'unicorn.png',\n\t'rainbow.png', // Only this one actually exists on disk\n\t'pony.png'\n];\n\nconst foundPath = await pLocate(files, file => pathExists(file));\n\nconsole.log(foundPath);\n//=> 'rainbow.png'\n```\n\n*The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*\n\n## API\n\n### pLocate(input, tester, options?)\n\nReturns a `Promise` that is fulfilled when `tester` resolves to `true` or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or `undefined` if `tester` never resolved to `true`.\n\n#### input\n\nType: `Iterable<Promise | unknown> | AsyncIterable<unknown>`\n\nAn iterable or async iterable of promises/values to test.\n\nWhen an `AsyncIterable` is given, it is iterated serially and the `concurrency` and `preserveOrder` options are not applicable.\n\n#### tester(element)\n\nType: `Function`\n\nThis function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`.\n\n#### options\n\nType: `object`\n\n##### concurrency\n\nType: `number`\\\nDefault: `Infinity`\\\nMinimum: `1`\n\nThe number of concurrently pending promises returned by `tester`.\n\n##### preserveOrder\n\nType: `boolean`\\\nDefault: `true`\n\nPreserve `input` order when searching.\n\nDisable this to improve performance if you don't care about the order.\n\n## Related\n\n- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently\n- [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently\n- [p-any](https://github.com/sindresorhus/p-any) - Wait for any promise to be fulfilled\n- [More…](https://github.com/sindresorhus/promise-fun)\n","time":{"created":"2022-01-26T13:09:10.419Z","modified":"2026-02-03T07:58:09.527Z","6.0.0":"2021-08-25T11:56:43.294Z","5.0.0":"2020-08-10T17:42:34.692Z","4.1.0":"2019-04-04T05:02:46.111Z","4.0.0":"2019-03-12T09:46:24.520Z","3.0.0":"2018-06-15T12:47:57.897Z","2.0.0":"2016-11-28T05:25:21.460Z","1.0.0":"2016-11-20T10:07:34.210Z","7.0.0":"2026-02-03T07:57:49.916Z"},"versions":{"6.0.0":{"name":"p-locate","version":"6.0.0","description":"Get the first fulfilled promise that satisfies the provided testing function","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"dependencies":{"p-limit":"^4.0.0"},"devDependencies":{"ava":"^3.15.0","delay":"^5.0.0","in-range":"^3.0.0","time-span":"^5.0.0","tsd":"^0.17.0","xo":"^0.44.0"},"gitHead":"1f7712038d6c9de2c197bc2ce43f4dc3456ae7f8","bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","_id":"p-locate@6.0.0","_nodeVersion":"16.7.0","_npmVersion":"7.20.3","dist":{"shasum":"3da9a49d4934b901089dca3302fa65dc5a05c04f","size":3069,"noattachment":false,"tarball":"https://registry.npmmirror.com/p-locate/-/p-locate-6.0.0.tgz","integrity":"sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw=="},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-locate_6.0.0_1629892603140_0.8482496598470137"},"_hasShrinkwrap":false,"publish_time":1629892603294,"_cnpm_publish_time":1629892603294,"_cnpmcore_publish_time":"2021-12-13T11:52:00.190Z"},"5.0.0":{"name":"p-locate","version":"5.0.0","description":"Get the first fulfilled promise that satisfies the provided testing function","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"engines":{"node":">=10"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"dependencies":{"p-limit":"^3.0.2"},"devDependencies":{"ava":"^2.4.0","delay":"^4.1.0","in-range":"^2.0.0","time-span":"^4.0.0","tsd":"^0.13.1","xo":"^0.32.1"},"gitHead":"a01d0e4d555c00e1551954751fd3cd4b238ce82f","bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","_id":"p-locate@5.0.0","_nodeVersion":"14.5.0","_npmVersion":"6.14.7","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"83c8315c6785005e3bd021839411c9e110e6d834","size":3151,"noattachment":false,"tarball":"https://registry.npmmirror.com/p-locate/-/p-locate-5.0.0.tgz","integrity":"sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw=="},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-locate_5.0.0_1597081354525_0.2940768154089548"},"_hasShrinkwrap":false,"publish_time":1597081354692,"_cnpm_publish_time":1597081354692,"_cnpmcore_publish_time":"2021-12-13T11:52:00.447Z"},"4.1.0":{"name":"p-locate","version":"4.1.0","description":"Get the first fulfilled promise that satisfies the provided testing function","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"dependencies":{"p-limit":"^2.2.0"},"devDependencies":{"ava":"^1.4.1","delay":"^4.1.0","in-range":"^1.0.0","time-span":"^3.0.0","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"a650b26e49713a8cca58f669a7f8aef9b655554c","bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","_id":"p-locate@4.1.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"a3428bb7088b3a60292f66919278b7c297ad4f07","size":3060,"noattachment":false,"tarball":"https://registry.npmmirror.com/p-locate/-/p-locate-4.1.0.tgz","integrity":"sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A=="},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-locate_4.1.0_1554354165996_0.6426620981467144"},"_hasShrinkwrap":false,"publish_time":1554354166111,"_cnpm_publish_time":1554354166111,"_cnpmcore_publish_time":"2021-12-13T11:52:00.746Z"},"4.0.0":{"name":"p-locate","version":"4.0.0","description":"Get the first fulfilled promise that satisfies the provided testing function","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"dependencies":{"p-limit":"^2.0.0"},"devDependencies":{"ava":"^1.3.1","delay":"^4.1.0","in-range":"^1.0.0","time-span":"^3.0.0","tsd-check":"^0.3.0","xo":"^0.24.0"},"gitHead":"44264731678d799f596872cb9ca73e0a3de4232f","bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","_id":"p-locate@4.0.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"fff5d4a5dc4f89babe7d266f6efc685630038651","size":2916,"noattachment":false,"tarball":"https://registry.npmmirror.com/p-locate/-/p-locate-4.0.0.tgz","integrity":"sha512-IvOiDT1hbCdrsFKKXs8AGjxouEfn9VVdz/edtT08IDr+RIn2U/o3Xx+Agx455+CkSRdomMs3EN5BgR2Q0LZX0g=="},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-locate_4.0.0_1552383984361_0.08899244113594595"},"_hasShrinkwrap":false,"publish_time":1552383984520,"_cnpm_publish_time":1552383984520,"_cnpmcore_publish_time":"2021-12-13T11:52:01.106Z"},"3.0.0":{"name":"p-locate","version":"3.0.0","description":"Get the first fulfilled promise that satisfies the provided testing function","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"dependencies":{"p-limit":"^2.0.0"},"devDependencies":{"ava":"*","delay":"^3.0.0","in-range":"^1.0.0","time-span":"^2.0.0","xo":"*"},"gitHead":"d37f108c0b04779e307b4e7203981caa367bac57","bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","_id":"p-locate@3.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"322d69a05c0264b25997d9f40cd8a891ab0064a4","size":2579,"noattachment":false,"tarball":"https://registry.npmmirror.com/p-locate/-/p-locate-3.0.0.tgz","integrity":"sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ=="},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-locate_3.0.0_1529066877849_0.3762033584213962"},"_hasShrinkwrap":false,"publish_time":1529066877897,"_cnpm_publish_time":1529066877897,"_cnpmcore_publish_time":"2021-12-13T11:52:01.393Z"},"2.0.0":{"name":"p-locate","version":"2.0.0","description":"Get the first fulfilled promise that satisfies the provided testing function","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"dependencies":{"p-limit":"^1.1.0"},"devDependencies":{"ava":"*","delay":"^1.3.1","in-range":"^1.0.0","time-span":"^1.0.0","xo":"*"},"xo":{"esnext":true},"gitHead":"6300abb6451f04bbaa760f42844ec1c501d79120","bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","_id":"p-locate@2.0.0","_shasum":"20a0103b222a70c8fd39cc2e580680f3dde5ec43","_from":".","_npmVersion":"3.10.9","_nodeVersion":"7.2.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"20a0103b222a70c8fd39cc2e580680f3dde5ec43","size":2580,"noattachment":false,"tarball":"https://registry.npmmirror.com/p-locate/-/p-locate-2.0.0.tgz","integrity":"sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg=="},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/p-locate-2.0.0.tgz_1480310721089_0.044998719124123454"},"directories":{},"publish_time":1480310721460,"_hasShrinkwrap":false,"_cnpm_publish_time":1480310721460,"_cnpmcore_publish_time":"2021-12-13T11:52:01.755Z"},"1.0.0":{"name":"p-locate","version":"1.0.0","description":"Get the first fulfilled promise that satisfies the provided testing function","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"dependencies":{"p-map":"^1.1.0"},"devDependencies":{"ava":"*","delay":"^1.3.1","in-range":"^1.0.0","time-span":"^1.0.0","xo":"*"},"xo":{"esnext":true},"gitHead":"3950c4990ccb06fd7846255fa8570dda3efaa153","bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","_id":"p-locate@1.0.0","_shasum":"0741476fe43666849508fd0b125778982de716aa","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.6.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"0741476fe43666849508fd0b125778982de716aa","size":2303,"noattachment":false,"tarball":"https://registry.npmmirror.com/p-locate/-/p-locate-1.0.0.tgz","integrity":"sha512-9deoXAv41KrmBdrRoMb4JTiPu05u0VEGkqr6b/9pdLk2ryVRwYmJ42mgR1dpeqlmL6ifuZrSDMvAhBtJGC/dug=="},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/p-locate-1.0.0.tgz_1479636453993_0.39431346161291003"},"directories":{},"publish_time":1479636454210,"_hasShrinkwrap":false,"_cnpm_publish_time":1479636454210,"_cnpmcore_publish_time":"2021-12-13T11:52:02.109Z"},"7.0.0":{"name":"p-locate","version":"7.0.0","description":"Get the first fulfilled promise that satisfies the provided testing function","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"dependencies":{"p-limit":"^7.2.0"},"devDependencies":{"ava":"^6.4.1","delay":"^7.0.0","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.33.0","xo":"^1.2.3"},"gitHead":"b9ccdaaa83f8d2f53f8acf8ff3c97b7aa21f655b","types":"./index.d.ts","_id":"p-locate@7.0.0","bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","_nodeVersion":"25.3.0","_npmVersion":"11.7.0","dist":{"integrity":"sha512-FRPW2lT1b/B8/CNkCOZ/Xl4mz52CWzwb+/dLa0GcCrH7u7djFf36VftuRJ5w/eCr1YXtbTGPuGoEDVSk14EwNQ==","shasum":"424e50a4031542ee7ca1937c06f12b93dcf2f7b3","tarball":"https://registry.npmmirror.com/p-locate/-/p-locate-7.0.0.tgz","fileCount":5,"unpackedSize":8195,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCwTXfsOswVTrF/Qrw52HVV9I1kC4P1VPTW5d2ehmX2hQIhAP5EuK0nNHYZibljlDmWZkwBMgSSIDv1X4tL2YuOXISX"}],"size":3124},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/p-locate_7.0.0_1770105469769_0.22464266465257876"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-02-03T07:57:49.916Z","publish_time":1770105469916,"_source_registry_name":"default"}},"bugs":{"url":"https://github.com/sindresorhus/p-locate/issues"},"homepage":"https://github.com/sindresorhus/p-locate#readme","keywords":["promise","locate","find","finder","search","searcher","test","array","collection","iterable","iterator","race","fulfilled","fastest","async","await","promises","bluebird"],"repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-locate.git"},"_source_registry_name":"default"}