{"id":16399,"library":"is-redirect","title":"HTTP Redirect Status Code Checker","description":"is-redirect is a lightweight, focused utility package for JavaScript and TypeScript environments that efficiently determines if a given numeric HTTP status code falls within the 3xx redirection range. The current stable version is 2.0.0. As part of Sindre Sorhus's collection of focused utilities, it follows a pragmatic release cadence, with major versions typically signaling significant breaking changes, such as the recent transition to pure ESM. Its primary differentiator is its singular focus and minimal footprint, providing a reliable, dependency-free check for redirect status codes without including additional HTTP client or server logic. It serves as a fundamental building block for applications that need to interpret HTTP responses, such as proxies, web scrapers, or API clients, ensuring correct handling of redirect flows.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/sindresorhus/is-redirect","tags":["javascript","redirect","http","https","status","code","codes","is","check"],"install":[{"cmd":"npm install is-redirect","lang":"bash","label":"npm"},{"cmd":"yarn add is-redirect","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-redirect","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is pure ESM since v2.0.0; CommonJS `require` is no longer supported and will result in an `ERR_REQUIRE_ESM` error. Ensure your project is configured for ESM.","wrong":"const isRedirect = require('is-redirect');","symbol":"isRedirect","correct":"import isRedirect from 'is-redirect';"},{"note":"When dynamically importing, the default export is nested under a `default` property. Destructure correctly or access `importedModule.default`.","wrong":"const isRedirect = await import('is-redirect');","symbol":"isRedirect (dynamic import)","correct":"const { default: isRedirect } = await import('is-redirect');"},{"note":"TypeScript users can import the type definition for the function if needed for advanced type-checking scenarios, though it's typically inferred.","symbol":"type IsRedirect","correct":"import type { IsRedirect } from 'is-redirect';"}],"quickstart":{"code":"import isRedirect from 'is-redirect';\n\nfunction categorizeStatusCode(statusCode) {\n  if (isRedirect(statusCode)) {\n    console.log(`Status ${statusCode}: This is a redirect code.`);\n    return 'redirect';\n  } else if (statusCode >= 200 && statusCode < 300) {\n    console.log(`Status ${statusCode}: This is a success code.`);\n    return 'success';\n  } else if (statusCode >= 400 && statusCode < 500) {\n    console.log(`Status ${statusCode}: This is a client error code.`);\n    return 'client-error';\n  } else if (statusCode >= 500 && statusCode < 600) {\n    console.log(`Status ${statusCode}: This is a server error code.`);\n    return 'server-error';\n  } else {\n    console.log(`Status ${statusCode}: Uncategorized.`);\n    return 'other';\n  }\n}\n\nconsole.log('\\n--- Testing various HTTP status codes ---');\ncategorizeStatusCode(301); // Moved Permanently\ncategorizeStatusCode(302); // Found\ncategorizeStatusCode(307); // Temporary Redirect\ncategorizeStatusCode(200); // OK\ncategorizeStatusCode(404); // Not Found\ncategorizeStatusCode(500); // Internal Server Error\ncategorizeStatusCode(100); // Continue\n","lang":"javascript","description":"Demonstrates how to use `is-redirect` to categorize different HTTP status codes, highlighting its primary function within a broader status checking logic."},"warnings":[{"fix":"Migrate your project to use ESM imports (`import isRedirect from 'is-redirect';`) or ensure your consuming module is also ESM. For Node.js, this often involves setting `\"type\": \"module\"` in your `package.json` or using `.mjs` file extensions.","message":"The package `is-redirect` is now pure ESM (ECMAScript Modules) starting from version 2.0.0. This means it can no longer be imported using CommonJS `require()` syntax.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your Node.js environment to version 12 or newer. If you must support older Node.js versions, you will need to stick to `is-redirect@1.x`.","message":"Version 2.0.0 and above of `is-redirect` requires Node.js version 12 or higher. Older Node.js versions will not be able to run this package.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"For comprehensive HTTP status code handling beyond 3xx redirects, integrate `is-redirect` with other status code checking utilities or custom logic for different HTTP ranges (e.g., `is-success`, `is-server-error`).","message":"The package only checks for 3xx status codes commonly associated with redirects. It does not handle edge cases like `101 Switching Protocols` or `204 No Content` which might imply a redirect-like behavior in specific application contexts but are not strictly 3xx redirects.","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":"Change your import statement to `import isRedirect from 'is-redirect';` and ensure your file/project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json`).","cause":"Attempting to import `is-redirect` (v2.0.0+) using `require()` in a CommonJS module.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/is-redirect/index.js from ... not supported."},{"fix":"Either rename your file to `.mjs` or add `\"type\": \"module\"` to your project's `package.json` to enable ESM for `.js` files. Alternatively, if your project needs to remain CommonJS, downgrade `is-redirect` to version 1.x.","cause":"Using an `import` statement for `is-redirect` (v2.0.0+) in a JavaScript file that is being interpreted as a CommonJS module (e.g., a `.js` file without `\"type\": \"module\"` in `package.json` and not an `.mjs` file).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}