Ejemplo
es-toolkit 1.50.0: compat/findIndex resolves Lodash-compatible iteratees including property paths, key-value pairs, partial objects, and truthy identity fallback, while supporting negative and floating fromIndex offsets.
Muestra verificada para npm es-toolkit 1.50.0: compat/findIndex resolves Lodash-compatible iteratees including property paths, key-value pairs, partial…
sha256:4945803ae6fe38e25a5bd24b720662416f887c0a168c957a711ad9c2c3d187b8
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 2
- Claves de firma que lo compilaron
- 2
Entorno declarado
node linux x64 node node npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-17 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
Caso
HOW- Objetivo
- compat/findIndex resolves Lodash-compatible iteratees including property paths, key-value pairs, partial objects, and truthy identity fallback, while supporting negative and floating fromIndex offsets.
- Paquetes
- Símbolos
-
- compat/findIndex
- Entorno
- node
- Creado
- 2026-08-17T23:42:55Z
Contrato
- findIndex matches elements using property path strings, key-value pairs, or partial objects, applies fromIndex offsets, and returns -1 for unfound items or nil collections.
- export identity matches between es-toolkit/compat named export and es-toolkit/compat/findIndex default export
- property name strings match the first item with a truthy value at the specified property or nested path
- two-element arrays match items where the property key equals the expected value
- plain objects perform deep partial matching against collection items
- omitting the predicate defaults to identity matching the first truthy element
- fromIndex offsets start searching from the given index, truncating floats and interpreting negative values from the array end
- null and undefined collections safely return -1 without throwing errors
- array-like objects and strings are converted and searched identically to arrays
Archivos
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
Código fuente
# es-toolkit compat/findIndex
## Known Solution Search
`search_known_solution` returned `NO_SAFE_MATCH` for `pkg:npm/es-toolkit@1.50.0` with symbol `compat/findIndex`.
## Pinned Release
- Package: `es-toolkit`
- Version: `1.50.0` (pinned in `package.json` and `package-lock.json`)
## Observed Behaviour
`compat/findIndex` provides a Lodash-compatible implementation of `findIndex` with full support for iteratee shorthands and index offsets:
1. **Module Exports**:
- Named export: `import { findIndex } from 'es-toolkit/compat'`
- Subpath default export: `import findIndex from 'es-toolkit/compat/findIndex'`
- Both export formats reference the same underlying function.
2. **Iteratee Shorthands**:
- **Property name string**: `findIndex(items, 'prop')` checks truthiness of property `prop` or nested dot-paths such as `'details.role'`.
- **Key-Value tuple**: `findIndex(items, ['prop', value])` performs equality comparison using `matchesProperty`.
- **Object pattern**: `findIndex(items, { key: value })` performs deep partial matching using `matches`.
- **Custom predicate**: `findIndex(items, (item) => ...)` executes the given boolean callback.
- **Default fallback**: When omitted, the iteratee defaults to `identity`, returning the index of the first truthy element.
3. **`fromIndex` Handling**:
- Accepts positive start indices, returning `-1` if `fromIndex >= length`.
- Truncates non-integer numeric offsets via `toInteger` (e.g., `1.9` becomes `1`).
- Negative numbers calculate the start index from the array end: `Math.max(length + fromIndex, 0)`.
4. **Nil Safety and Array-like Collections**:
- `findIndex(null, ...)` and `findIndex(undefined, ...)` safely return `-1` without throwing.
- Array-like collections (such as strings and custom `{ length, ... }` objects) are supported via `Array.from`.
{"case":{"caseId":"case:sha256:3ccfdf990eb5b0ca064d263b73fcc397403e001b365e38ea47511330d8b0538e","contract":["findIndex matches elements using property path strings, key-value pairs, or partial objects, applies fromIndex offsets, and returns -1 for unfound items or nil collections.","export identity matches between es-toolkit/compat named export and es-toolkit/compat/findIndex default export","property name strings match the first item with a truthy value at the specified property or nested path","two-element arrays match items where the property key equals the expected value","plain objects perform deep partial matching against collection items","omitting the predicate defaults to identity matching the first truthy element","fromIndex offsets start searching from the given index, truncating floats and interpreting negative values from the array end","null and undefined collections safely return -1 without throwing errors","array-like objects and strings are converted and searched identically to arrays"],"goal":"compat/findIndex resolves Lodash-compatible iteratees including property paths, key-value pairs, partial objects, and truthy identity fallback, while supporting negative and floating fromIndex offsets.","kind":"HOW","packages":["pkg:npm/es-toolkit@1.50.0"],"schemaVersion":1,"symbols":["compat/findIndex"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/es-toolkit@1.50.0"],"schemaVersion":1,"symbols":["compat/findIndex"],"verifierAdapter":"node-typescript@1"}
{
"name": "npm-es-toolkit-compat-findindex-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-es-toolkit-compat-findindex-sample",
"version": "1.0.0",
"dependencies": {
"es-toolkit": "1.50.0"
}
},
"node_modules/es-toolkit": {
"version": "1.50.0",
"resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.50.0.tgz",
"integrity": "sha512-OyZKhUVvEep9ITEiwHn8GKnMRQIVqoSIX7WnRbkWgJkllCujilqP2rD0u979tkl8wqyc8ICwlc1UBVv/Sl1G6w==",
"license": "MIT",
"workspaces": [
"docs",
"benchmarks",
"tests/types"
]
}
}
}
{
"name": "npm-es-toolkit-compat-findindex-sample",
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"es-toolkit": "1.50.0"
}
}
import assert from 'node:assert/strict';
import { findIndex } from 'es-toolkit/compat';
import findIndexDefault from 'es-toolkit/compat/findIndex';
// 1. Export identity across compat entrypoints
assert.strictEqual(findIndex, findIndexDefault, 'default export from compat/findIndex matches named export from compat');
const users = [
{ user: 'barney', age: 36, active: false, details: { role: 'dev' } },
{ user: 'fred', age: 40, active: true, details: { role: 'lead' } },
{ user: 'pebbles', age: 1, active: true, details: { role: 'intern' } },
];
// 2. Iteratee shorthand: property name string (checks truthiness of property)
assert.strictEqual(findIndex(users, 'active'), 1, 'matches first element where property is truthy');
assert.strictEqual(findIndex(users, 'details.role'), 0, 'supports nested property path string');
// 3. Iteratee shorthand: [key, value] tuple (matchesProperty)
assert.strictEqual(findIndex(users, ['active', false]), 0, 'matches property equality using [key, value] pair');
assert.strictEqual(findIndex(users, ['details.role', 'intern']), 2, 'matches nested property equality');
// 4. Iteratee shorthand: partial match object (matches)
assert.strictEqual(findIndex(users, { age: 40, active: true }), 1, 'matches partial object attributes');
assert.strictEqual(findIndex(users, { details: { role: 'intern' } }), 2, 'matches nested object attributes');
// 5. Predicate function
assert.strictEqual(findIndex(users, (u) => u.age < 10), 2, 'finds index matching custom predicate');
// 6. Default predicate (identity)
assert.strictEqual(findIndex([0, false, null, undefined, '', NaN, 'found', 42]), 6, 'defaults to identity matching first truthy item');
// 7. fromIndex handling
const list = ['a', 'b', 'c', 'b', 'a'];
assert.strictEqual(findIndex(list, (x) => x === 'b', 2), 3, 'starts search at fromIndex offset');
assert.strictEqual(findIndex(list, (x) => x === 'a', -2), 4, 'negative fromIndex computes offset from end');
assert.strictEqual(findIndex(list, (x) => x === 'a', -100), 0, 'negative fromIndex exceeding length clamps to 0');
assert.strictEqual(findIndex(list, (x) => x === 'a', 10), -1, 'fromIndex beyond array length returns -1');
assert.strictEqual(findIndex(list, (x) => x === 'c', 1.9), 2, 'floating fromIndex is truncated to integer');
// 8. Nil collection & not found safety
assert.strictEqual(findIndex(null, 'active'), -1, 'null collection returns -1');
assert.strictEqual(findIndex(undefined, 'active'), -1, 'undefined collection returns -1');
assert.strictEqual(findIndex(list, (x) => x === 'z'), -1, 'unmatched search returns -1');
// 9. Array-like collections
assert.strictEqual(findIndex('abcdef', (c) => c === 'd'), 3, 'searches string array-like');
assert.strictEqual(findIndex({ length: 3, 0: 'x', 1: 'y', 2: 'z' }, (v) => v === 'z'), 2, 'searches custom array-like object');