New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

nodeannotations

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodeannotations

NodeJS Support for Annotations

Source
npmnpm
Version
0.2.3
Version published
Weekly downloads
6
50%
Maintainers
1
Weekly downloads
 
Created
Source

NodeAnnotations

GitHub license npm version GitHub stars

Table of Contents

Getting Started

  • Clone the example repository
    git clone git@github.com:anupam-git/nodeannotations-example.git
  • Install Dependencies
    npm install
  • Test the Parser
    node testParser.js

Class : Annotation

Annotation.value

Stores the value of the Annotation

/**
 * @Annotation("someValue")
 */
function test() {
    //Function Body
}

value will have the data someValue for the function test()

Annotation.[param]

Stores the value of the parameter param of the Annotation

/**
 * @Annotation(param1="someValue1", param2="someValue2")
 */
function test() {
    //Function Body
}

param1 will have the data someValue1 for the function and param2 will have the data someValue2 for the function test()

Annotation.objectOf

Stores the type of the of the Annotation

/**
 * @Annotation("someValue")
 */
function test() {
    //Function Body
}

objectOf will have the data Annotation for the function test()

Class : AnnotatedElement

AnnotatedElement.getName()

Returns the name of the Element

/**
 * @Annotation("someValue")
 */
function test() {
    //Function Body
}

getName() will return "test" for the function test()

AnnotatedElement.getType()

Returns the Type of the Element (Variable, Method or Class)

/**
 * @Annotation("someValue")
 */
function test() {
    //Function Body
}

getType() will return "Method" for the function test()

AnnotatedElement.getAnnotation(objectOf)

Returns the Annotation object which is an instance of objectOf

/**
 * @Annotation("someValue")
 */
function test() {
    //Function Body
}

getAnnotation("Annotation") will return {"value":"someValue","objectOf":"Annotation"} for the function test()

AnnotatedElement.getAnnotations()

Returns all the annotations of an AnnotatedElement

/**
 * @Annotation("someValue")
 * @AnotherAnnotation("someMoreValue")
 */
function test() {
    //Function Body
}

getAnnotations() will return [{"value":"someValue","objectOf":"Annotation"}, {"value":"someMoreValue","objectOf":"AnotherAnnotation"}] for the function test()

AnnotatedElement.TYPE_CLASS

Constant value 0 representing the AnnotatedElement as a Class

AnnotatedElement.TYPE_METHOD

Constant value 1 representing the AnnotatedElement as a Method

AnnotatedElement.TYPE_VARIABLE

Constant value 2 representing the AnnotatedElement as a Variable

AnnotationParser

AnnotationParser.parse(filePath, annotationsPath)

Parses a file for Annotations and returns annotatedElements object.

  • filePath is the Absolute Path of File to be Parsed for Annotations.
  • annotationsPath is the Absolute Path of Directory containing all the Annotation Classes.

annotatedElements

annotatedElements is the result returned after parsing the file with path filePath. annotatedElements is the array of all the elements that are Annotated with the Annotations available at annotationsPath. The Array Object also has method filterBy(objectOf)

filterBy(objectOf)

filterBy returns the array of Elements Annotated with objectOf type of Annotation

Example

let annotatedElements = AnnotationParser.parse(__dirname+"/annotatedFile.js", __dirname+"/myannotations/");

annotatedElements.forEach((annotatedElement) => {
    console.log("\t"+annotatedElement.getName()+" : "+annotatedElement.getType());

    // Loop and Print All annotations of the current Element
    annotatedElement.getAnnotations().forEach((annotation) => {
        console.log("\t\t"+JSON.stringify(annotation));
    });

    console.log();
});

// Loop through the elements which are annotated with @Annotation()
annotatedElements.filterBy("Annotation").forEach((annotatedElement) => {
    console.log("\t"+annotatedElement.getName()+" : "+annotatedElement.getType());

    // Loop and Print All annotations of the current Element        
    annotatedElement.getAnnotations().forEach((annotation) => {
        console.log("\t\t"+JSON.stringify(annotation));
    });

    console.log();
});

Keywords

annotations

FAQs

Package last updated on 13 Apr 2017

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