Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zuoez02/http-code-translator
Translate http error code into your language
https://github.com/zuoez02/http-code-translator
Last synced: about 1 month ago
JSON representation
Translate http error code into your language
- Host: GitHub
- URL: https://github.com/zuoez02/http-code-translator
- Owner: zuoez02
- Created: 2017-11-21T06:23:57.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-22T03:49:06.000Z (about 7 years ago)
- Last Synced: 2024-11-06T02:42:06.238Z (about 2 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Http code translator
Translate http code into your languange.
## Install
```bash
npm install --save http-code-translator
```
or
```bash
yarn add http-code-translator
```## Usage
```javascript
// load the module
const HttpCodeTranslator = require('http-code-translator');// current support language is English and Chinese
const codeTranslator = new HttpCodeTranslator('en');// load language manually
// Language code is ISO 639-1
codeTranslator.loadLanguage('zh');
// or load the translation map
codeTranslator.loadTranslation({
// must have a default value when code not found
defaultValue: 'Unknown value',
200: 'OK',
});// translate code
codeTranslator.translate(200); // OK
codeTranslator.translate("200"); // OK
codeTranslator.translate("299"); // Unkonw value// Set default value
codeTranslator.setDefaultValue("The code is unknown");
codeTranslator.translate("299"); // The code is unknown
```## Typings
Typings is set in `index.d.ts` for typescript or code in VS code.
## LICENSE
MIT