{"id":15013,"library":"utils-flatten","title":"Array Flatten Utility","description":"The `utils-flatten` package provides a single, straightforward utility function for recursively flattening arrays in JavaScript. It is a minimal, focused library for transforming deeply nested arrays into a single-level array. The package is currently at version 1.0.0 and appears to be an unmaintained or abandoned project, with its last known activity dating back to around 2013, as indicated by the copyright and build status badge. Its primary differentiation, if any, lies in its extreme simplicity and small footprint, predating the widespread adoption of native `Array.prototype.flat()` in modern JavaScript environments (ES2019+). Developers should be aware that contemporary JavaScript offers built-in alternatives, making this package largely redundant for new projects.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/jaredhanson/utils-flatten","tags":["javascript","util","array"],"install":[{"cmd":"npm install utils-flatten","lang":"bash","label":"npm"},{"cmd":"yarn add utils-flatten","lang":"bash","label":"yarn"},{"cmd":"pnpm add utils-flatten","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module. Direct ESM imports like `import ... from 'utils-flatten'` will not work without a bundler that handles CJS interoperability. The default export is the `flatten` function.","wrong":"import flatten from 'utils-flatten';\nimport { flatten } from 'utils-flatten';","symbol":"flatten","correct":"const flatten = require('utils-flatten');"}],"quickstart":{"code":"const flatten = require('utils-flatten');\n\nconst nestedArray = ['one', ['two', ['three', 'four'], 'five'], 6, [7, [8]]];\n\nconst flattenedArray = flatten(nestedArray);\n\nconsole.log('Original array:', nestedArray);\nconsole.log('Flattened array:', flattenedArray);\n// Expected output: ['one', 'two', 'three', 'four', 'five', 6, 7, 8]\n\nconst anotherNestedArray = [1, [2, [3, 4], 5], [6, [7, [8, 9]]]];\nconst fullyFlattened = flatten(anotherNestedArray);\nconsole.log('Another original array:', anotherNestedArray);\nconsole.log('Fully flattened array:', fullyFlattened);","lang":"javascript","description":"Demonstrates how to import the `flatten` function using CommonJS and use it to flatten a deeply nested array."},"warnings":[{"fix":"Migrate to `Array.prototype.flat()` for native array flattening. For example, `arr.flat(Infinity)` can fully flatten an array.","message":"The `utils-flatten` package is effectively deprecated by native JavaScript features. Modern environments (ES2019+ / Node.js 11+) include `Array.prototype.flat()` and `Array.prototype.flatMap()` which provide equivalent or superior functionality directly in the language, negating the need for this external dependency.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"For ESM projects, consider using native `Array.prototype.flat()` or a modern utility library with ESM support. If you must use this package in ESM, a bundler like Webpack or Rollup can typically handle the `require` call.","message":"This package is a CommonJS module and does not natively support ES Modules (ESM) syntax. Attempting to use `import flatten from 'utils-flatten'` directly in an ESM environment will result in errors unless a bundler is configured to handle CJS interoperability.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"It is strongly recommended to replace `utils-flatten` with `Array.prototype.flat()` or a actively maintained modern utility library (e.g., Lodash, Ramda) that offers similar functionality and ongoing support.","message":"The package is unmaintained, with its last known update around 2013 (version 1.0.0). This means it will not receive bug fixes, performance improvements, or security patches. Using unmaintained dependencies can introduce vulnerabilities or compatibility issues with newer Node.js versions or language features.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using CommonJS `const flatten = require('utils-flatten');` in a CJS environment. For ESM, use `Array.prototype.flat()` instead.","cause":"Attempting to use `flatten` without properly importing or requiring it, or using an incorrect import style (e.g., in a modern ESM context without transpilation).","error":"ReferenceError: flatten is not defined"},{"fix":"Revert to CommonJS `const flatten = require('utils-flatten');` or, preferably, migrate to `Array.prototype.flat()`.","cause":"This error often occurs when a bundler (like Webpack or Rollup) tries to interpret a CommonJS module's default export when an ESM default import (`import flatten from 'utils-flatten'`) is used, but the CJS module's export structure doesn't align with what the bundler expects for a 'default' export.","error":"TypeError: (0 , _utilsFlatten.default) is not a function"}],"ecosystem":"npm"}