Registry / serialization / first-match

first-match

JSON →
library0.0.1jsnpmunverified

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.

npm install first-match
INSTALL
IMPORT
SIG · FIRST-MATCH
F
first-match
serializationjavascriptv0.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

first
const first = require('first-match')
import { first } from 'first-match'
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.

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`.

const first = require('first-match'); const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; console.log('Finding first truthy value (no iterator):'); const firstTruthy = first(numbers); console.log(`Result: ${firstTruthy} (expected 1)`); console.log('\nFinding first number greater than 5:'); const greaterThanFive = first(numbers, (n) => n > 5); console.log(`Result: ${greaterThanFive} (expected 6)`); console.log('\nFinding first odd number:'); const firstOdd = first(numbers, (n) => n % 2 !== 0); console.log(`Result: ${firstOdd} (expected 1)`); console.log('\nFinding first number where n + 2 > array length (using context):'); const contextExample = first(numbers, function(n) { return n + 2 > this.length; }); console.log(`Result: ${contextExample} (expected 8)`); // Demonstrating the equivalence to Array.prototype.find const nativeFindResult = numbers.find((n) => n > 5); console.log(`\nNative Array.prototype.find for > 5: ${nativeFindResult} (same as first-match)`);
Debug
Known issues
deprecatedThe 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.
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)`.
affects: >=0.0.1
gotchaThis 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.
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.
affects: >=0.0.1
gotchaThe 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.
fix
Migrate to `Array.prototype.find()` or a well-maintained utility library like Lodash's `_.find()`.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: first is not a function
Attempting to use `import { first } from 'first-match'` in an ESM module context, or incorrect `require` usage.
fix
Ensure you are using `const first = require('first-match')` in a CommonJS environment. If in an ESM environment, use `Array.prototype.find()` instead.
ReferenceError: first is not defined
The `first` variable was not properly assigned or the module was not correctly required/imported before use.
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()`.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
first-match — npm install first-match · libregistry