{"id":10568,"library":"bbox-fns","title":"Bounding Box Utility Functions","description":"bbox-fns is a lightweight JavaScript library offering a collection of modular utility functions for common geospatial bounding box operations. Bounding boxes are consistently represented as a four-element array: `[xmin, ymin, xmax, ymax]`. Currently at version 0.20.2, the library maintains a relatively frequent release cadence, often introducing new functions or minor fixes, with updates typically occurring every few weeks or months. Its key differentiator lies in its 'super light-weight' design and modular structure, where most functions reside in their own file. This approach facilitates granular imports, allowing developers to include only the specific utilities needed, thereby contributing to smaller bundle sizes. It focuses exclusively on core bounding box manipulations rather than broader GIS features.","status":"active","version":"0.20.2","language":"javascript","source_language":"en","source_url":"https://github.com/DanielJDufour/bbox-fns","tags":["javascript","bbox","geospatial","gis"],"install":[{"cmd":"npm install bbox-fns","lang":"bash","label":"npm"},{"cmd":"yarn add bbox-fns","lang":"bash","label":"yarn"},{"cmd":"pnpm add bbox-fns","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses ES Modules with explicit file paths. Attempting to use CommonJS `require` or named imports from the root package for individual functions will lead to errors.","wrong":"const bboxArea = require('bbox-fns/bbox-area');","symbol":"bboxArea","correct":"import bboxArea from 'bbox-fns/bbox-area.js';"},{"note":"Each utility is a default export from its specific file. Destructuring from the main package import is not supported.","wrong":"import { bboxArray } from 'bbox-fns'; // Incorrect named import for file-based modules","symbol":"bboxArray","correct":"import bboxArray from 'bbox-fns/bbox-array.js';"},{"note":"Ensure you include the `.js` extension in import paths when using ESM in environments like Node.js where it's not always implicitly handled.","wrong":"const { booleanContains } = require('bbox-fns');","symbol":"booleanContains","correct":"import booleanContains from 'bbox-fns/boolean-contains.js';"}],"quickstart":{"code":"import bboxArray from 'bbox-fns/bbox-array.js';\nimport bboxArea from 'bbox-fns/bbox-area.js';\nimport booleanIntersects from 'bbox-fns/boolean-intersects.js';\n\n// Define a set of points for a polygon ring\nconst points = [\n  [-180, 86.06126914660831],\n  [-180, 85.66739606126914],\n  [NaN, 84.87964989059081], // Point with NaN value\n  [-179, 84.48577680525165]\n];\n\n// Calculate the bounding box, skipping NaN values\nconst calculatedBbox = bboxArray(points, { nan_strategy: 'skip' });\nconsole.log('Calculated Bounding Box (skipping NaN):', calculatedBbox);\n\n// Calculate the area of the bounding box\nconst area = bboxArea(calculatedBbox);\nconsole.log('Area of the bounding box:', area);\n\n// Define another bounding box\nconst referenceBbox = [-10, -20, 10, 20];\n\n// Check if the calculated bbox intersects with the reference bbox\nconst intersects = booleanIntersects(calculatedBbox, referenceBbox);\nconsole.log('Does the calculated bbox intersect with reference bbox?', intersects);","lang":"javascript","description":"Demonstrates calculating a bounding box from an array of points, handling NaN values, then calculating its area, and finally checking for intersection with another bounding box."},"warnings":[{"fix":"For `bboxArray` and `reproject` functions, explicitly specify `{ nan_strategy: 'skip' }` in the options to ignore `NaN` values or implement pre-filtering of points to remove `NaN`s if strict error handling is desired.","message":"Prior to `v0.20.0`, functions like `bboxArray` would throw an error if any input points contained `NaN` values. The introduction of the `nan_strategy` option in `v0.20.0` (and `v0.20.2` fixing a related bug) changes this behavior, allowing developers to explicitly 'skip' or 'error' on `NaN`s. Existing code that relied on implicit error-throwing for `NaN` inputs might now behave differently if `nan_strategy: 'skip'` is applied.","severity":"breaking","affected_versions":"<0.20.0"},{"fix":"Always use `import` statements with the full path including the `.js` extension (e.g., `import functionName from 'bbox-fns/function-name.js';`). If running in Node.js, ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json` or using `.mjs` files).","message":"This library is distributed as ES Modules (ESM) and its examples consistently use `import` statements with explicit `.js` file extensions. Attempting to use CommonJS `require()` syntax will result in errors in Node.js environments that treat the package as ESM.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Refactor your import statements to use ESM syntax, such as `import functionName from 'bbox-fns/function-name.js';`. Ensure your project's `package.json` correctly sets `\"type\": \"module\"` if you intend to use ESM throughout, or use `.mjs` file extensions for ESM files.","cause":"Attempting to use CommonJS `require()` in an environment or module context configured for ES Modules (ESM). The `bbox-fns` library is primarily distributed as ESM.","error":"TypeError: require is not a function"},{"fix":"Upgrade to `bbox-fns v0.20.0` or higher and provide the `nan_strategy` option: `bboxArray(points, { nan_strategy: 'skip' })` to filter out `NaN` values, or `bboxArray(points, { nan_strategy: 'error' })` to explicitly control the error behavior. Alternatively, pre-filter your input points to remove `NaN` values.","cause":"Input array of points to functions like `bboxArray` contained `NaN` (Not-a-Number) values, and the function was called without a `nan_strategy` option. Before `v0.20.0`, this would always throw an error.","error":"Error: Points must not contain NaN values (thrown by bboxArray before v0.20.0)"}],"ecosystem":"npm"}