https://github.com/piterden/constructor-decorator
Constructor sugar with types checking
https://github.com/piterden/constructor-decorator
constructor decorations runtime-typechecking
Last synced: 11 months ago
JSON representation
Constructor sugar with types checking
- Host: GitHub
- URL: https://github.com/piterden/constructor-decorator
- Owner: Piterden
- Created: 2019-03-07T04:35:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-05T15:59:47.000Z (about 6 years ago)
- Last Synced: 2024-10-16T09:33:09.462Z (over 1 year ago)
- Topics: constructor, decorations, runtime-typechecking
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/constructor-decorator
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Constructor Decorator
   
Typized and autoassigned arguments for JS class constructor.
## Overview
Are you not tired of constantly writing like:
```js
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:
```js
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`