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

@flute/thistle

v0.2.0

Published

Annotating and tagging for typescript classes.

Downloads

3

Readme

@flute/annotations

Summary

@flute/annotations provides decorators and methods for adding/retrieving metadata, annotations and tags:

  • Metadata: Metadata is arbitrary data attached and retrieved to/from an object with a metadata key. This is equivalent to (and implemented via) Reflect.setMetadata(...) and Reflect.getMetadata(...).
  • Annotations: Annotations are a list of arbitrary objects, stored on a class, property, method or method parameter via the metadata methods. Annotations are stored in order of appearance, not order of execution.
  • Tags: Tags are like annotations with the difference that the are stored in a set. Therefore, no duplicate tags are allowed for a given class, property, method or method parameter and there is no guaranteed order of tags.

All data is stored in the metadata of the constructor. When requesting metadata from objects, the data is also loaded from its constructor.

Installation

To use the package inside your application:

npm install --save @flute/annotations

Make sure the following settings are enabled in your project's tsconfig.json:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Additionally, an implementation of Reflect.getMetadata(...) and Reflect.setMetadata(...) is needed, e.g. install reflect-metadata:

npm install --save reflect-metadata

Import reflect-metadata in your main module:

// inside your main module
// ...
import 'reflect-metadata';
// ...

Usage

This documentation is not complete yet. Please see the tests and the source code for more information and for the full method signatures. Generated typedoc documentation is available here:

Metadata

Metadata can be set via the *Metadata decorators:

  • ClassMethadata, PropertyMetadata, MethodMetadata and MethodParameterMetadata, SetMetadata: Adds or replaces the metadata with the provided key on the corresponding object (class, property, method or method-parameter). There is also a generic FieldMetadata decorator that can be used on properties and methods. SetMetadata is a generic version of the other decorators that can be applied to classes, properties, methods and method parameters.
  • AppendClassMethadata, AppendPropertyMetadata, AppendMethodMetadata and AppendMethodParameterMetadata, PrependClassMethadata, PrependPropertyMetadata, PrependMethodMetadata and PrependMethodParameterMetadata: Assumes the metadata for the given key is an array (initializes it if necessary) and add the data to the end (append) or the start (prepen) of the array.
  • PutClassMethadata, PutPropertyMetadata, PutMethodMetadata and PutMethodParameterMetadata: Assumes the metadata for the given key is a Set (initializes it if necessary) and adds the data to the set.

Metadata can be retrieved via the corresponding get*Metadata methods.

All methods and decorators support a parameter objectType telling whether the object provided is the constructor itself (e.g. when using the decorator methods as decorators) or an instance of the class.

Annotations

Annotations are stored in a list. New annotations are prepended via Prepend*Metadata, therefore the sort order of annotations is the reverse of the execution order of the decorators, meaning the annotation list will be ["1", "2", "3"] for the following code:

@ClassAnnotation("1")
@ClassAnnotation("2")
@ClassAnnotation("3")
class A {
}

Available decorators are AnnotateClass, AnnotateProperty, AnnotateMethod, AnnotateMethodParameter and the generic version Annotate.

Tags

Tags are stored in a set. Therefore, each tag can only appear once on an a given class, property, method or method parameter and there is no guaranteed order of tags.

License

MIT License

Copyright (c) 2020 Andreas Hubert

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.