New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

form-mutator

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

form-mutator

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

latest
Source
npmnpm
Version
4.0.7
Version published
Maintainers
1
Created
Source

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.

ParamTypeDescription
elementObjectThe 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.

ParamTypeDescription
elementObjectThe element to deselect from.
valuesArray.<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.

ParamTypeDescription
dataObjectThe selector => value data map.
data.selectorstringThe selector to find desired element.
data.valuemixedThe 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.

ParamTypeDescription
elementObjectThe element to select from.
valuesArray.<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.

ParamTypeDescription
selectorstringThe selector to find desired element.
valuemixedThe 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.

ParamTypeDescription
elementObjectThe element to toggle from.
valuebooleanCheck 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.

ParamTypeDescription
elementObjectThe element to type on.
valuemixedThe 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.

Keywords

fill out

FAQs

Package last updated on 22 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts