{"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,"search_vec":"'2.0.0':41 '3xx':33 'addit':97 'api':124 'applic':111 'block':109 'break':64 'build':108 'cadenc':57 'chang':65 'check':90,140 'checker':5 'client':99,125 'code':4,29,94,137,138 'collect':48 'correct':127 'current':37 'depend':88 'dependency-fre':87 'determin':22 'differenti':76 'effici':21 'ensur':126 'environ':19 'esm':73 'fall':30 'flow':131 'focus':12,50,80 'follow':53 'footprint':83 'free':89 'fundament':107 'given':25 'handl':128 'http':1,27,98,116,134 'https':135 'includ':96 'interpret':115 'is-redirect':6 'javascript':16,132 'lightweight':11 'logic':102 'major':59 'minim':82 'need':113 'numer':26 'packag':14 'part':43 'pragmat':55 'primari':75 'provid':84 'proxi':120 'pure':72 'rang':35 'recent':69 'redirect':2,8,34,92,130,133 'releas':56 'reliabl':86 'respons':117 'scraper':122 'serv':104 'server':101 'signal':62 'signific':63 'sindr':45 'singular':79 'sorhus':46 'stabl':38 'status':3,28,93,136 'transit':70 'typescript':18 'typic':61 'util':13,51 'version':39,60 'web':121 'within':31 'without':95","created_at":"2026-04-22T04:50:11.185690+00:00","updated_at":"2026-04-22T04:50:11.185690+00:00","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","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/sindresorhus/is-redirect","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/is-redirect","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-21","install_tag":null}}