Skip to content

Commit

Permalink
Merge pull request #3 from EGAMAGZ/development
Browse files Browse the repository at this point in the history
Documentation improvement
  • Loading branch information
EGAMAGZ authored Apr 27, 2024
2 parents 6ea8dd3 + 0d02209 commit 927a6f8
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 2 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Gamaliel Garcia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Paska Ovo

A simple javascript library for adding easter eggs to web pages

## Installation

### For Deno

```bash
deno add @egamagz/paska-ovo
```

### For Node.js

```bash
npx jsr add @egamagz/paska-ovo
```

### For Bun

```bash
bunx jsr add @egamagz/paska-ovo
```

### For other package managers

Check the [JSR page for more details](https://jsr.io/@egamagz/paska-ovo).

## Example

```typescript
import { HistoricalCodes, PaskaOvo } from "@egamagz/paska-ovo";

const paskaOvo = new PaskaOvo()
.addCallback((easterEgg) => {
console.log("Actual easter egg:", easterEgg.tag);
console.log("Easter egg's code:", easterEgg.code);
})
.addCode(
HistoricalCodes.Iddqd,
() => {
alert("God Mode");
},
"Doom",
)
.addCode("left,up,right,down", () => {
alert("Do a Barrel Roll");
}, "Barrel Roll");

// Listen to keyboard events
document.getElementById("add-easter-egg")
.addEventListener("click", () => {
paskaOvo.listen();
});

// Stop listening to keyboard events
document.getElementById("remove-easter-egg")
.addEventListener("click", () => {
paskaOvo.stop();
});

```

Alternatively, it's possible to define the easter egg using the constructor:

```typescript
import { HistoricalCodes, PaskaOvo } from "@egamagz/paska-ovo";

const paskaOvo = new PaskaOvo(
HistoricalCodes.Konami,
() => {
alert("Gradius");
},
"konami-code",
)
.addCallback((easterEgg) => {
console.log("Actual easter egg:", easterEgg.tag);
console.log("Easter egg's code:", easterEgg.code);
});

paskaOvo.listen();
```

## Credits

Inspired by the project [Egg.js](https://github.com/mikeflynn/egg.js). Created by [EGAMAGZ](https://github.com/EGAMAGZ).

## License

MIT License
31 changes: 29 additions & 2 deletions src/paska-ovo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@ import { codeToChars } from "./util/code.ts";

/**
* This class represents the PaskaOvo class.
*
* @example
* ```typescript
* import { HistoricalCodes, PaskaOvo } from "@egamagz/paska-ovo";
*
* const paskaOvo = new PaskaOvo()
* .addCallback((easterEgg) => {
* console.log("Actual easter egg:", easterEgg.tag);
* console.log("Easter egg's code:", easterEgg.code);
* })
* .addCode(
* HistoricalCodes.Iddqd,
* () => {
* alert("God Mode");
* },
* "Doom",
* )
* .addCode("left,up,right,down", () => {
* alert("Do a Barrel Roll");
* }, "Barrel Roll");
*
* paskaOvo.listen();
*
* // ...
*
* paskaOvo.stop()
* ```
*/
export class PaskaOvo {
private easterEggs: EasterEgg[] = [];
Expand All @@ -35,9 +62,9 @@ export class PaskaOvo {
* Adds an easter egg to the easterEggs array of the current instance of PaskaOvo.
*
* @param {string} code - Sequence of keys to trigger the easter egg.
* @param {() => void} fn - Function to execute when the easter egg is triggered.
* @param {() => void} callback - Function to execute when the easter egg is triggered.
* @param {string} tag - Tag to identify the easter egg.
* @return {this} - Current instance of PaskaOvo.
* @return {this} Current instance of PaskaOvo.
*/
public addCode(code: string, callback: () => void, tag: string): this {
this.easterEggs.push({ code: codeToChars(code), callback, tag });
Expand Down

0 comments on commit 927a6f8

Please sign in to comment.