nd-responses

0.0.4 • Public • Published

Response Module Documentation

The Response module provides an easy way to fetch all sorts responses for specific keys, languages, and sensitivities. Developed by tobi from Nous Dynasty.

Installation

If you are reading this you are most likely on nodejs.. just run

npm i nd-responses

you can then import or requires, call the class and use as you please

Usage

Importing the Module

You can import the Response class using require:

const { Response } = require('nd-responses');

or

import { Response } from 'nd-responses';

Initialization

To initialize a Response object, pass the desired language and sensitivity:

const responses = new Response('en', 'humorous');

If nothing is passed the default is english language with a normal sensitivity

  • Parameters:
    • language (optional): The language of the response, e.g., 'en' (only en for now). Defaults to 'en'.
    • sensitivity (optional): The tone or style of the response, e.g., normal' ,'detailed' ,'concise' ,'nice' ,'sad' ,'angry' ,'confused' ,'encouraging' ,'sarcastic' ,'humorous' ,'uncle' ,'sad_exaggerated' ,'dark' ,'roadman' ,'jamaican' ,'old_british' ,'viking'. Defaults to 'normal'.

Fetching a Response

Use the getResponse method to fetch a response for a given key.

(async () => {
    const response = await responses.getResponse('404');
    console.log(response);
})();
  • Method: getResponse
  • Parameters:
    • key (required): The response key, e.g., '404', 'LOGIN_ERROR_WRONG_DETAILS', 'LOGIN_ERROR_WRONG_PASSWORD'.
    • language (optional): Overrides the instance language for this request. Defaults to what what used in initialization of the class en
    • sensitivity (optional): Overrides the instance sensitivity for this request.Defaults to what what used in initialization of the class normal
  • Returns: A Promise that resolves to the response text.

Examples

Example 1: Default Language and Sensitivity

const { Response } = require('responses');
const roadmanResponses = new Response('en', 'roadman');

    try{
        ...
    }
    catch(e){
        res.send(await roadmanResponses.getResponse('LOGIN_ERROR_WRONG_DETAILS')); // would send a roadman kind of response
    }

Example 2: Custom Language and Sensitivity

const { Response } = require('./index');
const responses = new Response();

(async () => {
    const response = await responses.getResponse('404', 'en', 'viking');
    console.log(response); // Outputs a response as thought your app was run by vikings.
})();

API Overview

Property/Method Description Default
language Language of the response (e.g., 'en', 'es'). 'en'
sensitivity Tone or style of the response (e.g., 'normal', 'sarcastic', 'humorous'). 'normal'
getResponse(key) Fetches a response for the provided key. Returns a Promise with the response text. -

Error Handling

Errors during the fetch request will need to be handled manually. Example:

const { Response } = require('./index');
const responses = new Response();

(async () => {
    let response
    try {
        response = await responses.getResponse('404');
    } catch (error) {
        console.error('Error fetching response:', error.message);
        response = // a default message
    }
})();

Contributing

Feel free to contribute to this module by improving features, fixing bugs, or suggesting new ideas. Submit your changes through My Email .


License

This module is licensed under the ASC License. See the LICENSE file for more details.

Package Sidebar

Install

npm i nd-responses

Weekly Downloads

9

Version

0.0.4

License

ISC

Unpacked Size

5.12 kB

Total Files

3

Last publish

Collaborators

  • oluwatobioluwole