‚̧Nitrate Processed Mincemeat
    Have ideas to improve npm?Join in the discussion! ¬Ľ

    lexicon-js

    0.1.3¬†‚Äʬ†Public¬†‚Äʬ†Published

    Lexicon.js

    Fast and simple storage of your phrases.

    Getting started

    • Install with npm;
    • Download zip.

    Example

    Lexicon.js brings you ability to resolve message in your vocabulary tree by path. If there no key of path chain, Lexicon tries to resolve the default one.

        var vocabulary, lexicon;
     
        vocabulary = {
            greetings: {
                hi:      "Hi, wassup?"
                hello:   "Hello, my dear <%= friend %>!",
                goodbye: "Goodbye, my dear!"
                _:       "Some greetings to you!"
            }
        };
     
        lexicon = new Lexicon();
     
        console.log(lexicon.getMessage(vocabulary, ["greetings", "hi"]));                               // Hi, wassup?
        console.log(lexicon.getMessage(vocabulary, ["greetings", "hello"], { data: {friend: "Alf"} })); // Hello, my dear Alf!
        console.log(lexicon.getMessage(vocabulary, ["greetings", "not-existing-key"]));                 // Some greetings to you!

    Options

    By default there are few reserved keys:

        Lexicon.DEFAULTS = {
            key: {
                _:       '_',
                info:    'info',
                error:   'error'
            }
        };

    But you can redefine them by given options object. For example:

        var lexicon = new Lexicon({ key: { _: "_default" } });

    Lexicon uses underscore template notation. So if you want to render message dynamically, just declare your message with underscore template syntax, and then pass options to the #getMessage method:

        lexicon.getMessage(vocabulary, ["greetings", "hello"], { data: { friend: "Alf" } });

    Enjoy =)

    Install

    npm i lexicon-js

    DownloadsWeekly Downloads

    2

    Version

    0.1.3

    License

    MIT

    Last publish

    Collaborators

    • avatar