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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-attributes

v1.0.13

Published

Provides auxiliary typescript decorators.

Readme

TS Attributes

This package provides a vast variety of TypeScript decorators of high importance. These decorators make sure that only valid values are considered but some of them do also make conversions like converting a string to upper-case or unharmful "refinements" of the input values like removing harmful characters from strings, removing unnecessary characters from them and more on.

Before enjoying the functionalities offered by this package please make sure that the node "experimentalDecorators" inside the "compilerOptions" of your tsconfig.json file is set to true as follows:

// tsconfig.json
{
  // ...
  "compilerOptions": {
    // ...
    "experimentalDecorators": true   
  }
}

##API Documentation

Property Decorators

  • creditCardNumber(accepts: CreditCardType | CreditCardType[] | 'all') Makes sure that the value of the property is a valid credit card number. This method also refines the value of the property in case the credit card number is a string like 5105-1051-0510-5100. In this case the '-' characters are removed from the string for convenience. Defaults to all.

Example:

class Account {
  @creditCardNumber() creditCardNr: string = '4111111111111111'; // correct!
}
  • date() Makes sure that the property to which this decorator is applied is a valid date object; otherwise throws.

Example:

class User {
  @date() created: Date = new Date('blahblah'); // error!
}
  • email() Makes sure that the value of the property is a string which represents a valid email address; otherwise throws.

Example:

class Customer {
  @email() emailAddress: string = 'someinvalidemail.com'; // error!
}
  • escape() Removes or replaces illegal characters of the string value of the given property.

Example:

class Link {
  @escape()
  url: string = `<script src="some/source.js">var & @+?</script>`;
  // %26lt;script src=%26quot;some%2Fsource.js%26quot;%26gt;var %26amp; @%2B%3F%26lt;%2Fscript%26gt;
}
  • float(decimals: number) Rounds a decimal number to the given number of decimal digits.

Example:

class BankAccount {
  @float(2) balance: number = 56.669; // value: 56.67
}
  • iban(accepts: Country | Country[] | 'all') Makes suret that the string value of the given property is a valid IBAN; otherwise throws. Defaults to all.

Example:

class Account {
  @iban() iban: string = 'DE75 5121 0800 1245 1261 99'; // correct!
}
  • integer() Makes sure that the value of a property is an integer; otherwise throws.

Example:

class Person {
  @integer() age: number = -1.1; // error!
}
  • interval(from: Date, to: Date) Makes sure that the value of the given property is within the determined time interval.

Example:

class Citizen {
  @interval(new Date('1995-12-17'), new Date())
  born: Date = new Date('1991-12-17'); // error!
}
  • key() Makes sure that the property fulfills the criteria for being a key i. e. is a required property and its value is read-only.

Example:

class ClientDto {
  @key() id: string = undefined as unknown as string; // error!
}
  • lowerFirst() Converts the first character of the value of the string property to lower case.

Example:

class Student {
  @lowerFirst() hobby: string = 'Guitar'; // guitar
}
  • lowercase() Converts the value of a property of type string to lower case.

Example:

class Applicant {
  @lowercase() note: string = 'bLaH BlAh'; // blah blah
}
  • negativeInteger() Makes sure that the value of the given property is a negative integer.

Example:

class X {
  @negativeInteger() x: number = 1; // error!
}
  • notNull() Makes sure that the property has a value other than null set; otherwise throws.

Example:

class Pupil {
  @notNull() age: number = null as unknown as number; // error!
}
  • positiveInteger() Makes sure that the value of the property is a positive integer incl. zero.

Example:

class X {
  @positiveInteger() x: number = -1; // error!
}
  • readOnly() Makes the given property read-only.

Example:

class Visitor {
  @readOnly() id: string = 'somevalue';
}

const visitor = new Visitor();
visitor.id = 'othervalue'; // error!
  • required() Makes sure that neither null nor undefined is set as a value to the property to which this decorator is applied; otherwise throws.

Example:

class Pupil {
  @required() age: number = undefined as unknown as number; // error!
}
  • segment(from: number, to: number) Makes sure that the value of the property is within the determined segment; otherwise an error is thrown.

Example:

class X {
  @segment(-1, 1) x: number = 2; // error!
}
  • upperFirst() Capitalizes the first character of the value of the string property.

Example:

class Student {
  @upperFirst() name: string = 'johnny'; // Johnny
}
  • uppercase() Capitalizes the string value of the property to which this decorator is being applied.

Example:

class Applicant {
  @uppercase() passportNo: string = 'ab1234567l'; // AB1234567L
}