Skip to content

Commit 1c18e97

Browse files
committed
Merge pull request DefinitelyTyped#4237 from ToastHawaii/master
Add type definitions for Egg.js
2 parents 7acdb48 + 8032fe7 commit 1c18e97

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

egg.js/egg.js-tests.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path="egg.js.d.ts" />
2+
3+
var egg = new Egg();
4+
egg
5+
.addCode("up,up,down,down,left,right,left,right,b,a", function () {
6+
alert("Konami!");
7+
}, "konami-code")
8+
.addHook(function () {
9+
console.log("Hook called for: " + this.activeEgg.keys);
10+
console.log(this.activeEgg.metadata);
11+
})
12+
.listen();
13+
14+
var egg = new Egg("up,up,down,down,left,right,left,right,b,a", function () {
15+
alert("Konami!");
16+
}).listen();
17+
18+
// EGGSAMPLE
19+
var egg = new Egg();
20+
egg
21+
.AddCode("up,up,down,down,left,right,left,right,b,a", function () {
22+
alert("Konami!");
23+
}, "konami-code")
24+
.AddHook(function () {
25+
console.log("Hook called for: " + this.activeEgg.keys);
26+
console.log(this.activeEgg.metadata);
27+
}).Listen();

egg.js/egg.js.d.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Type definitions for Egg.js 0.0.1
2+
// Project: https://github.com/mikeflynn/egg.js/
3+
// Definitions by: Markus Peloso <https://github.com/ToastHawaii/>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
declare var egg: Egg;
7+
8+
declare module "egg" {
9+
export = egg;
10+
}
11+
12+
/**
13+
* Egg.js is a simple JS library that has no prerequisites and allows you to easily add web easter
14+
* eggs by watching the user's key strokes.
15+
*/
16+
declare class Egg {
17+
/**
18+
* Egg.js is a simple JS library that has no prerequisites and allows you to easily add web easter
19+
* eggs by watching the user's key strokes.
20+
*/
21+
constructor();
22+
/**
23+
* Egg.js is a simple JS library that has no prerequisites and allows you to easily add web easter
24+
* eggs by watching the user's key strokes.
25+
* @param keySequence You need to pass it the character sequence to trigger the easter egg
26+
* callback (which can either be in plain English or JavaScript key codes).
27+
* @param fn A function to trigger when it happens.
28+
*/
29+
constructor(keySequence: string, fn: () => any);
30+
/**
31+
* Egg.js is a simple JS library that has no prerequisites and allows you to easily add web easter
32+
* eggs by watching the user's key strokes.
33+
* @param keySequence You need to pass it the character sequence to trigger the easter egg
34+
* callback (which can either be in plain English or JavaScript key codes).
35+
* @param fn A function to trigger when it happens.
36+
* @param metadata An optional set of metadata.
37+
*/
38+
constructor(keySequence: string, fn: () => any, metadata: any);
39+
/**
40+
* Use to add in your easter eggs.
41+
* @param keySequence You need to pass it the character sequence to trigger the easter egg
42+
* callback (which can either be in plain English or JavaScript key codes).
43+
* @param fn A function to trigger when it happens.
44+
*/
45+
AddCode(keySequence: string, fn: () => any): Egg;
46+
/**
47+
* Use to add in your easter eggs.
48+
* @param keySequence You need to pass it the character sequence to trigger the easter egg
49+
* callback (which can either be in plain English or JavaScript key codes).
50+
* @param fn A function to trigger when it happens.
51+
* @param metadata An optional set of metadata.
52+
*/
53+
AddCode(keySequence: string, fn: () => any, metadata: any): Egg;
54+
/**
55+
* Add a hook, that will run after any egg code is triggered. You could use it to fire a Google
56+
* Analytics event or send out a tweet that someone finally found your easter egg. Hooks get
57+
* access to the whole Egg.js object so you can pull information about the easter egg that
58+
* fired via this.activeEgg.
59+
* @param fn A function to trigger when it happens.
60+
*/
61+
AddHook(fn: () => any): Egg;
62+
/**
63+
* Start listening to key codes.
64+
*/
65+
Listen(): Egg;
66+
/**
67+
* Use to add in your easter eggs.
68+
* @param keySequence You need to pass it the character sequence to trigger the easter egg
69+
* callback (which can either be in plain English or JavaScript key codes).
70+
* @param fn A function to trigger when it happens.
71+
*/
72+
addCode(keySequence: string, fn: () => any): Egg;
73+
/**
74+
* Use to add in your easter eggs.
75+
* @param keySequence You need to pass it the character sequence to trigger the easter egg
76+
* callback (which can either be in plain English or JavaScript key codes).
77+
* @param fn A function to trigger when it happens.
78+
* @param metadata An optional set of metadata.
79+
*/
80+
addCode(keySequence: string, fn: () => any, metadata: any): Egg;
81+
/**
82+
* Add a hook, that will run after any egg code is triggered. You could use it to fire a Google
83+
* Analytics event or send out a tweet that someone finally found your easter egg. Hooks get
84+
* access to the whole Egg.js object so you can pull information about the easter egg that
85+
* fired via this.activeEgg.
86+
* @param fn A function to trigger when it happens.
87+
*/
88+
addHook(fn: () => any): Egg;
89+
/**
90+
* Start listening to key codes.
91+
*/
92+
listen(): Egg;
93+
}

0 commit comments

Comments
 (0)