Skip to content

dominictarr/hoox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hoox

hook around a function to alter input and output.

Very simple. only 20 lines. The example below is longer than the code.

Example

//take an innocent function
function plus (a, b) {
  return a + b
}

//and add hooks to it.
plus = Hoox(plus)

//now you can control input and output
plus.hook(function (fn, args) {

  var value = fn.apply(null, args.map(Math.round))

  return Math.max(value, 0)
})

console.log(plus(1,3))
// 4

console.log(plus(0.8, -5))
// 0

console.log(plus(0.9, 0.9))
// 2

in Aspect Oriented Programming, this function would be called an around hook. I have not implemented pre, and post hooks yet, because this is currently sufficent for my purposes.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published