Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yehorbk/annotations-js
Library that provides annotations functionality in vanilla JavaScript
https://github.com/yehorbk/annotations-js
annotation annotations javascript javascript-library javascript-vanilla
Last synced: 2 days ago
JSON representation
Library that provides annotations functionality in vanilla JavaScript
- Host: GitHub
- URL: https://github.com/yehorbk/annotations-js
- Owner: yehorbk
- License: mit
- Created: 2020-11-18T10:48:13.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-06T12:31:27.000Z (almost 4 years ago)
- Last Synced: 2024-08-08T18:57:41.338Z (3 months ago)
- Topics: annotation, annotations, javascript, javascript-library, javascript-vanilla
- Language: JavaScript
- Homepage:
- Size: 54.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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.```javascript
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:```javascript
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:```javascript
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**: [GitHub](https://github.com/yehorbk) • [Twitter](https://twitter.com/yehorbk)