{"id":13184,"library":"first-match","title":"first-match: Array Element Finder","description":"The `first-match` package provides a utility function to find the first element in an array that satisfies a given callback test. If no iterator is provided, it returns the first truthy value encountered in the array. This functionality is directly equivalent to what was historically offered by `underscore.find()` and is now standard in modern JavaScript environments via `Array.prototype.find()`. The package is at version 0.0.1, indicating an early development stage, and has effectively been abandoned given the ubiquitous availability of native array methods and the lack of updates over a significant period. Its primary differentiating factor might have been its minimal footprint before native alternatives were widely adopted, but it offers no unique advantages over current standard practices. Its release cadence is effectively zero.","status":"abandoned","version":"0.0.1","language":"javascript","source_language":"en","source_url":"git://github.com/hughsk/first-match","tags":["javascript","element","array","first","truth","test","find"],"install":[{"cmd":"npm install first-match","lang":"bash","label":"npm"},{"cmd":"yarn add first-match","lang":"bash","label":"yarn"},{"cmd":"pnpm add first-match","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. Direct ESM imports like 'import { first }' will not work and cause a runtime error. It might be possible to use dynamic import() or a CJS bridge, but it's generally not recommended for this package.","wrong":"import { first } from 'first-match'","symbol":"first","correct":"const first = require('first-match')"}],"quickstart":{"code":"const first = require('first-match');\n\nconst numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\n\nconsole.log('Finding first truthy value (no iterator):');\nconst firstTruthy = first(numbers);\nconsole.log(`Result: ${firstTruthy} (expected 1)`);\n\nconsole.log('\\nFinding first number greater than 5:');\nconst greaterThanFive = first(numbers, (n) => n > 5);\nconsole.log(`Result: ${greaterThanFive} (expected 6)`);\n\nconsole.log('\\nFinding first odd number:');\nconst firstOdd = first(numbers, (n) => n % 2 !== 0);\nconsole.log(`Result: ${firstOdd} (expected 1)`);\n\nconsole.log('\\nFinding first number where n + 2 > array length (using context):');\nconst contextExample = first(numbers, function(n) {\n  return n + 2 > this.length;\n});\nconsole.log(`Result: ${contextExample} (expected 8)`);\n\n// Demonstrating the equivalence to Array.prototype.find\nconst nativeFindResult = numbers.find((n) => n > 5);\nconsole.log(`\\nNative Array.prototype.find for > 5: ${nativeFindResult} (same as first-match)`);\n","lang":"javascript","description":"Demonstrates `first-match` finding the first truthy value, numbers matching a condition, and utilizing the optional `context` parameter for the iterator function, while also comparing it to modern `Array.prototype.find`."},"warnings":[{"fix":"Replace calls to `first(array, iterator)` with `array.find(iterator)`. For example, `first([1,2,3], n => n > 1)` becomes `[1,2,3].find(n => n > 1)`.","message":"The functionality provided by `first-match` is directly superseded by `Array.prototype.find()` which is natively available in all modern JavaScript environments (ES6+). Using native methods is generally more performant, better maintained, and requires no external dependencies.","severity":"deprecated","affected_versions":">=0.0.1"},{"fix":"If you absolutely must use this package in an ESM context, consider dynamic import (`import('first-match').then(module => module(...))`) or a CommonJS wrapper if using Node.js, but prefer native `Array.prototype.find()` instead.","message":"This package is CommonJS-only. Attempting to use `import { first } from 'first-match'` in an ESM module will result in a runtime error because it does not provide an ESM export.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Migrate to `Array.prototype.find()` or a well-maintained utility library like Lodash's `_.find()`.","message":"The package is at version 0.0.1 and has seen no updates, indicating it is unmaintained and potentially abandoned. Relying on unmaintained packages can introduce security vulnerabilities or compatibility issues over time.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using `const first = require('first-match')` in a CommonJS environment. If in an ESM environment, use `Array.prototype.find()` instead.","cause":"Attempting to use `import { first } from 'first-match'` in an ESM module context, or incorrect `require` usage.","error":"TypeError: first is not a function"},{"fix":"Add `const first = require('first-match');` at the top of your CommonJS file where `first` is used. For ESM, refer to `warnings` and switch to `Array.prototype.find()`.","cause":"The `first` variable was not properly assigned or the module was not correctly required/imported before use.","error":"ReferenceError: first is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}