New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

annotations-js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

annotations-js

Library that provides annotations functionality in vanilla JavaScript

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Annotations-JS

Library that provides annotations functionality in vanilla JavaScript.

Installation

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');

Annotation.bind(CustomAnnotation);
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.

Linting

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.

Author

Yehor Bublyk: GitHubTwitter

Keywords

FAQs

Package last updated on 06 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc