method-enhancer
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i method-enhancer

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.64 kB

Total Files

5

Last publish

Collaborators

  • kirrs