spelledright
v1.0.0
Published
This project is a js library used to facilitate spell checks on HTML pages
Downloads
1
Maintainers
Readme
spelledright
This project is a js library used to facilitate spell checks on XML, HTML pages in English. It wraps around cfinke/Typo.js. You can directly take the spelledright.js file and add it to your project.
The Mechanism
The way it works is by:
- Parsing all children under a specified XML Node.
- Gathering all elements innertext
- Going throws the gat hered innertext and (logically) breaking it up into words
- Performing a spelling check on each word according to the desired options config
Example Usage
// 1) Load a page using a UI test driver ex.
// selenium-webdriver (https://www.npmjs.com/package/selenium-webdriver)
let driver = new webdriver.Builder().forBrowser('firefox').build();
driver.get(URL).then(() => {
// 2) Get the target node to perform checks on the target children
return driver.executeScript(`
return document.getElementsByTagName('body')[0];
`);
}).then(node => {
// 3) Return the inner HTML (Library initialization as string node is supported)
return node.getInnerHtml();
}).then(inner => {
// 4) Use the library with your asserts, or logs
let spelledright = new SpelledRight(inner, {
ignoreCase: false,
ignoreComments: true,
whitelist: [/^[A-Z]+$/ /* All caps letters */]
});
console.log('Misspellings are: ' +
JSON.stringify(spelledright.getMisspellings()));
return driver.quit();
})
Note See the spec files for concrete examples.
Additional Usage
To run this project locally, or contribute:
npm install
Make sure everything is installed.
- 2)
grunt babel
Convert es6 files to the js counterparts. npm run-script unittest && npm run-script perftest
Make sure tests are working.
grunt watch
Anytime before developing. Note: The project is linted extend from google.
- Develop!
- Don't forget to add tests and test it out! Let's aim to keep coverage >= 93% Performance benchmarks should be roughly:
- DETAILED_PAGE_BENCHMARK: 1040.511ms
- SIMPLE_PAGE_BENCHMARK: 752.908ms
npm build
To ensure everything is in working order.
- Now we're talking, make a PR upstream.