Skip to content

CLI tool that converts jQuery to ES6 vanilla JavaScript (available as npm package)

License

Notifications You must be signed in to change notification settings

dongskyler/vaniquery

Repository files navigation

Vaniquery

Homepage: https://github.com/BadwaterBay/vaniquery

npm version Node.js CI codecov CodeFactor DeepScan grade License: MIT

GitHub issues GitHub issues-closed GitHub pull-requests GitHub pull-requests closed


Table of contents


Thank you, contributors

We'd like to thank all of our contributors.


Description

This command line interface (CLI) tool helps you convert jQuery to vanilla JavaScript.

Once upon a time, jQuery offers great convenience to JavaScript developers. However, now vanilla JavaScript has been improved and standardized across all modern browsers. More often than you think, you don't always need jQuery. Removing jQuery dependency means your web app can be loaded faster. It also makes it easier when you migrate your existing web app to more modern libraries or frameworks, such as React.

This app helps you convert jQuery syntax to vanilla JavaScript ones.


Installation and usage

To install this tool on your machine, use commands npm i -g vaniquery or yarn global add vaniquery.

Available commands:

  • vaniquery vanilla path/to/file: Convert jQuery to vanilla JavaScript in a file.
  • vaniquery revert path/to/file: Revert vanillaization in a file given its corresponding cache file.

Options:

  • --help: Show help.
  • --version: Show version number.
  • -c, --cache: Cache the original file (Default).
  • -C, --no-cache: Do not cache the original file (Not recommended).
  • -v, --verbose: Show the code being worked on.

Available conversions from jQuery to vanilla JavaScript

  • .addClass()
  • .append()
  • .attr()
  • .children()
  • $('.class')
  • .click()
  • .closest()
  • $('[data-foo="val"]') (select by attribute)
  • $('div')
  • $(document).ready()...
  • .each()
  • $(function ()... (shorthand for $(document).ready())
  • .find()
  • .hasClass()
  • $('#id') (select by ID)
  • .keyup()
  • .mouseenter()
  • .parent()
  • .prop('checked')
  • .removeAttr()
  • .removeClass()
  • .text()
  • $(this)
  • .toggleClass()
  • .val() (get the value)

Contributing to this project

Please refer to our Contributing Guidelines.