1.0.0 • Published 5 years ago

js-language-error v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 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'