@gamingmedley/konami.js

1.0.3 • Public • Published

Konami.js Tweet

Konami.js is a JavaScript package that allows web developers to implement an event listener for the Konami code on their web pages. By pressing up, up, down, down, left, right, left, right, B, A, Enter, one or more custom JavaScript functions will execute.

package minified size minzipped size downloads build

Examples

ES6

Install

  • npm install @gamingmedley/konami.js --save or
  • yarn add @gamingmedley/konami.js

Adding an Event Listener

import Konami from '@gamingmedley/konami.js';
Konami.add(() => {
  alert('This will alert every time the Konami code is entered.');
});

Adding a Single-Execution Event Listener

import Konami from '@gamingmedley/konami.js';
Konami.add((unsubscribe) => {
  unsubscribe(); // Unsubscribes the listener from future Konami code entries.
  alert('This will only alert the first time the Konami code is entered.');
});

Removing an Event Listener

import Konami from '@gamingmedley/konami.js';
const unsubscribe = Konami.add(() => {
  alert('This will not alert, because it will have been removed.');
});
unsubscribe();

Methods

add

Queues a function to be executed when the Konami code is entered by the user.

Returns an unsubscribe function. When executed, the unsubscribe function will disable the associated function from executing in future uses of the Konami code.

Parameters

  • function e: The function to be executed when the Konami code is entered by the user. An unsubscribe function is passed as a parameter to it.

remove

The function associated with the ID will no longer execute when the Konami code is entered.

Returns true on success, false on failure.

Parameters

  • string id: The ID of the event to remove.

Readme

Keywords

Package Sidebar

Install

npm i @gamingmedley/konami.js

Weekly Downloads

7

Version

1.0.3

License

MIT

Unpacked Size

7.54 kB

Total Files

4

Last publish

Collaborators

  • charlesstover