ng-konami
Index
About
A light-weight service for handling secret codes such as The Konami Code within any Angular 2+ app.
- Try out the demo to see it in action!
- Visit my website for other cool projects!
Setup
Install Node
npm install ng-konami --save
Import module
-
Import
NgKonamiModule
by adding the following to your parent module (i.e.app.module.ts
):import { NgKonamiModule } from 'ng-konami'; @NgModule({ ... imports: [ NgKonamiModule, ... ], ... }) export class AppModule {}
Listen for Keyboard Events
```
constructor(
private service:NgKonamiService
) {
}
@HostListener('window:keyup', ['$event'])
keyEvent(event:KeyboardEvent) {
this.events.push(event);
this.service.listen(event);
}
```
Register Secret Code
```
constructor(
private service:NgKonamiService
) {
this.service.register(
'ArrowUp,ArrowUp,ArrowDown,ArrowDown,ArrowLeft,ArrowRight,ArrowLeft,ArrowRight,b,a',
() => {
// do something
}
);
}
```
Documentation
Functions
register()
- Register a particular sequence of keyboard characters (in CSV format).- Keyboard characters can be differentiated by the KeyboardEvent's key or code
listen()
- Pass the keyboard events through to listen for the secret coderemoveAll()
- Remove all registered codes
Contributing
Thanks
Issues
If you find any issues feel free to open a request in the Issues tab. If I have the time I will try to solve any issues but cannot make any guarantees. Feel free to contribute yourself.
Deploy
Demo
- Run
npm install
to get packages required for the demo and then runnpm run demo
to run locally.
Generate Docs
- Run
npm run docs:build
Update Version
- Update version
package.json
files in both the root anddist/
directory following Semantic Versioning (2.0.0).
Build
- Run
npm run build
from root.
Test
- Copy
dist/
contents intodemo/node_modules/ng-konami/
- Run from root:
cp -fr dist/* demo/node_modules/ng-konami/
- Run from root:
- Run
ng serve
fromdemo/
- Run
ng build --prod
fromdemo/
NPM Release
- Run
npm publish
fromdist/
directory.
Update Changelog
- Add updates to
CHANGELOG.md
in root.