1.0.0 ā€¢ Published 4 years ago

js-language-error v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

Javascript Language Error Package

āœ” For bored developers, from bored developer.

How to use it

config.js

Contains the defaults configuration like:

module.exports = {
    language: 'hebrew', // The selected language
    translations: {
        hebrew: { // The key could be anything, add your language here šŸ˜Š
            // The translation is <from>: <to>, you should use real js errors for your key.
            'null': '×¢×Øך ×Øיק',
        },
        french: {},
        klingone: {}
    },
};

index.js / your code

You should use the error as:

    try {
        // This section will throw an error (I hope not)        
    }
    catch (err) {
        // The usage of HebrewError is like:
        throw new HebrewError(err);
    }

The exception will look like:

HebrewError: אינני יכול להחיל א×Ŗ הגולה 'gever' מ ×¢×Øך ×Øיק

Add Your Language

set your environment 'JS_LANGUAGE_ERROR_LANGUAGES' with JSON.stringify(...) of your language translation object.

JSON.stringify({
    hebrew: {
        'of': 'מ',
        'null': '×¢×Øך ×Øיק',
        'property': 'הגולה',
        'defined': 'הוצה×Ø',
        'is not': 'אינו',
        'unexpected token': 'אנלא ציפי×Ŗי לאהימון',
        'cannot read': 'לא ני×Ŗן לק×Øא א×Ŗ',
        'Cannot set': 'אינני יכול להחיל א×Ŗ',
        'maximum': '×Ŗק×Øה עליונה',
        'exceeded': 'הוח×Øגה',
        'object': 'אובייקט',
        'at': 'ב',
        'error': 'שגיאה',
        'exception': 'ח×Øיגה',
    }
})

For example:

set JS_LANGUAGE_ERROR_LANGUAGES='{"hebrew":{"of":"מ","null":"×¢×Øך ×Øיק","property":"הגולה","defined":"הוצה×Ø","is not":"אינו","unexpected token":"אנלא ציפי×Ŗי לאהימון","cannot read":"לא ני×Ŗן לק×Øא א×Ŗ","Cannot set":"אינני יכול להחיל א×Ŗ","maximum":"×Ŗק×Øה עליונה","exceeded":"הוח×Øגה","object":"אובייקט","at":"ב","error":"שגיאה","exception":"ח×Øיגה"}}'

Select language

set your environment 'JS_LANGUAGE_ERROR_SELECTED' with the name of your language (as specified as key in the languages object).### For example:

set JS_LANGUAGE_ERROR_SELECTED='hebrew'