1.0.2 ā€¢ Published 2 years ago

abstract-events v1.0.2

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

āš” abstract-events āš”

Version Maintenance License: MIT

Live Demo

Install

npm install abstract-events

Usage

const abstractEvents = require('abstract-events');

let someButton = document.getElementById('someButton');
someButton.onclick = abstractEvents.create(
    {
        type: 'count',
        count: 4
    },
    () => alert('You clicked the button 4 times!')
);

let phraseListener = abstractEvents.create(
    {
        type: 'phrase',
        phrase: 's3cr3tP@ssw0rd'
    },
    () => alert("You've activated the admin mode by typing in the secret password!")
);

document.addEventListener('keydown', phraseListener);

API

create(options, callback)

Returns a new event listener that calls the callback function once conditions are met.

ParameterTypeDescription
optionsobjectRequired. Settings to define the abstract event.
callbackfunctionRequired. Function to be called once the abstract event conditions are met

options

FieldTypeDescription
typestringRequired. Type of event. Value must be either count or phrase
countnumberRequired if type is count. Number of times the event is raised before calling the callback function.
phrasestringRequired if type is phrase. String to listen for before calling the callback function.
timeoutnumberOptional. Number of milliseconds (rolling) all triggers must occur within. When the type is count, this is the amount of time all triggers must occur within for the callback function to be called. When the type is phrase, this is the amount time all characters must be typed within for the callback function to be called.

Author

šŸ‘¤ zachnology

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ā­ļø if this project helped you!

šŸ“ License

Copyright Ā© 2021 Zack Gomez.

This project is MIT licensed.


This README was generated with ā¤ļø by readme-md-generator