{"id":17152,"library":"amp-index-of","title":"amp-index-of Array Utility","description":"The `amp-index-of` package provides a lightweight utility function for arrays, serving as an `indexOf` implementation similar to `Array.prototype.indexOf`. It is a component of the Ampersand.js ecosystem, a modular, non-frameworky framework for client-side JavaScript applications, initially popular in the mid-2010s. The package is at version 1.1.0 and has not seen active development or releases for several years, aligning with the broader inactivity of the Ampersand.js project. Its original purpose was to offer a consistent array utility within the Ampersand.js environment. However, in modern JavaScript development, direct use of native `Array.prototype.indexOf` is preferred due to universal browser support and native performance. Therefore, `amp-index-of` is considered abandoned and primarily serves historical contexts or legacy applications built with Ampersand.js. Its release cadence was tied to the now-inactive Ampersand.js development cycle.","status":"abandoned","version":"1.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/ampersandjs/amp","tags":["javascript","amp","util","arrays"],"install":[{"cmd":"npm install amp-index-of","lang":"bash","label":"npm"},{"cmd":"yarn add amp-index-of","lang":"bash","label":"yarn"},{"cmd":"pnpm add amp-index-of","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not provide an ESM export. Attempting to use `import` syntax will result in a runtime error in ESM environments.","wrong":"import { indexOf } from 'amp-index-of';","symbol":"indexOf","correct":"const indexOf = require('amp-index-of');"},{"note":"Only the default CommonJS export is available. Named or namespace imports are not supported.","wrong":"import * as indexOf from 'amp-index-of';","symbol":"* as indexOf","correct":"const indexOf = require('amp-index-of');"}],"quickstart":{"code":"const indexOf = require('amp-index-of');\n\nconst myArray = ['apple', 'banana', 'orange', 'grape', 'banana'];\n\n// Find the first occurrence of 'banana'\nconst firstIndex = indexOf(myArray, 'banana');\nconsole.log(`First 'banana' found at index: ${firstIndex}`); // Expected: 1\n\n// Find an element that does not exist\nconst notFoundIndex = indexOf(myArray, 'kiwi');\nconsole.log(`'kiwi' found at index: ${notFoundIndex}`); // Expected: -1\n\n// Demonstrating behavior similar to Array.prototype.indexOf\nconst anotherArray = [10, 20, 30, 10, 40];\nconsole.log(`Native indexOf of 10: ${anotherArray.indexOf(10)}`); // Expected: 0\nconsole.log(`amp-index-of of 10: ${indexOf(anotherArray, 10)}`); // Expected: 0","lang":"javascript","description":"Demonstrates how to import and use the `amp-index-of` function to find the index of an element in an array using CommonJS syntax."},"warnings":[{"fix":"Replace `require('amp-index-of')(arr, val)` with `arr.indexOf(val)` in modern JavaScript environments.","message":"This package is part of the deprecated Ampersand.js ecosystem and is no longer actively maintained. No further updates, bug fixes, or security patches are expected. Consider migrating to native `Array.prototype.indexOf`.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Ensure you are using CommonJS `require()` syntax for importing this package, or transpile your code if working in an ESM-first project.","message":"The package is CommonJS-only. Using ES Module `import` syntax directly will cause a runtime error (`require is not defined` or similar) in environments configured for ESM.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer `Array.prototype.indexOf()` directly, e.g., `myArray.indexOf('element')`.","message":"This package provides identical functionality to the native `Array.prototype.indexOf` method, which is universally supported in modern browsers and Node.js. Using the native method avoids an unnecessary dependency.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"If running in an ESM environment (e.g., Node.js with `\"type\": \"module\"` in package.json), you may need to use a CommonJS wrapper or switch to native `Array.prototype.indexOf`.","cause":"Attempting to use `require()` in an ES Module context without proper transpilation or configuration.","error":"ReferenceError: require is not defined"},{"fix":"Ensure you are using `const indexOf = require('amp-index-of');` and then calling `indexOf(myArray, item)`.","cause":"Incorrect import of the `amp-index-of` function, or the module being used incorrectly after import.","error":"TypeError: indexOf is not a function"}],"ecosystem":"npm","meta_description":null}