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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    0
  • 0.0.9
    0
  • 0.0.8
    0
  • 0.0.7
    0

Package Sidebar

Install

npm i method-enhancer

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

4.64 kB

Total Files

5

Last publish

Collaborators

  • kirrs