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

@itrocks/email-address

v0.0.7

Published

An @EmailAddress() decorator to validate that a property contains a valid email address

Readme

npm version npm downloads GitHub issues discord

email-address

An @EmailAddress() decorator to validate that a property contains a valid email address.

This documentation was written by an artificial intelligence and may contain errors or approximations. It has not yet been fully reviewed by a human. If anything seems unclear or incomplete, please feel free to contact the author of this package.

Installation

npm i @itrocks/email-address

Usage

@itrocks/email-address provides a property decorator @EmailAddress() that lets you mark a field as expected to contain a valid email address. The decorator does not perform the validation itself: it adds metadata that other parts of the framework (or your own code) can use to check and enforce the value.

You can also read this metadata using the helper function emailAddressOf, for example to build your own validation pipeline or form‑rendering logic.

Minimal example

import { EmailAddress } from '@itrocks/email-address'

class User {
  @EmailAddress()
  email = ''
}

Here, the email property is marked as containing an email address. A generic validator can then iterate over the properties decorated with @EmailAddress() to verify that they match the expected format.

Complete example with decorator lookup

In a typical use case, you combine this package with other components that rely on decorators to generate forms or validate data.

import type { ObjectOrType }   from '@itrocks/class-type'
import { EmailAddress, emailAddressOf } from '@itrocks/email-address'

class User {
  @EmailAddress()
  email = ''

  // This property will not be considered an email address
  name  = ''
}

function listEmailFields<T extends object>(type: ObjectOrType<T>): (keyof T)[] {
  const result: (keyof T)[] = []

  // Simplified example: iterate over known properties
  for (const property of ['email', 'name'] as (keyof T)[]) {
    if (emailAddressOf(type, property)) {
      result.push(property)
    }
  }

  return result
}

// Result: ['email']
const emailFields = listEmailFields(User)

In practice, you will usually rely on helpers provided by other @itrocks/* packages to navigate decorator metadata, instead of manually listing properties as in this example.

API

function EmailAddress<T extends object>(value?: boolean): DecorateCaller<T>

Property decorator indicating that a field is expected to contain a valid email address.

Parameters

  • value (optional, default: true) – enables or disables the marking of the property as an email address. In most cases you will simply use @EmailAddress(). Passing false lets you remove or ignore this marker in advanced scenarios.

Return value

  • DecorateCaller<T> – function from @itrocks/decorator/property used internally by TypeScript to apply the decorator on the target property. You normally do not need to call it directly; you just apply @EmailAddress() to the property.

Example

class ContactForm {
  @EmailAddress()
  replyTo = ''
}

function emailAddressOf<T extends object>(target: ObjectOrType<T>, property: KeyOf<T>): boolean

Checks whether a given property is decorated with @EmailAddress().

Parameters

  • target – the class (User) or instance (new User()) that owns the property to check.
  • property – the name of the property to inspect.

Return value

  • booleantrue if the property is currently marked as an email address, false otherwise.

Example

import type { ObjectOrType } from '@itrocks/class-type'
import { EmailAddress, emailAddressOf } from '@itrocks/email-address'

class User {
  @EmailAddress()
  email = ''

  name = ''
}

function isEmailProperty<T extends object>(type: ObjectOrType<T>, property: keyof T): boolean {
  return emailAddressOf(type, property)
}

isEmailProperty(User, 'email') // true
isEmailProperty(User, 'name')  // false

Typical use cases

  • Mark properties in your domain models that must contain an email address, so that a generic validator can verify them.
  • Automatically generate email‑type form fields based on decorator metadata.
  • Build a validation or rendering system that relies on decorators to infer the constraints associated with each property.
  • Centralize the definition of what a “valid email address” is inside a single component of your application or framework, while keeping model annotations simple (@EmailAddress()).