Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

decorator-utils

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decorator-utils

Utilities for ES7 decorators.

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

decorator-utils NPM version Build status

Utilities for ES7 decorators.

Installation

Install the package with NPM:

$ npm install decorator-utils

Usage

A simple example:

import {DecoratorUtils} from "decorator-utils";

function decorator() {
  let declarationType = DecoratorUtils.getDeclarationType(arguments);

  if (declarationType !== DecoratorUtils.declarationTypes.CLASS_METHOD) {
    throw new Error("Decorator must be applied to a class method declaration.");
  }

  // The rest of the decorator's logic...
}

@decorator // Error will be thrown.
class Dog {
  @decorator // Error will NOT be thrown.
  woof() {}
}

API

The package exposes a static class, DecoratorUtils, which has the following functions and properties:

getDeclarationType()

  • A function that can be called from within a decorator to determine the type of declaration that is being targeted. Useful for guarding a decorator against certain declaration types.
  • Parameters:
    • arguments - The arguments object of the decorator function. Just pass it through!
  • Returns a value from DecoratorUtils.declarationTypes.

createDecorator()

  • A function that produces a decorator that can only be applied to a subset of "supported" declaration types; all "unsupported" ones will throw an error. Handy if you want to create decorators in a factory-like manner.
  • Parameters:
    • supportedDeclarationTypes - An array of values from DecoratorUtils.declarationTypes.
    • fn - A function that contains the rest of the decorator's logic.
  • Returns a decorator (function).

declarationTypes

  • A property describing the set of possible declaration types that a decorator can target, as key-value pairs of an object (String -> Symbol). To be used in conjunction with DecoratorUtils.getDeclarationType().
  • Keys:
    • CLASS
    • CLASS_METHOD
    • CLASS_ACCESSOR
    • OBJECT_LITERAL_METHOD
    • OBJECT_LITERAL_ACCESSOR

Keywords

FAQs

Package last updated on 26 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc