Skip to content

Commit

Permalink
Merge pull request #13 from bmeck/master
Browse files Browse the repository at this point in the history
add typescript definitions
  • Loading branch information
3rd-Eden authored Apr 26, 2019
2 parents eada14f + 9c55e97 commit 2b53f2a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
32 changes: 32 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Type definitions for: hearing-aid
/// <reference lib="dom">
/// <reference types="node">
export = hearing;

// Browser
declare function hearing(
what: EventTarget,
when: string,
how: EventListenerOrEventListenerObject): () => void;

// Node
declare function hearing(
what: import('events').EventEmitter,
when: string,
how: (...args: any) => any): () => void;

// Ad-hoc
declare function hearing(
what: Object & ({
addEventListener: Function,
removeEventListener?: Function
} | {
attachEvent: Function,
detachEvent?: Function
} | {
on: Function,
removeListener?: Function,
off?: Function
}),
when: string,
how: Function): () => void;
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ var ftw = typeof window !== 'undefined' ? window : {}
* @param {Function} how Function to be executed.
* @returns {Function}
* @api public
*
* @example ```js
// listen for `stream` to 'end'
var stop = hearing(stream, 'end', callback);
// stop listening after 1 second
setTimeout(stop, 1000);
```
*/
module.exports = function hearing(what, when, how) {
if ('addEventListener' in what) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
},
"dependencies": {
"one-time": "0.0.4"
}
},
"types": "./index.d.ts"
}

0 comments on commit 2b53f2a

Please sign in to comment.