Newsworthy Presidential Mistakes
    Wondering what’s next for npm?Check out our public roadmap! »


    1.0.1 • Public • Published


    Library that provides annotations functionality in vanilla JavaScript.


    Install library via npm:

    $ npm install annotations-js

    How to Use

    Creating custom annotation

    First of all, you need to get the main Annotation function by connecting the library. To create your own custom annotation, you need to call the bind function from Annotation, passing your function (annotation) to it. This function will set generic annotation prototype to your annotation and then you will be able to use your annotation or extend it's functionality.

    const Annotation = require('annotations.js');
    function CustomAnnotation() {}

    To get all binded annotations in your application you can use method getAnnotations from Annotation.

    Working with annotation

    With your custom annotation you can annotate functions, objects and variables. All annotated items will be stored in annotation's storage that can be returned from getAnnotated method. Also you able to pass params with annotated item. To annotate a function declaration - use next syntax:

    CustomAnnotation.annotate(FooFunction, { fooParam: 'fooParam' });
    function FooFunction() {}

    If you want to annotate functional expressions, objects, variables, etc. - there is special syntax for it. The annotate method returns interface for your annotated value:

    const fooInterface = CustomAnnotation.annotate('fooObject');
    const fooObject = (fooInterface.value = { objectParam: 'objectParam' });

    The string literal 'fooObject' in this example - it's a key for annotated item. It is advisable to name it the same as the annotated one.


    Unfortunately, not all basic linter configurations allow you to work with multi-assignment and use of a function before it's declared, so if you are using ESLint you should disable these rules: no-multi-assign, no-use-before-define.


    Yehor Bublyk: GitHubTwitter


    npm i annotations-js

    DownloadsWeekly Downloads






    Unpacked Size

    16.4 kB

    Total Files


    Last publish


    • avatar