{"id":10656,"library":"component-each","title":"Component Each Iteration Utility","description":"The `component-each` package provides a highly generalized utility function for iterating over arrays, objects, and strings. It was developed as part of the 'Component' project, an early modularity solution for JavaScript that predates modern package managers like npm for front-end assets. This library allows a single `each` function to handle different data types by inspecting their structure, making it a flexible but less performant alternative to native `forEach` or `for...in` loops. Its current stable version is 0.2.6, and it has not seen updates since 2013, indicating it is no longer actively maintained. Its primary differentiator was its role within the now largely superseded 'Component' ecosystem, rather than its unique iteration features which are now standard or handled more efficiently by native JavaScript or modern utility libraries like Lodash.","status":"abandoned","version":"0.2.6","language":"javascript","source_language":"en","source_url":"https://github.com/component/each","tags":["javascript"],"install":[{"cmd":"npm install component-each","lang":"bash","label":"npm"},{"cmd":"yarn add component-each","lang":"bash","label":"yarn"},{"cmd":"pnpm add component-each","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and was designed for the 'Component' build tool ecosystem, not modern ESM environments. It does not ship with TypeScript definitions.","wrong":"import each from 'component-each';","symbol":"each","correct":"const each = require('component-each');"},{"note":"The default export is the `each` function. There are no named exports.","wrong":"import { each } from 'component-each';","symbol":"each","correct":"const each = require('component-each');\n// Usage:\neach([1, 2, 3], (num, i) => console.log(num, i));"}],"quickstart":{"code":"const each = require('component-each');\n\nconsole.log('--- Iterating an array ---');\neach([1, 2, 3], (num, i) => {\n  console.log(`Array item at index ${i}: ${num}`);\n});\n\nconst config = {\n  name: 'example',\n  version: '1.0.0',\n  env: 'development'\n};\nconsole.log('\\n--- Iterating an object ---');\neach(config, (key, value) => {\n  console.log(`Object property '${key}': ${value}`);\n});\n\nconsole.log('\\n--- Iterating a string ---');\neach('hello', (char, i) => {\n  console.log(`String character at index ${i}: '${char}'`);\n});","lang":"javascript","description":"Demonstrates the universal `each` function iterating over arrays, objects, and strings with a callback."},"warnings":[{"fix":"Consider using native array methods (`forEach`, `for...of`), `Object.keys().forEach()`, or a modern utility library (e.g., Lodash's `_.forEach`) for iteration. If absolutely necessary, you may need to use a CommonJS transpiler or bundler.","message":"This package is part of the 'Component' project ecosystem, which has been largely superseded by modern Node.js module systems (CommonJS/ESM) and build tools (npm, webpack, Rollup). It is not directly compatible with standard npm workflows without specific configuration or polyfills.","severity":"breaking","affected_versions":"all"},{"fix":"Avoid using this package in new projects. For existing projects, consider migrating to maintained alternatives to prevent potential security vulnerabilities or compatibility issues.","message":"The package is unmaintained since 2013. There will be no bug fixes, security updates, or new features. It may not work correctly with newer JavaScript runtimes or language features.","severity":"gotcha","affected_versions":"all"},{"fix":"Prefer native JavaScript iteration methods when possible for better performance and readability.","message":"Performance of this generic `each` function may be lower than native iteration methods (e.g., `Array.prototype.forEach`, `for...of` loops, `Object.keys().forEach()`), especially for large collections, due to its internal type checking and abstraction layer.","severity":"gotcha","affected_versions":"all"},{"fix":"If using TypeScript, implement custom iteration logic or use a modern utility library that provides built-in TypeScript support.","message":"This library does not provide TypeScript declarations and is not designed for TypeScript environments. Using it in a TypeScript project will require manual type declarations or `@ts-ignore` directives.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `component-each` is properly installed and bundled by your build system. For modern projects, it's strongly recommended to replace it with native iteration or a modern utility library.","cause":"The package was designed for the 'Component' build tool, not direct npm installation or standard Node.js module resolution without a bundler.","error":"Error: Cannot find module 'component-each'"},{"fix":"Change your import statement to `const each = require('component-each');`.","cause":"Attempting to import `each` using ESM `import` syntax (`import each from 'component-each'`) instead of CommonJS `require`.","error":"TypeError: each is not a function"}],"ecosystem":"npm"}