1.1.1 • Published 8 months ago

@shgysk8zer0/konami v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Konami Code JS module

CodeQL Node CI Lint Code Base

GitHub license GitHub last commit GitHub release GitHub Sponsors

npm node-current npm bundle size gzipped npm

GitHub followers GitHub forks GitHub stars Twitter Follow

Donate using Liberapay

npm.io

The Konami Code (Japanese: コナミコマンド, Konami Komando, "Konami command"), also commonly referred to as the Contra Code and sometimes the 30 Lives code, is a cheat code that appears in many Konami video games, as well as some non-Konami games. In the original code, the player has to press the following sequence of buttons on the game controller to enable a cheat or other effects:

↑ ↑ ↓ ↓ ← → ← → B A; sometimes Start and/or Select is added to the sequence (usually to start Single player or, Two player modes). ~Konami Code | Wikipedia

Quick Links

About

konami.js enables developers to easily add the Konami Code to their websites. Like other JavaScript solutions, this one adds keyboard listeners and waits for the specifc sequence of keys to be pressed. Unlike other solutions, however, this one:

  • Is a JavaScript module that may be imported
  • Returns a Promise that resolves when the correct sequence is entered and may be awaited
  • Supports AbortSignal
  • Allows specifying the EventTarget via the optional { target }.

Installation

npm

npm i @shgysk8zer0/konami

Git Submodule

git submodule add https://github.com/shgysk8zer0/konami.git js/konami

CDN (unpkg)

const { konami } = await import('https://unpkg.com/@shgysk8zer0/konami');

Updating

Git Submodule

git submodule update --remote -- js/konami

Tip: Use Dependabot to automatically get Pull Requests when a submodule or package is updated.

Options

import { konami } from '/js/konami/konami.js';

await konami({ target, delay, signal, capture });
NameTypeDefault ValueDescription
targetEventTargetglobalThisTarget to listen for input on
delayNumber1000Allowed delay in ms between inputs
signalAbortSignalundefinedSee signal on MDN
captureBooleantrueSee capture on MDN

Example

From Submodule

import { konami } from '/js/konami/konami.js';

konami().then(/* Enter Cheat Mode! */);

From npm

import { konami } from '@shgysk8zer0/konami';
// or const { konami } = require('@shgysk8zer0/konami');

konami().then(/* Enter Cheat Mode! */);

Advanced

From unpkg CDN

const controller = new AbortController();
// This will use version 1.0.5
const { konami } = await import('https://unpkg.com/@shgysk8zer0/konami@1.0.5/konami.js');

try {
  await konami({
    delay: 500,
    target: document.getElementById('konami-target'),
    signal: controller.signal,
    capture: true,
  });

  /* Enter Cheat Mode! */
} catch(err) {
  // Signal was aborted
}

Requirements

Due to use of signal, support is currently limited to browsers supporting AbortSignal & AbortController. Support may be extended to other browser by importing a polyfill.

Supported Browsers

BrowserSupportedVersionReleased
Internet Explorer𐄂
Edge162017-10-16
Safari12.12019-03-24
Chrome662018-04-16
Firefox572017-11-13
Node15?
Deno1.0?
1.1.1

8 months ago

1.1.0

11 months ago

1.0.10

11 months ago

1.0.9

1 year ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago