npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

localized-http-messages

v0.1.2

Published

A simple package giving you translated http messages

Downloads

15

Readme

localized-http-messages

A simple package giving you translated http messages.

npm bundle size Coverage Status dependencies Status

devDependencies Status Maintainability

Known locales

  • en (english)
  • fr (français)

You can send me translations in your locale if you want it in the module!

Basic usage

const translator = require('localized-http-messages')

let tr = new translator('fr') // or a JS Object with translations
console.log( tr.getMessage(418) )
// > Je suis une théière

API

Constructor(String|JS Object)

The parameter is the locale to set. If no locale is set, it will fallback to en.

The behavior is the same than calling setLocale method.

setLocale(String|JS Object)

Set the current locale.

If the parameter is a String, the module will try to find it in the list of known locale. If the locale is not known, it is ignored.

If the parameter is a JS Object, the module will load the object as the current locale. The object must be formatted like this:

{
    code: "Message",
    code: "Message",
    etc.
}

Example:

{
    404: "Custom message when not found",
    418: "Custom message for teapot"
}

getMessage(Number|String)

Return the String of the code given in paramter.

If the code is not found in the current locale, it falls back to the previous locale set. If the code is not found in the previous locale, it falls back to en.

If the code is not found in any of the locales, it return the code as a String.

Example:

const translator = require('localized-http-messages')

let tr = new translator('fr')
tr.setLocale({
    404: 'Not found, sorry!'
})
console.log( tr.getMessage(404) )
// > Not found, sorry!
console.log( tr.getMessage(418) )
// > Je suis une théière
console.log( tr.getMessage(999) )
// > 999

List of known codes

| Code | English translation | | :----- | :------------------------------------ | | 100 | Continue | | 101 | Switching Protocols | | 102 | Processing | | 103 | Early Hints | | 200 | OK | | 201 | Created | | 202 | Accepted | | 203 | Non-Authoritative Information | | 204 | No Content | | 205 | Reset Content | | 206 | Partial Content | | 207 | Multi-Status | | 208 | Already Reported | | 210 | Content Different | | 226 | IM Used | | 300 | Multiple Choices | | 301 | Moved Permanently | | 302 | Found | | 303 | See Other | | 304 | Not Modified | | 305 | Use Proxy | | 306 | Switch Proxy | | 307 | Temporary Redirect | | 308 | Permanent Redirect | | 310 | Too many Redirects | | 400 | Bad Request | | 401 | Unauthorized | | 402 | Payment Required | | 403 | Forbidden | | 404 | Not Found | | 405 | Method Not Allowed | | 406 | Not Acceptable | | 407 | Proxy Authentication Required | | 408 | Request Timeout | | 409 | Conflict | | 410 | Gone | | 411 | Length Required | | 412 | Precondition Failed | | 413 | Request Entity Too Large | | 414 | Request-URI Too Long | | 415 | Unsupported Media Type | | 416 | Requested range unsatisfiable | | 417 | Expectation failed | | 418 | I'm a teapot | | 421 | Bad mapping / Misdirected Request | | 422 | Unprocessable entity | | 423 | Locked | | 424 | Method failure | | 425 | Unordered Collection | | 426 | Upgrade Required | | 428 | Precondition Required | | 429 | Too Many Requests | | 431 | Request Header Fields Too Large | | 449 | Retry With | | 450 | Blocked by Windows Parental Controls | | 451 | Unavailable For Legal Reasons | | 456 | Unrecoverable Error | | 444 | No Response | | 495 | SSL Certificate Error | | 496 | SSL Certificate Required | | 497 | HTTP Request Sent to HTTPS Port | | 498 | Token expired/invalid | | 499 | Client Closed Request | | 500 | Internal Server Error | | 501 | Not Implemented | | 502 | Bad Gateway | | 503 | Service Unavailable | | 504 | Gateway Timeout | | 505 | HTTP Version not supported | | 506 | Variant Also Negotiates | | 507 | Insufficient storage | | 508 | Loop detected | | 509 | Bandwidth Limit Exceeded | | 510 | Not extended | | 511 | Network authentication required | | 520 | Unknown Error | | 521 | Web Server Is Down | | 522 | Connection Timed Out | | 523 | Origin Is Unreachable | | 524 | A Timeout Occurred | | 525 | SSL Handshake Failed | | 526 | Invalid SSL Certificate | | 527 | Railgun Error |

Sources

  • https://fr.wikipedia.org/wiki/Liste_des_codes_HTTP
  • https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  • https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
  • https://httpstatuses.com/
  • https://www.loggly.com/blog/http-status-code-diagram/
  • https://assiste.com/Codes_HTTP/index_01.html
  • https://translate.google.com