{"id":17143,"library":"amp-each","title":"Ampersand.js Each Utility","description":"amp-each is a lightweight JavaScript utility module, part of the ampersand.js project, designed to provide an iteration function similar to `Array.prototype.forEach` or `_.each` from Lodash. It allows iterating over both arrays and objects, applying a callback function to each element or property. The ampersand.js ecosystem, from which amp-each originates, was popular around 2015-2017 as a modular alternative to larger frameworks like Backbone.js, favoring CommonJS modules for client-side applications. However, the project appears to be largely unmaintained, with its core modules having last seen significant updates many years ago (e.g., ampersand-state last published 8 years ago from October 2017). This package, at version 1.0.1, should be considered abandoned, lacking recent updates, active development, or a clear release cadence. Its primary differentiator was being part of a \"non-frameworky\" collection of modules, offering granular control over application structure.","status":"abandoned","version":"1.0.1","language":"javascript","source_language":"en","source_url":"git://github.com/ampersandjs/amp","tags":["javascript","amp","util","collections"],"install":[{"cmd":"npm install amp-each","lang":"bash","label":"npm"},{"cmd":"yarn add amp-each","lang":"bash","label":"yarn"},{"cmd":"pnpm add amp-each","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module and does not natively support ES module import syntax. Use `require()` in Node.js or a bundler for browser usage.","wrong":"import each from 'amp-each';","symbol":"each","correct":"const each = require('amp-each');"}],"quickstart":{"code":"const each = require('amp-each');\n\n// Example 1: Iterating over an array\nconst numbers = [1, 2, 3, 4, 5];\nconst doubledNumbers = [];\n\neach(numbers, function (num, index) {\n  doubledNumbers.push(num * 2);\n  console.log(`Array item at index ${index}: ${num}`);\n});\nconsole.log('Doubled Numbers:', doubledNumbers);\n\n// Example 2: Iterating over an object\nconst user = {\n  name: 'Alice',\n  age: 30,\n  city: 'New York'\n};\n\nconsole.log('\\nUser details:');\neach(user, function (value, key) {\n  console.log(`${key}: ${value}`);\n});\n\n// Example 3: Using 'this' context (if the function supports it, which 'amp-each' typically would)\nconst contextObject = { multiplier: 10 };\nconst multipliedNumbers = [];\n\neach(numbers, function (num) {\n  multipliedNumbers.push(num * this.multiplier);\n}, contextObject);\nconsole.log('Multiplied by context:', multipliedNumbers);","lang":"javascript","description":"Demonstrates how to use `amp-each` to iterate over arrays and objects, applying a callback function to each element or property, and passing a context object."},"warnings":[{"fix":"Consider replacing with native JavaScript methods (e.g., `Array.prototype.forEach`, `Object.keys().forEach`) or a actively maintained utility library like Lodash (`_.each`).","message":"The entire ampersand.js project, including `amp-each`, appears to be abandoned. It has not seen updates in many years and lacks active maintenance, posing risks for security and compatibility with modern environments.","severity":"breaking","affected_versions":">=1.0.1"},{"fix":"Ensure you use `const each = require('amp-each');` for Node.js environments or configure your bundler (e.g., Webpack, Rollup) to handle CJS modules if targeting browsers.","message":"This package is exclusively a CommonJS (CJS) module. Attempting to use ES module `import` syntax will result in runtime errors in environments that don't specifically transpile CJS to ESM.","severity":"gotcha","affected_versions":">=1.0.1"},{"fix":"Prefer native JavaScript iteration methods for better maintainability, performance, and reduced bundle size.","message":"Modern JavaScript environments provide native iteration alternatives (e.g., `Array.prototype.forEach`, `Object.keys().forEach`, `for...of` loops) that offer similar functionality, often with better performance and native support, making this package largely redundant in current development.","severity":"gotcha","affected_versions":">=1.0.1"},{"fix":"If you must use this library, install `@types/amp-each` if available (unlikely due to abandonment) or create a custom declaration file (e.g., `amp-each.d.ts`) to provide type information.","message":"The package does not ship with TypeScript definitions. Using it in a TypeScript project will require manual type declarations or using `any`, leading to a loss of type safety.","severity":"gotcha","affected_versions":">=1.0.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change the file to a CommonJS module (e.g., rename to `.cjs`, remove `\"type\": \"module\"` from `package.json`, or configure your build system). Alternatively, use a dynamic import (`import('amp-each').then(mod => mod)`), though this package is not designed for it.","cause":"Attempting to use `require('amp-each')` in a JavaScript file that is being interpreted as an ES module (e.g., due to `\"type\": \"module\"` in `package.json` or a `.mjs` extension).","error":"ReferenceError: require is not defined"},{"fix":"If transpilation is in place, try `import * as each from 'amp-each';` and then use `each.default(collection, fn)`. However, the recommended fix is to revert to `const each = require('amp-each');`.","cause":"Incorrect ES module import (`import each from 'amp-each'`) for a CommonJS module that exports a single function directly (not as a default object property).","error":"TypeError: (0 , amp_each_1.default) is not a function"},{"fix":"Ensure the import is `const each = require('amp-each');` for CommonJS, or verify your bundler's configuration if using ES modules in a browser context.","cause":"The `amp-each` module was imported incorrectly, or the variable `each` was not assigned the exported function. This can happen with incorrect `require()` syntax or failed ES module imports.","error":"TypeError: each is not a function"}],"ecosystem":"npm","meta_description":null}