abstract-events

    0.0.2-alpha • Public • Published

    Welcome to abstract-events

    Version Maintenance License: MIT

    Abstract events in JS

    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.

    Parameter Type Description
    options object Required. Settings to define the abstract event.
    callback function Required. Function to be called once the abstract event conditions are met

    options

    Field Type Description
    type string Required. Type of event. Value must be either count or phrase
    count number Required if type is count. Number of times the event is raised before calling the callback function.
    phrase string Required if type is phrase. String to listen for before calling the callback function.
    timeout number Optional. 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

    Install

    npm i abstract-events

    DownloadsWeekly Downloads

    0

    Version

    0.0.2-alpha

    License

    MIT

    Unpacked Size

    10.9 kB

    Total Files

    5

    Last publish

    Collaborators

    • zachnology