Etiam porta sem malesuada magna mollis euismod.
34 |├── .babelrc ├── .eslintrc ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .npmignore ├── CONTRIBUTING.md ├── LICENCE.txt ├── README.md ├── dist └── typemate.js ├── package.json ├── src └── typemate.js ├── tests.js ├── tests.json └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "targets": { 5 | "browsers": ["last 2 versions", "safari >= 7"] 6 | } 7 | }] 8 | ], 9 | "plugins": ["transform-object-rest-spread"] 10 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "browser": true, 5 | "commonjs": true, 6 | "es6": true, 7 | "node": true 8 | }, 9 | "rules": { 10 | "no-const-assign": "warn", 11 | "no-this-before-super": "warn", 12 | "no-unreachable": "warn", 13 | "no-unused-vars": "warn", 14 | "constructor-super": "warn", 15 | "valid-typeof": "warn", 16 | "quotes": [2, "single", { "allowTemplateLiterals": true }] 17 | } 18 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Expected Behavior 2 | 3 | 4 | ## Actual Behavior 5 | 6 | 7 | ## Steps to Reproduce the Problem 8 | 9 | 1. 10 | 1. 11 | 1. 12 | 13 | ## Specifications 14 | 15 | - Version: 16 | - Platform: 17 | - Browser: 18 | - Environment/Url: -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes Issue # (Delete if not applicable) 2 | 3 | ## Proposed Changes 4 | 5 | - 6 | - 7 | - 8 | 9 | ## Add a GIF that demonstrates how this Pull Request makes you feel (optional) 10 |  -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | .debug 4 | .vscode 5 | node_modules 6 | package-lock.json 7 | yarn.lock 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | tests.* -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. 11 | 2. Ensure your work is thoroughly tested, to the best of your abilities 12 | 2. You may merge the Pull Request in once you have the sign-off from a maintainer 13 | 14 | ## Code of Conduct 15 | 16 | ### Our Pledge 17 | 18 | In the interest of fostering an open and welcoming environment, we as 19 | contributors and maintainers pledge to making participation in our project and 20 | our community a harassment-free experience for everyone, regardless of age, body 21 | size, disability, ethnicity, gender identity and expression, level of experience, 22 | nationality, personal appearance, race, religion, or sexual identity and 23 | orientation. 24 | 25 | ### Our Standards 26 | 27 | Examples of behavior that contributes to creating a positive environment 28 | include: 29 | 30 | - Using welcoming and inclusive language 31 | - Being respectful of differing viewpoints and experiences 32 | - Gracefully accepting constructive criticism 33 | - Focusing on what is best for the community 34 | - Showing empathy towards other community members 35 | 36 | Examples of unacceptable behavior by participants include: 37 | 38 | - The use of sexualized language or imagery and unwelcome sexual attention or 39 | advances 40 | - Trolling, insulting/derogatory comments, and personal or political attacks 41 | - Public or private harassment 42 | - Publishing others' private information, such as a physical or electronic 43 | address, without explicit permission 44 | - Other conduct which could reasonably be considered inappropriate in a 45 | professional setting 46 | 47 | ### Our Responsibilities 48 | 49 | Project maintainers are responsible for clarifying the standards of acceptable 50 | behavior and are expected to take appropriate and fair corrective action in 51 | response to any instances of unacceptable behavior. 52 | 53 | Project maintainers have the right and responsibility to remove, edit, or 54 | reject comments, commits, code, wiki edits, issues, and other contributions 55 | that are not aligned to this Code of Conduct, or to ban temporarily or 56 | permanently any contributor for other behaviors that they deem inappropriate, 57 | threatening, offensive, or harmful. 58 | 59 | ### Scope 60 | 61 | This Code of Conduct applies both within project spaces and in public spaces 62 | when an individual is representing the project or its community. Examples of 63 | representing a project or community include using an official project e-mail 64 | address, posting via an official social media account, or acting as an appointed 65 | representative at an online or offline event. Representation of a project may be 66 | further defined and clarified by project maintainers. 67 | 68 | ### Enforcement 69 | 70 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 71 | reported by contacting the project team at andy@hankchizljaw.io. All 72 | complaints will be reviewed and investigated and will result in a response that 73 | is deemed necessary and appropriate to the circumstances. The project team is 74 | obligated to maintain confidentiality with regard to the reporter of an incident. 75 | Further details of specific enforcement policies may be posted separately. 76 | 77 | Project maintainers who do not follow or enforce the Code of Conduct in good 78 | faith may face temporary or permanent repercussions as determined by other 79 | members of the project's leadership. 80 | 81 | ### Attribution 82 | 83 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 84 | available at [http://contributor-covenant.org/version/1/4][version] 85 | 86 | [homepage]: http://contributor-covenant.org 87 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /LICENCE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 hankchizljaw.io and other contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TypeMate 2 | TypeMate is a little JavaScript module that fixes your typesetting woes automatically. Right now it only fixes orphans, but the plan is to add more filters in the future that fix other typesetting issues such as line-length. 3 | 4 | ## Getting started 5 | 6 | Install it as a dependancy with npm: 7 | 8 | ```bash 9 | npm install typemate 10 | ``` 11 | 12 | Then import it: 13 | 14 | ```javascript 15 | import TypeMate from 'typemate'; 16 | ``` 17 | 18 | At its most basic level, we create `TypeMate` instance and it'll look for all of the `
` elements on your page.
19 |
20 | ```javascript
21 | const typeMateInstance = new TypeMate();
22 |
23 | // Run it
24 | typeMateInstance.apply();
25 | ```
26 |
27 | 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.
28 |
29 | Take this markup sample:
30 |
31 | ```html
32 | Etiam porta sem malesuada magna mollis euismod.
` element within `article#content` will be affected by TypeMate. 48 | 49 | ## Settings 50 | You can pass an object of settings as the second parameter when you construct TypeMate. Using the instantiation example from above, we'll add some settings like so: 51 | 52 | ```javascript 53 | const articleElement = document.getElementById('content'); 54 | const typeMateInstance = new TypeMate(articleElement, { selector: 'h2, p' }); 55 | 56 | // Run it 57 | typeMateInstance.apply(); 58 | ``` 59 | 60 | That settings object now allows `
Etiam porta sem malesuada.
Etiam porta sem malesuada.
tag": { 8 | "init": "
Etiam porta sem malesuada magna mollis euismod.
Maecenas sed diam eget risus varius blandit sit amet non magna.
", 9 | "apply": "Etiam porta sem malesuada magna mollis euismod.
Maecenas sed diam eget risus varius blandit sit amet non magna.
" 10 | }, 11 | "Fewer than minWords (default 4) settings has no affect": { 12 | "init": "Etiam porta sem.
", 13 | "apply": "Etiam porta sem.
" 14 | }, 15 | "Tags with the ignoreClass class will be ignored": { 16 | "init": "Etiam porta sem malesuada.
Maecenas sed diam eget risus varius blandit sit amet non magna.
", 17 | "apply": "Etiam porta sem malesuada.
Maecenas sed diam eget risus varius blandit sit amet non magna.
" 18 | }, 19 | "Can override minWords setting": { 20 | "settings": { 21 | "minWords": 3 22 | }, 23 | "init": "Etiam porta sem.
", 24 | "apply": "Etiam porta sem.
" 25 | }, 26 | "Can override selector setting": { 27 | "settings": { 28 | "selector": "p,h1" 29 | }, 30 | "init": "Etiam porta sem malesuada.
", 31 | "apply": "Etiam porta sem malesuada.
" 32 | }, 33 | "Can override ignoreClass setting": { 34 | "settings": { 35 | "ignoreClass": "ignore" 36 | }, 37 | "init": "Etiam porta sem malesuada.
", 38 | "apply": "Etiam porta sem malesuada.
" 39 | }, 40 | "Will ignore element if there's 1 or more characters present": { 41 | "settings": { 42 | "ignoreExistingSpaceChars": true 43 | }, 44 | "init": "Some text with an existing character
", 45 | "apply": "Some text with an existing character
" 46 | } 47 | } -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | // Define webpack stuff 2 | var isProduction = process.env.NODE_ENV === 'production'; 3 | var path = require('path'); 4 | var plugins = []; 5 | 6 | var settings = { 7 | libraryName: 'typemate', 8 | inputs: { 9 | js: { 10 | entryPath: '/src/typemate.js' 11 | } 12 | }, 13 | outputs: { 14 | js: { 15 | fileName: 'typemate.js', 16 | path: 'dist' 17 | } 18 | } 19 | }; 20 | var webpack = require('webpack'); 21 | 22 | if(isProduction) { 23 | plugins.push(new webpack.optimize.UglifyJsPlugin({ minimize: true })); 24 | } 25 | 26 | module.exports = { 27 | entry: path.join(__dirname, settings.inputs.js.entryPath), 28 | devtool: 'source-map', 29 | output: { 30 | path: path.join(__dirname, settings.outputs.js.path), 31 | filename: settings.outputs.js.fileName, 32 | library: settings.libraryName, 33 | libraryTarget: 'umd', 34 | umdNamedDefine: true 35 | }, 36 | module: { 37 | rules: [ 38 | { 39 | test: /\.js$/, 40 | exclude: /node_modules/, 41 | use: [ 42 | { 43 | loader: 'babel-loader' 44 | } 45 | ] 46 | } 47 | ] 48 | }, 49 | resolve: { 50 | extensions: ['.js'] 51 | }, 52 | plugins: plugins 53 | }; --------------------------------------------------------------------------------