1.0.0 • Published 6 months ago

method-enhancer v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Method Enhancer

Enhance the class method in a simple way.

Install

npm install method-enhancer

Usage

import { Enhance, Enhancement } from 'method-enhancer'

class SpeakerEnhancer implements Enhancement<Speaker> {
  say(target: Speaker['say'], arg: string): void {
    console.log('Before')
    target(arg)
    console.log('After')
  }
}

const speakerEnhancer = new SpeakerEnhancer()

class Speaker {
  @Enhance(speakerEnhancer.say)
  say(arg: string) {
    console.log(arg)
  }
}

const speaker = new Speaker()

speaker.say('Hello world')
// output:
// Before
// Hello world
// After

Typescript Support

Only support Typescript 5.0 and above

1.0.0

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago