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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@arcmantle/reflect-metadata

v1.0.4

Published

Lightweight, partial implementation of TC39 Reflect Metadata proposal with function-activated shim

Readme

@arcmantle/reflect-metadata

License TypeScript

A lightweight, partial implementation of the TC39 Reflect Metadata proposal. This library provides reflection metadata functionality with a focus on performance and bundle size.

✨ Features

  • 🪶 Lightweight: Only ~3.2KB unminified, 1.7KB minified, 0.7KB gzipped
  • 🚀 Performance optimized: WeakMap-based storage for optimal memory usage
  • 🔧 Function-activated: Extends the global Reflect object with metadata APIs
  • 🛡️ Safe: Won't override existing reflect-metadata implementations
  • 📦 ESM native: Built for modern JavaScript environments
  • 🎯 TypeScript ready: Full type definitions included

📦 Installation

npm install @arcmantle/reflect-metadata
pnpm add @arcmantle/reflect-metadata
yarn add @arcmantle/reflect-metadata

🚀 Quick Start

Extend Global Reflect

Extend the global Reflect object with metadata APIs:

TypeScript/JavaScript

import { useReflectMetadata } from '@arcmantle/reflect-metadata';

// Extend the global Reflect with metadata APIs
const Reflect = useReflectMetadata();

// Now you can use Reflect metadata APIs (global Reflect is extended)
Reflect.defineMetadata('custom:key', 'value', target);
const value = Reflect.getMetadata('custom:key', target);

HTML

<script type="module">
 import { useReflectMetadata } from '@arcmantle/reflect-metadata';

 const Reflect = useReflectMetadata();
 // Reflect metadata APIs are now available globally
</script>

📚 API Reference

This library implements the following Reflect metadata APIs:

Reflect.defineMetadata(key, value, target[, propertyKey])

Defines metadata for a target object or property.

const Reflect = useReflectMetadata();
Reflect.defineMetadata('custom:type', 'string', MyClass, 'propertyName');

Reflect.getMetadata(key, target[, propertyKey])

Retrieves metadata from a target object or property, including inherited metadata.

const Reflect = useReflectMetadata();
const type = Reflect.getMetadata('custom:type', MyClass, 'propertyName');

Reflect.getOwnMetadata(key, target[, propertyKey])

Retrieves own metadata from a target object or property (no inheritance).

const Reflect = useReflectMetadata();
const ownType = Reflect.getOwnMetadata('custom:type', MyClass, 'propertyName');

Reflect.hasMetadata(key, target[, propertyKey])

Checks if metadata exists for a target object or property (including inherited).

const Reflect = useReflectMetadata();
const hasType = Reflect.hasMetadata('custom:type', MyClass, 'propertyName');

Reflect.hasOwnMetadata(key, target[, propertyKey])

Checks if own metadata exists for a target object or property (no inheritance).

const Reflect = useReflectMetadata();
const hasOwnType = Reflect.hasOwnMetadata('custom:type', MyClass, 'propertyName');

Reflect.metadata(key, value)

Creates a metadata decorator function.

const Reflect = useReflectMetadata();
const Type = (type: string) => Reflect.metadata('custom:type', type);

class MyClass {
 @Type('string')
 propertyName: string;
}

Reflect.decorate(decorators, target[, propertyKey, descriptor])

Applies decorators to a target.

const Reflect = useReflectMetadata();
const decoratedClass = Reflect.decorate([MyDecorator], MyClass);

🔧 Usage Examples

Basic Metadata Storage

import { useReflectMetadata } from '@arcmantle/reflect-metadata';

const Reflect = useReflectMetadata();

class User {
 name: string;
 email: string;
}

// Store metadata
Reflect.defineMetadata('validation:required', true, User, 'name');
Reflect.defineMetadata('validation:email', true, User, 'email');

// Retrieve metadata
const isNameRequired = Reflect.getMetadata('validation:required', User, 'name');
const isEmailValidation = Reflect.getMetadata('validation:email', User, 'email');

Custom Decorators

import { useReflectMetadata } from '@arcmantle/reflect-metadata';

const Reflect = useReflectMetadata();

// Create a validation decorator
function Required(target: any, propertyKey: string) {
 Reflect.defineMetadata('validation:required', true, target, propertyKey);
}

function Email(target: any, propertyKey: string) {
 Reflect.defineMetadata('validation:email', true, target, propertyKey);
}

class User {
 @Required
 name: string;

 @Required
 @Email
 email: string;
}

// Validation logic
function validate(instance: any) {
 const constructor = instance.constructor;

 for (const property of Object.keys(instance)) {
  const isRequired = Reflect.getMetadata('validation:required', constructor, property);
  const isEmail = Reflect.getMetadata('validation:email', constructor, property);

  if (isRequired && !instance[property]) {
   throw new Error(`${property} is required`);
  }

  if (isEmail && !instance[property].includes('@')) {
   throw new Error(`${property} must be a valid email`);
  }
 }
}

⚠️ Important Notes

  • Safe activation: Multiple calls to useReflectMetadata() return the same extended global Reflect
  • Non-destructive: Won't override existing reflect-metadata implementations
  • Global extension: Extends the global Reflect object with metadata methods
  • ESM only: This package is ESM-only and requires Node.js 14+ or modern browsers
  • Partial implementation: Only implements the most commonly used metadata APIs

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

🔗 Related Projects