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

awesome-annotations

v1.0.7

Published

This library provides a simple and elegant solution for parsing annotations in JavaScript projects. It makes it easy to organize and scale your projects by extracting meaningful information from your code.

Downloads

20

Readme

Awesome Annotation Library

This library provides a simple and elegant solution for parsing annotations in JavaScript projects. It makes it easy to organize and scale your projects by extracting meaningful information from your code.

With this library, you can parse module.exports = class Something, annotations for default exporting class, functions, properties, methods, static methods, static properties, async methods, async functions, and more!

Features

Supports a wide range of JavaScript syntax for annotations.

Easy to use and integrate into your projects.

Makes it simple to extract and organize meaningful information from your code.

Usage

To get started with this library, simply include it in your project and start using it to parse your annotations.

Installation

You can install awesome-annotation as a dependency in your project by running the following command in your terminal:

npm install awesome-annotation

Or if you are using Yarn:

yarn add awesome-annotation 

After successful installation, you can import the package in your project and start using it.

Guide

You can use the annotation function in your project by requiring it in your code:

  const annotation = require("awesome-annotation");

The annotation function takes two arguments: the path to the file you want to parse for annotations, and an options object (which is optional).

Here is an example of how you could use the annotation function:

  const fileContent = annotation("/test/testone1.js", { cached: true, debug: false });

  console.table(fileContent.annotations);
  console.table(fileContent.getAnnos("UserController"));

  console.log(fileContent.exports.something, "@@");
  console.log(new fileContent.exports());

The fileContent variable will contain the annotations found in the file, as well as information about the exports. You can access the annotations through the annotations property, and use the getAnnos method to get annotations for a specific exported entity. Additionally, you can access the exports themselves through the exports property.

Realistic Example Use Case

Let's say you're working on a complex Ecommerce project and you need to implement hundreds of REST APIs. Rather than copying and pasting code multiple times, you can use Awesome Annotations to make your code more scalable and reusable.

To use Awesome Annotations, you simply add annotations to your JavaScript code that describe the data model, collection name, and other important information. For example, take a look at this code:

  /** 
   * % @Model
   * % @ModelName := Review
   * % @CollectionName := reviews 
   * & @Fields := ModelFields
   * & @GenerateDefaultAdminCRUDAll
   */
  module.exports = class Review extends EcommerceLib.Model
  {
    /** 
     * @override default behaviour of EcommerceLib.Model 
     * @example you can override default read_many method
     */
  }

  module.exports.ModelFields = [
    { name: "user",             mongodb: EcommerceLib.userField(true),       populate: true  },
    { name: "product",          mongodb: EcommerceLib.productField(true),    populate: true  },
    { name: "rating",           mongodb: { type: Number, required: true, min: 1, max: 5 }    },
    { name: "comment",          mongodb: { type: String, required: true, maxlength: 255 }    },
    { name: "metadata",         mongodb: { type: String, maxlength: 1400 } } // just in case...json stringify format
  ]

This code uses Awesome Annotations to describe a Mongoose model for product reviews. The annotations specify that this is a model, the name of the model is "Review", the collection name is "reviews", and the fields for this model are defined in the ModelFields array. Additionally, the GenerateDefaultAdminCRUDAll annotation generates default CRUD APIs for this model.

By using these annotations, you can easily generate the boilerplate code for your REST APIs, and also maintain your code as your project grows. The Ecommerce library reads these annotations and generates REST APIs automatically based on the specified model, collection name, and fields.

With Awesome Annotations, you can write clean, readable code that is also scalable and reusable, making it easy to build complex projects with ease.

Contributing

We welcome contributions to this library. If you would like to contribute, please fork the repository and submit a pull request.

License

This library is open-source and available under the MIT License.