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

form-mutator

v4.0.7

Published

A utility to fill out web form and mutate field data programmatically.

Downloads

5

Readme

Version Downloads Dependency Status Dev Dependency Status Code Style Build Coverage Vulnerability Dependabot License

Form Mutator

A utility to fill out web form and mutate field data programmatically.

Browser Download

You can download compressed copy for browser usage.

Node.js Installation

$ npm install --save form-mutator

API Reference

Provide utility to fill out web form and mutate field data programmatically.

Example (Browser usage)

<script type="text/javascript" src="form-mutator.min.js"></script>
<script>
  formMutator.fillOut({
    '[name="fullName"]': 'Your Name',
    '[name="address"]': '1 Awesome Way',
    '[name="city"]': 'Lalaland',
    '[type="submit"]': true,
  });
</script>

Example (Node.js usage)

const formMutator = require('form-mutator');

formMutator.fillOut({
  '[name="fullName"]': 'Your Name',
  '[name="address"]': '1 Awesome Way',
  '[name="city"]': 'Lalaland',
  '[type="submit"]': true,
});

form-mutator.click ⇒ boolean

Click on given element.

Kind: static property of form-mutator
Returns: boolean - Truthy if click triggered, otherwise falsy.

| Param | Type | Description | | --- | --- | --- | | element | Object | The element to click. |

Example

const el = document.querySelector('a[href="/"]');
const response = formMutator.click(el);

form-mutator.deselectByText ⇒ boolean

Deselect given values from dropdown list.

Kind: static property of form-mutator
Returns: boolean - Truthy if deselect triggered, otherwise falsy.

| Param | Type | Description | | --- | --- | --- | | element | Object | The element to deselect from. | | values | Array.<string> | The values to deselect. |

Example

const el = document.querySelector('[name="month"]');
const response = formMutator.deselectByText(el, ['January']);

form-mutator.fillOut ⇒ boolean

Fill out all form field matched given selector => value key-pair. It will skip unknown field type and missing field.

Kind: static property of form-mutator
Returns: boolean - Truthy if the values are set, otherwise false.

| Param | Type | Description | | --- | --- | --- | | data | Object | The selector => value data map. | | data.selector | string | The selector to find desired element. | | data.value | mixed | The value to be set. |

Example

const response = formMutator.fillOut({
  '[name="fullName"]': 'Your Name',
  '[name="address"]': '1 Awesome Way',
  '[name="city"]': 'Lalaland',
  '[type="submit"]': true,
});

form-mutator.selectByText ⇒ boolean

Select given values from dropdown list.

Kind: static property of form-mutator
Returns: boolean - Truthy if select triggered, otherwise falsy.

| Param | Type | Description | | --- | --- | --- | | element | Object | The element to select from. | | values | Array.<string> | The values to select. |

Example

const el = document.querySelector('[name="month"]');
const response = formMutator.selectByText(el, ['January']);

form-mutator.setValue ⇒ boolean

Set given value to input field that match given selector.

Kind: static property of form-mutator
Returns: boolean - Truthy if the value is set, or the field is unknown type or the field can not be found, otherwise false.

| Param | Type | Description | | --- | --- | --- | | selector | string | The selector to find desired element. | | value | mixed | The value to be set. |

Example

const response = formMutator.setValue('[type="text"]', 'value');

form-mutator.toggleCheckbox ⇒ boolean

Toggle the checkbox or radio button field.

Kind: static property of form-mutator
Returns: boolean - Truthy if toggle triggered, otherwise falsy.

| Param | Type | Description | | --- | --- | --- | | element | Object | The element to toggle from. | | value | boolean | Check if true, otherwise uncheck. |

Example

const el = document.querySelector('[type="checkbox"]');
const response1 = formMutator.toggleCheckbox(el, true);  // checked
const response2 = formMutator.toggleCheckbox(el, false); // unchecked

form-mutator.typeValue ⇒ boolean

Type given value to password or text field.

Kind: static property of form-mutator
Returns: boolean - Truthy if type in triggered, otherwise falsy.

| Param | Type | Description | | --- | --- | --- | | element | Object | The element to type on. | | value | mixed | The value to be typed in. |

Example

const el = document.querySelector('[type="text"]');
const response = formMutator.typeValue(el, 'value');

Development Dependencies

You will need to install Node.js as a local development dependency. The npm package manager comes bundled with all recent releases of Node.js.

npm install will attempt to resolve any npm module dependencies that have been declared in the project’s package.json file, installing them into the node_modules folder.

$ npm install

Run Linter

To make sure we followed code style best practice, run:

$ npm run lint

Run Unit Tests

To make sure we did not break anything, let's run:

$ npm test

Contributing

If you would like to contribute code to Form Mutator repository you can do so through GitHub by forking the repository and sending a pull request.

If you do not agree to Contribution Agreement, do not contribute any code to Form Mutator repository.

When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. Please also include appropriate test cases.

That's it! Thank you for your contribution!

License

Copyright (c) 2018 - 2020 Richard Huang.

This utility is free software, licensed under: Mozilla Public License (MPL-2.0).

Documentation and other similar content are provided under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.