npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mie-simulijs

v1.1.8

Published

It helps to simulate events on a webpage

Downloads

33

Readme

mie-simulijs

mie-simulijs is a JavaScript library that helps simulate events on a webpage. It can simulate mouse and keyboard events programmatically.

Usage

Here is how you can use the mie-simulijs library to simulate click and keypress events.

Using CDN

Include the following script tag in your HTML file:

<script src="https://unpkg.com/mie-simulijs"></script>

Simulating Click Event

Create an HTML file (e.g., click-test.html) with the following content:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simulijs Click Test</title>
    <script src="https://unpkg.com/mie-simulijs"></script>
</head>
<body>
    <h1>Simulijs Click Test</h1>

    <button id="testButton">Click me</button>
    <div id="clickResult"></div>

    <script>
        // Ensure simulijs is accessible
        const { simulateClick } = window.simulijs;

        // Select the element
        const testButton = document.getElementById('testButton');
        const clickResult = document.getElementById('clickResult');

        // Add event listener to log event
        testButton.addEventListener('click', () => {
            clickResult.textContent = 'Button was clicked!';
            console.log('Button was clicked!');
        });

        // Simulate events using simulijs
        window.onload = () => {
            // Simulate a button click
            simulateClick(testButton);
        };
    </script>
</body>
</html>

Simulating Keypress Event

Create an HTML file (e.g., keypress-test.html) with the following content:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simulijs Keypress Test</title>
    <script src="https://unpkg.com/mie-simulijs"></script>
</head>
<body>
    <h1>Simulijs Keypress Test</h1>

    <input type="text" id="testInput" placeholder="Type something here">
    <div id="keypressResult"></div>

    <script>
        // Ensure simulijs is accessible
        const { simulateKeyPress } = window.simulijs;

        // Select the element
        const testInput = document.getElementById('testInput');
        const keypressResult = document.getElementById('keypressResult');

        // Add event listener to log event
        testInput.addEventListener('keydown', (event) => {
            keypressResult.textContent = `Key "${event.key}" was pressed!`;
            console.log(`Key "${event.key}" was pressed!`);
        });

        // Simulate events using simulijs
        window.onload = () => {
            // Simulate a key press
            simulateKeyPress(testInput, 'a');
        };
    </script>
</body>
</html>

Using npm

If you prefer to use npm, you can install the package and include it in your project:

npm install mie-simulijs

Then, you can require it in your JavaScript files:

const simulijs = require('mie-simulijs');

Functions

simulateClick

Simulates a mouse click on a given element.

Parameters

  • element (HTMLElement): The element to click.
  • options (Object): Optional settings.
    • button (String): The mouse button to use for the click. Default is 'left'. Possible values are 'left', 'middle', and 'right'.
    • callback (Function): A function to call after the click event is dispatched.
    • delay (Number): The delay before the click event is dispatched, in milliseconds. Default is 100.

Example

simulijs.simulateClick(document.getElementById('myButton'), {
  button: 'right',
  callback: () => console.log('Right click simulated!'),
  delay: 200
});

simulateKeyPress

Simulates a key press on a given element.

Parameters

  • element (HTMLElement): The element to type into.
  • key (String): The key to simulate.
  • callback (Function): A function to call after the key press event is dispatched.
  • delay (Number): The delay before the key press event is dispatched, in milliseconds. Default is 100.

Example

simulijs.simulateKeyPress(document.getElementById('myInput'), 'a', () => console.log('Key press simulated!'));

simulateKeyDown

Simulates a key down event on the document.

Parameters

  • keyCode (Number): The key code of the key to simulate.
  • callback (Function): A function to call after the key down event is dispatched.
  • delay (Number): The delay before the key down event is dispatched, in milliseconds. Default is 100.

Example

simulijs.simulateKeyDown(13, () => console.log('Enter key down simulated!'));

simulateKeyUp

Simulates a key up event on the document.

Parameters

  • keyCode (Number): The key code of the key to simulate.
  • callback (Function): A function to call after the key up event is dispatched.
  • delay (Number): The delay before the key up event is dispatched, in milliseconds. Default is 100.

Example

simulijs.simulateKeyUp(13, () => console.log('Enter key up simulated!'));

simulateMouseEnter

Simulates a mouse enter event on a given element.

Parameters

  • element (HTMLElement): The element to simulate the event on.
  • callback (Function): A function to call after the mouse enter event is dispatched.
  • delay (Number): The delay before the mouse enter event is dispatched, in milliseconds. Default is 100.

Example

simulijs.simulateMouseEnter(document.getElementById('myDiv'), () => console.log('Mouse enter simulated!'));

simulateMouseLeave

Simulates a mouse leave event on a given element.

Parameters

  • element (HTMLElement): The element to simulate the event on.
  • callback (Function): A function to call after the mouse leave event is dispatched.
  • delay (Number): The delay before the mouse leave event is dispatched, in milliseconds. Default is 100.

Example

simulijs.simulateMouseLeave(document.getElementById('myDiv'), () => console.log('Mouse leave simulated!'));

simulateFocus

Simulates a focus event on a given element.

Parameters

  • element (HTMLElement): The element to simulate the event on.
  • callback (Function): A function to call after the focus event is dispatched.
  • delay (Number): The delay before the focus event is dispatched, in milliseconds. Default is 100.

Example

simulijs.simulateFocus(document.getElementById('myInput'), () => console.log('Focus simulated!'));

simulateChange

Simulates a change event on a given element.

Parameters

  • element (HTMLElement): The element to simulate the event on.
  • callback (Function): A function to call after the change event is dispatched.
  • delay (Number): The delay before the change event is dispatched, in milliseconds. Default is 100.

Example

simulijs.simulateChange(document.getElementById('mySelect'), () => console.log('Change simulated!'));

simulationSelector

Selects an element based on various criteria (ID, class, XPath, etc.) and returns the element if found.

Parameters

  • value (String): The value used to select the element. It can be an ID, class, CSS selector, or XPath.

Example

const element = simulijs.simulationSelector('#myId');
if (element) {
  console.log('Element found!', element);
} else {
  console.log('Element not found!');
}

Usage

Include the SimuliJS library in your project and use the provided functions to simulate user interactions.

<script src="path/to/simulijs.js"></script>
<script>
  // Example usage
  simulijs.simulateClick(document.getElementById('myButton'));
</script>

SimuliJS makes it easy to automate and test user interactions on your web pages.