on-awesome
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

onAwesome

A smol library that responds to the word "awesome" being typed into the browser. It also exports a lower level onWord function that can be used to respond to any word.

How to Use

First, you'll want to install the library:

npm i on-awesome

Then, in your application, you can use it like so:

import { onAwesome } from "on-awesome";

onAwesome(() => {
  alert('You typed the word "awesome"!');
});

API

It returns some utilities to help you manage awesome state:

import { onAwesome } from "on-awesome";

const { cleanUp, isAwesome, reset } = onAwesome(() => {
  alert('You typed the word "awesome"!');
});

Here's what each function does:

  • cleanUp - Removes the event listener that was added to the document.
  • isAwesome - Returns a boolean indicating whether or not the word "awesome" has been typed.
  • reset - Resets the state of the library so that it can be used again.

Lower level onWord API

If you want to respond to a word other than "awesome", you can onhe onWord function:

import { onWord } from "on-awesome";

onWord("ilovetejas", () => {
  alert('You typed the word "ilovetejas"!');
});

Usage in a React App

If you're using this library in a React app, you'll want to use the useEffect hook to clean up the event listener when the component unmounts:

import { useEffect } from "react";
import { onAwesome } from "on-awesome";

const AwesomeComponent = () => {
  useEffect(() => {
    const { cleanUp } = onAwesome(() => {
      alert('You typed the word "awesome"!');
    });
    return cleanUp;
  }, []);

  return <div>Awesome!</div>;
};

Contributing

You're awesome and I want to collaborate with you! Please feel free to open an issue and we can go from there.

Readme

Keywords

none

Package Sidebar

Install

npm i on-awesome

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

7.91 kB

Total Files

10

Last publish

Collaborators

  • tejaskumar