Etiam porta sem malesuada magna mollis euismod.
A little JavaScript module that fixes your typesetting Edit
npm install typemateInstall it as a dependancy with npm:
``bash`
npm install typemate
Then import it:
`javascript`
import TypeMate from 'typemate';
At its most basic level, we create TypeMate instance and it'll look for all of the
elements on your page.
`javascript
const typeMateInstance = new TypeMate();
// Run it
typeMateInstance.apply();
`
You can also pass it a parent element to work with. This is really useful if you only want TypeMate to focus on a particular element, such as an article.
Take this markup sample:
` Etiam porta sem malesuada magna mollis euismod.html`
We can target that particular article's content like so:
`javascript
const articleElement = document.getElementById('content');
const typeMateInstance = new TypeMate(articleElement);
// Run it
typeMateInstance.apply();
`
Now, only that
element within article#content will be affected by TypeMate.
`javascript
const articleElement = document.getElementById('content');
const typeMateInstance = new TypeMate(articleElement, { selector: 'h2, p' });
// Run it
typeMateInstance.apply();
`
That settings object now allows
elements within article#content to be processed by TypeMate.$3
| Property | Type | Description | Default Value |
| ------------- | ------ | ---------------------------------------- | ----------------------------------- |
|
minWords | Number | The minimum amount of words that have to be present in an element's content before TypeMate will process it | 4 |
| selector | String | The selector string that's passed to querySelectorAll | 'p' |
| ignoreClass | String | The CSS class that can be added to an element to mark itself as ignorable to TypeMate | 'js-typemate__ignore' |
| ignoreExistingSpaceChars | Boolean | Determine if elements should be ignored if they already contain an character | false |Codepen example
Check out an example of TypeMate over at CodePen: https://codepen.io/hankchizljaw/project/full/ZgpRNy
Running tests
Tests are defined as simple test cases in
tests.json.Each test case can define:
| Key | Type | Description | Default Value |
| ---------- | ------- | --------------------------------------- | ------------- |
|
parent | String | selector of the parent element to use | undefined |
| settings | Object | settings object | null |
| init | String | initial HTML to test against | |
| apply | String | expected HTML after apply() is called | this.init |
| reset | String | expected HTML after reset() is called | this.init |$3
`bash
npm i
npm run test
`$3
`bash
yarn
yarn test
``---
Made with ❤️ by HankChizlJaw and friends.