{"id":17289,"library":"ltrl-http","title":"Literal HTTP Codes & Statuses","description":"ltrl-http is a JavaScript/TypeScript library that provides a comprehensive, type-safe collection of HTTP status codes and their corresponding descriptions. It offers both numerical codes and string statuses, along with utility functions for validation and resolution. Currently at version 0.0.20, the package demonstrates a rapid release cadence with frequent patch and minor updates, often related to broader `ltrl` monorepo enhancements, particularly around Nuxt.js integration. Its key differentiators include strong TypeScript typing for HTTP codes and statuses, allowing for compile-time safety, and helper functions like `isHTTPCode` and `useHTTPCode` to work with these values programmatically. It aims to simplify handling HTTP responses by providing a consistent and robust interface for standard HTTP semantics.","status":"active","version":"0.0.20","language":"javascript","source_language":"en","source_url":"https://github.com/zoobzio/ltrl","tags":["javascript","typescript"],"install":[{"cmd":"npm install ltrl-http","lang":"bash","label":"npm"},{"cmd":"yarn add ltrl-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add ltrl-http","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses ES module syntax. CommonJS `require` might not work directly without transpilation or specific Node.js configuration.","wrong":"const { status } = require('ltrl-http');","symbol":"status","correct":"import { status } from 'ltrl-http';"},{"note":"Used for runtime validation of a number against known HTTP status codes.","symbol":"isHTTPCode","correct":"import { isHTTPCode } from 'ltrl-http';"},{"note":"This is a TypeScript type union of all available HTTP status code literals, useful for type checking functions that accept HTTP codes.","symbol":"HTTPCode","correct":"import type { HTTPCode } from 'ltrl-http';"},{"note":"Utility function to get an HTTP code from a status string.","symbol":"useHTTPStatus","correct":"import { useHTTPStatus } from 'ltrl-http';"}],"quickstart":{"code":"import { status, isHTTPCode, HTTPCode } from 'ltrl-http';\n\n// Accessing HTTP status codes directly\nconsole.log(`OK: ${status.OK}`); // Output: OK: 200\nconsole.log(`Forbidden: ${status.FORBIDDEN}`); // Output: Forbidden: 403\n\n// Using utility functions\nconst codeToCheck: unknown = 200;\nif (isHTTPCode(codeToCheck)) {\n  console.log(`${codeToCheck} is a valid HTTP code.`);\n} else {\n  console.log(`${codeToCheck} is not a valid HTTP code.`);\n}\n\n// Type usage example\nfunction handleResponse(code: HTTPCode) {\n  switch (code) {\n    case status.OK:\n      console.log('Request successful!');\n      break;\n    case status.NOT_FOUND:\n      console.log('Resource not found.');\n      break;\n    default:\n      console.log(`Unhandled HTTP code: ${code}`);\n  }\n}\n\nhandleResponse(status.INTERNAL_SERVER_ERROR);\n// Expected output: Unhandled HTTP code: 500","lang":"typescript","description":"Demonstrates importing `status` for direct code access, `isHTTPCode` for validation, and `HTTPCode` for type safety."},"warnings":[{"fix":"Review any code that directly accesses the configuration object returned by `useHTTPCodeConfig()` and update field names from `key` or `label` to `id` as appropriate.","message":"The internal structure of 'congruents' has changed from using 'key' and 'label' fields to a single 'id' field. While `ltrl-http`'s direct exports like `status` are unaffected, custom integrations or direct access to the configuration via `useHTTPCodeConfig()` that rely on the previous field names will break.","severity":"breaking","affected_versions":">=0.0.20"},{"fix":"Use exact version numbers (e.g., `\"ltrl-http\": \"0.0.20\"`) in `package.json` and regularly review changelogs before upgrading.","message":"The `ltrl` project, including `ltrl-http`, is actively developed with frequent minor versions and patches. While this indicates active maintenance, it also means that internal structures and features might evolve rapidly. It's advisable to pin exact versions in production to avoid unexpected behavior changes from sub-minor updates.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure the import statement `import { status } from 'ltrl-http';` is at the top of your file and that your environment supports ES Modules. If using CommonJS, consider transpiling or using dynamic import if available.","cause":"Attempting to access `status.OK` before the module is correctly imported, or if the `status` object is undefined.","error":"TypeError: Cannot read properties of undefined (reading 'OK')"},{"fix":"Ensure `ltrl-http` is installed (`npm install ltrl-http` or `pnpm add ltrl-http`) and that `moduleResolution` in your `tsconfig.json` is set to a suitable value like `Node16` or `Bundler` for modern module resolution.","cause":"TypeScript compiler cannot locate the package or its declaration files (`.d.ts`).","error":"TS2307: Cannot find module 'ltrl-http' or its corresponding type declarations."}],"ecosystem":"npm","meta_description":null}