npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@schennco/nodeannotations

v2.0.2

Published

The annotations library is a tool which allows you to generate metadata about a javascript class from the annotations in the class, methods, and property comments. This can be useful for things such as, automatic validation, controller routing, dependen

Downloads

7

Readme

The annotations library is a tool which allows you to generate metadata about a javascript class from the annotations in the class, methods, and property comments. This can be useful for things such as, automatic validation, controller routing, dependency injection, testing, and much much more.

Comments must use the following format to be scanned

/**
 * @annotation
 * @annotation {types}
 * @annotation value
 * @annotation {types} value
 */

The methods and properties you wish to memoize must follow a comment or they will be skipped.
Methods must use the following format to be scanned The whitespaces are optional. There can be a linebreak between the end paren and opening brace

/**
 * @annotations
 */
 methodName (params...) {

Properties must use the following format to be scanned The whitespaces are optional. There can be a linebreak between the end paren and opening brace

 /**
  * @annotations
  */
  get prop () {
  

and/or

/**
 * @annotations
 */
 set prop (value) {

To use for scanning a directory or multiple individual files.

let collector = new Collector();
collector.collectFromPath(FullWorkingPathToDirectory, onCompleteCallback);

or, for loading a single file at a time.

let collector = new Collector();
collector.collectFromFile(FullWorkingPathToFile, onCompleteCallback);
    

The collector creates a Metadata object for each class.
If you want to bypass the Collector then you can just use the Metadata class. for example, If you're only working with a limited set of classes or only need to fetch the metadata occasionally

let metadata = new Metadata();
metadata.parseFile(FullWorkingPathToFile, OnCompleteCallback);

If you're working with strings instead of filepaths

let metadata = new Metadata();
metadata.parseContent(TextThatDescribesClass, OnCompleteCallback);

The string must represent the text of a class. For example, see any of the classes in the annotations library. Comments which do not immediately precede the class declaration, a class method, or a class property are skipped. You can include them in your classes for the sake of documentation without worrying about them being memoized.

If you're only interested in scanning a string which contains a comment block

let docblock = new DocBlock();
let startIndex = contentString.indexOf(docBlock.openComment, currentTextIndex);
let endIndex = docblock.fromIndex(contentString, startIndex);

or, if your string is just the comment body or you don't need the end index of the comment being memoized

let docblock = new DocBlock();
docblock.comment = commentString;

The Annotation takes a string that looks like a slice of the comment format above

* @annotation
* @annotation {types}
* @annotation value
* @annotation {types} value