1.0.0 • Published 3 years ago

use-kanomi-code v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

use-kanomi-code

A zero dependency React hook that listens for a sequence of key presses to unlock a feature. This is usually referred to an easter egg. The default sequence is commonly known as the Kanomi Code: a b.

NPM Version NPM Total Downloads License

Installation

yarn add use-kanomi-code

Usage

import useKanomiCode from 'use-kanomi-code';

const Demo = () => {
  useKanomiCode({
    onUnlock: () => console.log('Unlocked 30 extra lives'),
  });

  return (
    <div>useKanomiCode Demo</div>
  );
};

Options

onUnlock: () => void The callback when the sequence has been completed and the secret unlocked

sequence: string[] An optional key sequence to use instead of the default Kanomi Code. This should be an array of strings that correspond to key events.

onReset: (distance: number) => void An optional callback when a portion of the sequence has been completed, but reset before being unlocked. It is called with the distance through the sequence that was make. For example, it d be invoked with 3 if the they successfully pressed the first 3 keys in the sequence before pressing an incorrect key.

target: HTMLElement An optional target element to listen to events. The default is the window object.

1.0.0

3 years ago

0.0.1

3 years ago