Socket
Socket
Sign inDemoInstall

constructor-decorator

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    constructor-decorator

Typized and autoassigned constructor arguments for JS


Version published
Maintainers
1
Install size
4.54 kB
Created

Readme

Source

Constructor Decorator

Travis (.com) npm NPM npm

Typized and autoassigned arguments for JS class constructor.

Overview

Are you not tired of constantly writing like:

class TypedEntity {
  constructor (
    foo,
    bar,
    baz,
    bat,
    fie,
    bal,
    fuu,
    faa
  ) {
    this.baz = baz
    this.bal = bal
    this.foo = foo
    this.fuu = fuu
    this.bar = bar
    this.bat = bat
    this.fie = fie
    this.faa = faa
  }
}

module.exports = TypedEntity

Now you can avoid of it with the class extend:

const BaseClass = require('constructor-decorator')

const Foo = require('./Foo')
const Bar = require('./Bar')
const Baz = require('./Baz')


class TypedEntity extends BaseClass {
  get args () {
    return {
      foo: [Foo, Baz],
      bar: [Bar, String],
      baz: String,
      bat: Boolean,
      fie: String,
      bal: [String, Number],
      fuu: Date,
      faa: Number,
    }
  }

  constructor () {
    super(...arguments)
  }
}

module.exports = TypedEntity

The types compare is enabled with an array OR-operator syntax support.

Donate

  • BTC 3F275vPSCvYW19MHZqSjw79fEwwU4MbTgV
  • LTC MGMCQB3QAcrSBjU3eGJviqB2J2f5BNVRGr
  • DOGE D5m69FRDGEn3G3xuakvqTxUpGVt6NegKJp

Keywords

FAQs

Last updated on 05 Feb 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc