├── .babelrc ├── .circleci └── config.yml ├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .npmignore ├── .nvmrc ├── CHANGELOG.md ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── dist ├── jquery.shave.js ├── jquery.shave.min.js ├── shave.es.js ├── shave.js └── shave.min.js ├── package.json ├── renovate.json ├── rollup.config.js ├── scripts └── acceptance.js ├── src ├── jquery.shave.js └── shave.js ├── tests ├── index.html └── tests.js ├── tsconfig.json ├── types └── index.d.ts └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/preset-env", 5 | { 6 | "modules": false, 7 | "targets": { 8 | "browsers": [ 9 | "defaults", 10 | "ie >= 8" 11 | ] 12 | } 13 | } 14 | ] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | defaults: &defaults 2 | working_directory: ~/code 3 | docker: 4 | - image: circleci/node:10 5 | environment: 6 | NPM_CONFIG_LOGLEVEL: error # make npm commands less noisy 7 | JOBS: max # https://gist.github.com/ralphtheninja/f7c45bdee00784b41fed 8 | 9 | version: 2 10 | jobs: 11 | build: 12 | <<: *defaults 13 | steps: 14 | - checkout 15 | - run: npm install 16 | - run: npm run eslint:ci 17 | - run: npm run build 18 | - run: npm test 19 | 20 | workflows: 21 | version: 2 22 | all: 23 | jobs: 24 | - build 25 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.js] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.hbs] 21 | insert_final_newline = false 22 | indent_style = space 23 | indent_size = 2 24 | 25 | [*.css] 26 | indent_style = space 27 | indent_size = 2 28 | 29 | [*.html] 30 | indent_style = space 31 | indent_size = 2 32 | 33 | [*.{diff,md}] 34 | trim_trailing_whitespace = false 35 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/* 2 | tests/* 3 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ "dollarshaveclub"], 3 | "rules": { 4 | "indent": 2, 5 | "semi": [2, "never"], 6 | "no-continue": 0 7 | }, 8 | "globals": { 9 | "document": true, 10 | "window": true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## What Is the issue? 2 | 3 | ## Provide issue context below using code examples, images, or links 4 | 5 | ---- 6 | 7 | > Read about references issues [here](https://help.github.com/articles/closing-issues-using-keywords/). Provide paragraph text responses to each header. 8 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Fixes 2 | 3 | - Fixes # 4 | 5 | ## Proposed Changes 6 | 7 | - Change 8 | 9 | ---- 10 | 11 | > Read about referenced issues [here](https://help.github.com/articles/closing-issues-using-keywords/). Replace words with this Pull Request's context. 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bower_components/* 2 | node_modules/* 3 | .tags 4 | .tags1 5 | package-lock.json 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | gulpfile.js 2 | rollup.config.js 3 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [2.5.7](https://github.com/dollarshaveclub/shave/compare/2.5.6...2.5.7) (2019-12-05) 2 | 3 | 4 | 5 | 6 | ## [2.5.6](https://github.com/dollarshaveclub/shave/compare/2.5.4...2.5.6) (2019-10-21) 7 | 8 | 9 | 10 | 11 | ## [2.5.4](https://github.com/dollarshaveclub/shave/compare/2.5.3...2.5.4) (2019-06-25) 12 | 13 | 14 | 15 | 16 | ## [2.5.3](https://github.com/dollarshaveclub/shave/compare/2.5.2...2.5.3) (2019-04-17) 17 | 18 | 19 | 20 | 21 | ## [2.5.2](https://github.com/dollarshaveclub/shave/compare/2.5.1...2.5.2) (2018-10-09) 22 | 23 | 24 | 25 | 26 | ## [2.5.1](https://github.com/dollarshaveclub/shave/compare/2.5.0...2.5.1) (2018-09-06) 27 | 28 | 29 | 30 | 31 | # [2.5.0](https://github.com/dollarshaveclub/shave/compare/2.4.0...2.5.0) (2018-09-06) 32 | 33 | 34 | 35 | 36 | # [2.4.0](https://github.com/dollarshaveclub/shave/compare/2.3.0...2.4.0) (2018-08-10) 37 | 38 | 39 | 40 | 41 | # [2.3.0](https://github.com/dollarshaveclub/shave/compare/2.2.2...2.3.0) (2018-08-04) 42 | 43 | 44 | 45 | 46 | ## [2.2.2](https://github.com/dollarshaveclub/shave/compare/2.2.1...2.2.2) (2018-07-17) 47 | 48 | 49 | 50 | 51 | ## [2.2.1](https://github.com/dollarshaveclub/shave/compare/2.2.0...2.2.1) (2018-06-27) 52 | 53 | 54 | 55 | 56 | # [2.2.0](https://github.com/dollarshaveclub/shave/compare/2.1.7...2.2.0) (2018-06-24) 57 | 58 | 59 | 60 | 61 | ## [2.1.7](https://github.com/dollarshaveclub/shave/compare/2.1.3...2.1.7) (2018-06-06) 62 | 63 | 64 | 65 | 66 | ## [2.1.2](https://github.com/dollarshaveclub/shave/compare/2.0.4...2.1.2) (2017-09-14) 67 | 68 | 69 | 70 | 71 | ## [2.0.4](https://github.com/dollarshaveclub/shave/compare/2.0.3...2.0.4) (2017-07-17) 72 | 73 | 74 | 75 | 76 | ## [2.0.3](https://github.com/dollarshaveclub/shave/compare/2.0.0...2.0.3) (2017-07-10) 77 | 78 | 79 | 80 | 81 | # [2.0.0](https://github.com/dollarshaveclub/shave/compare/1.0.4...2.0.0) (2017-05-18) 82 | 83 | 84 | 85 | 86 | ## [1.0.4](https://github.com/dollarshaveclub/shave/compare/1.0.3...1.0.4) (2017-01-23) 87 | 88 | 89 | 90 | 91 | ## [1.0.3](https://github.com/dollarshaveclub/shave/compare/1.0.2...1.0.3) (2017-01-02) 92 | 93 | 94 | 95 | 96 | ## [1.0.2](https://github.com/dollarshaveclub/shave/compare/1.0.1...1.0.2) (2017-01-02) 97 | 98 | 99 | 100 | 101 | ## [1.0.1](https://github.com/dollarshaveclub/shave/compare/1.0.0...1.0.1) (2016-12-28) 102 | 103 | 104 | 105 | 106 | # [1.0.0](https://github.com/dollarshaveclub/shave/compare/0.2.3...1.0.0) (2016-12-24) 107 | 108 | 109 | 110 | 111 | ## [0.2.3](https://github.com/dollarshaveclub/shave/compare/0.2.2...0.2.3) (2016-11-22) 112 | 113 | 114 | 115 | 116 | ## [0.2.2](https://github.com/dollarshaveclub/shave/compare/0.2.1...0.2.2) (2016-11-18) 117 | 118 | 119 | 120 | 121 | ## [0.2.1](https://github.com/dollarshaveclub/shave/compare/0.2.0...0.2.1) (2016-11-15) 122 | 123 | 124 | 125 | 126 | # [0.2.0](https://github.com/dollarshaveclub/shave/compare/0.1.8...0.2.0) (2016-11-06) 127 | 128 | 129 | 130 | 131 | ## [0.1.8](https://github.com/dollarshaveclub/shave/compare/0.1.7...0.1.8) (2016-11-02) 132 | 133 | 134 | 135 | 136 | ## [0.1.7](https://github.com/dollarshaveclub/shave/compare/0.1.6...0.1.7) (2016-11-01) 137 | 138 | 139 | ### WIP 140 | 141 | * spread ([502809c](https://github.com/dollarshaveclub/shave/commit/502809c5720519dc92edaeb2a888d95bb16b5dfd)) 142 | 143 | 144 | 145 | ## [0.1.6](https://github.com/dollarshaveclub/shave/compare/0.1.5...0.1.6) (2016-10-30) 146 | 147 | 148 | 149 | 150 | ## [0.1.5](https://github.com/dollarshaveclub/shave/compare/0.1.4...0.1.5) (2016-10-26) 151 | 152 | 153 | 154 | 155 | ## [0.1.4](https://github.com/dollarshaveclub/shave/compare/0.1.3...0.1.4) (2016-10-26) 156 | 157 | 158 | 159 | 160 | ## [0.1.3](https://github.com/dollarshaveclub/shave/compare/0.1.1...0.1.3) (2016-10-22) 161 | 162 | 163 | 164 | 165 | ## [0.1.1](https://github.com/dollarshaveclub/shave/compare/0.1.0...0.1.1) (2016-10-22) 166 | 167 | 168 | 169 | 170 | # [0.1.0](https://github.com/dollarshaveclub/shave/compare/0.0.8...0.1.0) (2016-10-22) 171 | 172 | 173 | 174 | 175 | ## [0.0.8](https://github.com/dollarshaveclub/shave/compare/0.0.7...0.0.8) (2016-10-21) 176 | 177 | 178 | 179 | 180 | ## [0.0.7](https://github.com/dollarshaveclub/shave/compare/0.0.5...0.0.7) (2016-10-21) 181 | 182 | 183 | 184 | 185 | ## [0.0.5](https://github.com/dollarshaveclub/shave/compare/0.0.4...0.0.5) (2016-10-21) 186 | 187 | 188 | 189 | 190 | ## [0.0.4](https://github.com/dollarshaveclub/shave/compare/0.0.3...0.0.4) (2016-10-21) 191 | 192 | 193 | 194 | 195 | ## [0.0.3](https://github.com/dollarshaveclub/shave/compare/0.0.2...0.0.3) (2016-10-21) 196 | 197 | 198 | 199 | 200 | ## [0.0.2](https://github.com/dollarshaveclub/shave/compare/0.0.1...0.0.2) (2016-10-21) 201 | 202 | 203 | 204 | 205 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Stickybits owners 2 | # ---- 3 | * @yowainwright 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4, available at [Contributor Covenant, Code of Conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html) 71 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Jeff Wainwright 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

2 |

3 | 4 | This software is maintained under a new repository located at yowainwright/shave 5 | 6 |

7 |

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

8 | 9 | *** 10 | 11 |

12 | Shave 13 |

14 |
15 |

16 | 17 | npm 18 | 19 | 20 | Bower 21 | 22 | 23 | Travis 24 | 25 | 26 | Greenkeeper 27 | 28 | 29 | CDNJS 30 | 31 | 32 | Twitter share 33 | 34 |

35 | 36 | ---- 37 | 38 |

Shave ✁

39 | 40 | **Shave** is a zero dependency javascript plugin that truncates multi-line text to fit within an html element based on a set pixel number **max-height**. It then stores the _diff_ of the original text string in a hidden `` element following the visible text. This means the original text remains intact! 41 | 42 | **Shave, compared to other truncation plugins:** 43 | - maintains the original text after truncation. 44 | - does not require other libraries 45 | - only requires a selector and a max height 46 | - is very lightweight; `~1.5kb` unminified 47 | - allows for custom ellipsis strings and class names but doesn't over complicate 48 | - is fast and capable of truncating text within lots of elements [quickly](http://codepen.io/pwfisher/full/ozVAyr/) 49 | - is additive. It will play nice with other javascript libraries and more truncation features can easily be built with it. 50 | - supports non-spaced languages ([Non-ascii](https://en.wikipedia.org/wiki/ASCII)). 51 | 52 | ## Installing from a package manager 53 | 54 | npm 55 | 56 | ```sh 57 | 58 | npm install shave --save 59 | 60 | ``` 61 | 62 | bower 63 | 64 | ```sh 65 | 66 | bower install shave --save 67 | 68 | ``` 69 | 70 | yarn 71 | 72 | ```sh 73 | 74 | yarn add shave 75 | 76 | ``` 77 | 78 | ## Usage 79 | 80 | Add **dist/shave.js** to your html 81 | - Or, **dist/jquery.shave.js** for jQuery/Zepto as of Shave >= v2. 82 | 83 | Or as a module 84 | 85 | ```sh 86 | 87 | import shave from 'shave'; 88 | 89 | ``` 90 | 91 | ## Syntax 92 | 93 | Basic setup 94 | 95 | ```javascript 96 | 97 | shave('selector', maxheight); 98 | // shave('.shave-selector', 0) for example 99 | 100 | ``` 101 | 102 | **Shave also provided options _only_ to overwrite what it uses.** 103 | 104 | If you'd like have custom class names and not use `.js-shave`: 105 | 106 | ```javascript 107 | 108 | shave('selector', maxheight, { classname: 'classname' }); 109 | 110 | ``` 111 | 112 | Or if you'd like to have custom characters (instead of the standard ellipsis): 113 | 114 | ```javascript 115 | 116 | shave('selector', maxheight, { character: '✁' }); 117 | 118 | ``` 119 | 120 | Or both: 121 | 122 | ```javascript 123 | 124 | shave('selector', maxheight, { classname: 'classname', character: '✁' }); 125 | 126 | ``` 127 | 128 | Without spaces: 129 | 130 | ```javascript 131 | 132 | shave('selector', maxheight, { spaces: false }); 133 | 134 | ``` 135 | 136 | ---- 137 | 138 | You can also use **shave** as a [jQuery](http://jquery.com/) or [Zepto](http://zeptojs.com/) plugin. As of Shave >= v2, use **dist/jquery.shave.js** for jQuery/Zepto. 139 | 140 | ```javascript 141 | 142 | $('selector').shave(maxheight); 143 | 144 | ``` 145 | 146 | And here's a _jQuery/Zepto_ example with custom options: 147 | 148 | ```javascript 149 | 150 | $('selector').shave(maxheight, { classname: 'your-css-class', character: '✁' }); 151 | 152 | ``` 153 | 154 | If you're using a non-spaced language, you can support shave by setting an option `spaces` to `false`. 155 | 156 | ```javascript 157 | 158 | $('selector').shave(maxheight, { classname: 'your-css-class', character: '✁', spaces: false }); 159 | 160 | ``` 161 | 162 | ## Examples 163 | 164 | [Codepen example](http://codepen.io/yowainwright/pen/5f471214df90f43c7996c5914c88e858/) with plain javascript. 165 | 166 | [Codepen example](http://codepen.io/yowainwright/pen/c35ad7a281bc58ce6f89d2adb94c5d14/) with jQuery. 167 | 168 | [Codepen example](http://codepen.io/yowainwright/pen/wzVgMp) with a non-spaced language. 169 | 170 | ## Notes 171 | 172 | `text-overflow: ellipsis` is the way to go when truncating text to a single line. Shave does something very similar to `text-overflow: ellipsis` but for _multiple lines_ when [line-clamp](https://caniuse.com/#feat=css-line-clamp) is not supported. Shave bypasses being a `line-clamp` polyfill by only accepting a max-height number. This keeps shave a fast and light weight utility. 173 | 174 | Shave implements a [binary search](http://oli.me.uk/2013/06/08/searching-javascript-arrays-with-a-binary-search/) to truncate text in the most optimal way possible. 175 | 176 | Shave is meant to truncate text within a selected html element. This means it will overwrite html within an html element with just the text within the selected element. 177 | 178 | Here are some super basic examples of shave with [window resize](http://codepen.io/yowainwright/pen/yVBxGY) and [click](http://codepen.io/yowainwright/pen/PbYdvL/) events. 🙌 179 | 180 | Shave works in all modern browsers and was tested in some not so modern browsers (like Internet Explorer 8) - it works there too. 🍻 181 | 182 | ---- 183 | 184 | [Created](https://github.com/yowainwright/truncated.js) and maintained by [Jeff Wainwright](https://github.com/yowainwright) with [Dollar Shave Club Engineering](https://github.com/dollarshaveclub). 185 | -------------------------------------------------------------------------------- /dist/jquery.shave.js: -------------------------------------------------------------------------------- 1 | (function (global, factory) { 2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory() : 3 | typeof define === 'function' && define.amd ? define(factory) : 4 | (factory()); 5 | }(this, (function () { 'use strict'; 6 | 7 | function shave(target, maxHeight) { 8 | var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 9 | 10 | if (!maxHeight) throw Error('maxHeight is required'); 11 | var els = typeof target === 'string' ? document.querySelectorAll(target) : target; 12 | if (!els) return; 13 | 14 | var character = opts.character || '…'; 15 | var classname = opts.classname || 'js-shave'; 16 | var spaces = opts.spaces || true; 17 | var charHtml = '' + character + ''; 18 | 19 | if (!('length' in els)) els = [els]; 20 | for (var i = 0; i < els.length; i += 1) { 21 | var el = els[i]; 22 | var styles = el.style; 23 | var span = el.querySelector('.' + classname); 24 | var textProp = el.textContent === undefined ? 'innerText' : 'textContent'; 25 | 26 | // If element text has already been shaved 27 | if (span) { 28 | // Remove the ellipsis to recapture the original text 29 | el.removeChild(el.querySelector('.js-shave-char')); 30 | el[textProp] = el[textProp]; // eslint-disable-line 31 | // nuke span, recombine text 32 | } 33 | 34 | var fullText = el[textProp]; 35 | var words = spaces ? fullText : fullText.split(' '); 36 | 37 | // If 0 or 1 words, we're done 38 | if (words.length < 2) continue; 39 | 40 | // Temporarily remove any CSS height for text height calculation 41 | var heightStyle = styles.height; 42 | styles.height = 'auto'; 43 | var maxHeightStyle = styles.maxHeight; 44 | styles.maxHeight = 'none'; 45 | 46 | // If already short enough, we're done 47 | if (el.offsetHeight <= maxHeight) { 48 | styles.height = heightStyle; 49 | styles.maxHeight = maxHeightStyle; 50 | continue; 51 | } 52 | 53 | // Binary search for number of words which can fit in allotted height 54 | var max = words.length - 1; 55 | var min = 0; 56 | var pivot = void 0; 57 | while (min < max) { 58 | pivot = min + max + 1 >> 1; // eslint-disable-line no-bitwise 59 | el[textProp] = spaces ? words.slice(0, pivot) : words.slice(0, pivot).join(' '); 60 | el.insertAdjacentHTML('beforeend', charHtml); 61 | if (el.offsetHeight > maxHeight) max = spaces ? pivot - 2 : pivot - 1;else min = pivot; 62 | } 63 | 64 | el[textProp] = spaces ? words.slice(0, max) : words.slice(0, max).join(' '); 65 | el.insertAdjacentHTML('beforeend', charHtml); 66 | var diff = spaces ? words.slice(max) : words.slice(max).join(' '); 67 | 68 | el.insertAdjacentHTML('beforeend', ''); 69 | 70 | styles.height = heightStyle; 71 | styles.maxHeight = maxHeightStyle; 72 | } 73 | } 74 | 75 | /* global window */ 76 | 77 | if (typeof window !== 'undefined') { 78 | var plugin = window.$ || window.jQuery || window.Zepto; 79 | if (plugin) { 80 | plugin.fn.shave = function shavePlugin(maxHeight, opts) { 81 | shave(this, maxHeight, opts); 82 | return this; 83 | }; 84 | } 85 | } 86 | 87 | }))); 88 | -------------------------------------------------------------------------------- /dist/jquery.shave.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height 3 | @version v2.5.7 4 | @link https://github.com/dollarshaveclub/shave#readme 5 | @author Jeff Wainwright (jeffry.in) 6 | @license MIT 7 | **/ 8 | !function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";if("undefined"!=typeof window){var e=window.$||window.jQuery||window.Zepto;e&&(e.fn.shave=function(e,t){return function(e,t,n){var i=2");"length"in a||(a=[a]);for(var h=0;h>1,d[v]=s?u.slice(0,w).join(" "):u.slice(0,w),d.insertAdjacentHTML("beforeend",c),d.offsetHeight>t?y=w-1:j=w;d[v]=s?u.slice(0,y).join(" "):u.slice(0,y),d.insertAdjacentHTML("beforeend",c);var x=s?" ".concat(u.slice(y).join(" ")):u.slice(y),H=document.createTextNode(x),b=document.createElement("span");b.classList.add(r),b.style.display="none",b.appendChild(H),d.insertAdjacentElement("beforeend",b),l.height=p,l.maxHeight=m}}}}}(this,e,t),this})}}); 9 | -------------------------------------------------------------------------------- /dist/shave.es.js: -------------------------------------------------------------------------------- 1 | /** 2 | shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height 3 | @version v2.5.7 4 | @link https://github.com/dollarshaveclub/shave#readme 5 | @author Jeff Wainwright (jeffry.in) 6 | @license MIT 7 | **/ 8 | function shave(target, maxHeight) { 9 | var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 10 | if (typeof maxHeight === 'undefined' || isNaN(maxHeight)) throw Error('maxHeight is required'); 11 | var els = typeof target === 'string' ? document.querySelectorAll(target) : target; 12 | if (!els) return; 13 | var character = opts.character || '…'; 14 | var classname = opts.classname || 'js-shave'; 15 | var spaces = typeof opts.spaces === 'boolean' ? opts.spaces : true; 16 | var charHtml = "".concat(character, ""); 17 | if (!('length' in els)) els = [els]; 18 | 19 | for (var i = 0; i < els.length; i += 1) { 20 | var el = els[i]; 21 | var styles = el.style; 22 | var span = el.querySelector(".".concat(classname)); 23 | var textProp = el.textContent === undefined ? 'innerText' : 'textContent'; // If element text has already been shaved 24 | 25 | if (span) { 26 | // Remove the ellipsis to recapture the original text 27 | el.removeChild(el.querySelector('.js-shave-char')); 28 | el[textProp] = el[textProp]; // eslint-disable-line 29 | // nuke span, recombine text 30 | } 31 | 32 | var fullText = el[textProp]; 33 | var words = spaces ? fullText.split(' ') : fullText; // If 0 or 1 words, we're done 34 | 35 | if (words.length < 2) continue; // Temporarily remove any CSS height for text height calculation 36 | 37 | var heightStyle = styles.height; 38 | styles.height = 'auto'; 39 | var maxHeightStyle = styles.maxHeight; 40 | styles.maxHeight = 'none'; // If already short enough, we're done 41 | 42 | if (el.offsetHeight <= maxHeight) { 43 | styles.height = heightStyle; 44 | styles.maxHeight = maxHeightStyle; 45 | continue; 46 | } // Binary search for number of words which can fit in allotted height 47 | 48 | 49 | var max = words.length - 1; 50 | var min = 0; 51 | var pivot = void 0; 52 | 53 | while (min < max) { 54 | pivot = min + max + 1 >> 1; // eslint-disable-line no-bitwise 55 | 56 | el[textProp] = spaces ? words.slice(0, pivot).join(' ') : words.slice(0, pivot); 57 | el.insertAdjacentHTML('beforeend', charHtml); 58 | if (el.offsetHeight > maxHeight) max = pivot - 1;else min = pivot; 59 | } 60 | 61 | el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max); 62 | el.insertAdjacentHTML('beforeend', charHtml); 63 | var diff = spaces ? " ".concat(words.slice(max).join(' ')) : words.slice(max); 64 | var shavedText = document.createTextNode(diff); 65 | var elWithShavedText = document.createElement('span'); 66 | elWithShavedText.classList.add(classname); 67 | elWithShavedText.style.display = 'none'; 68 | elWithShavedText.appendChild(shavedText); 69 | el.insertAdjacentElement('beforeend', elWithShavedText); 70 | styles.height = heightStyle; 71 | styles.maxHeight = maxHeightStyle; 72 | } 73 | } 74 | 75 | export default shave; 76 | -------------------------------------------------------------------------------- /dist/shave.js: -------------------------------------------------------------------------------- 1 | /** 2 | shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height 3 | @version v2.5.7 4 | @link https://github.com/dollarshaveclub/shave#readme 5 | @author Jeff Wainwright (jeffry.in) 6 | @license MIT 7 | **/ 8 | (function (global, factory) { 9 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 10 | typeof define === 'function' && define.amd ? define(factory) : 11 | (global = global || self, global.shave = factory()); 12 | }(this, (function () { 'use strict'; 13 | 14 | function shave(target, maxHeight) { 15 | var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 16 | if (typeof maxHeight === 'undefined' || isNaN(maxHeight)) throw Error('maxHeight is required'); 17 | var els = typeof target === 'string' ? document.querySelectorAll(target) : target; 18 | if (!els) return; 19 | var character = opts.character || '…'; 20 | var classname = opts.classname || 'js-shave'; 21 | var spaces = typeof opts.spaces === 'boolean' ? opts.spaces : true; 22 | var charHtml = "".concat(character, ""); 23 | if (!('length' in els)) els = [els]; 24 | 25 | for (var i = 0; i < els.length; i += 1) { 26 | var el = els[i]; 27 | var styles = el.style; 28 | var span = el.querySelector(".".concat(classname)); 29 | var textProp = el.textContent === undefined ? 'innerText' : 'textContent'; // If element text has already been shaved 30 | 31 | if (span) { 32 | // Remove the ellipsis to recapture the original text 33 | el.removeChild(el.querySelector('.js-shave-char')); 34 | el[textProp] = el[textProp]; // eslint-disable-line 35 | // nuke span, recombine text 36 | } 37 | 38 | var fullText = el[textProp]; 39 | var words = spaces ? fullText.split(' ') : fullText; // If 0 or 1 words, we're done 40 | 41 | if (words.length < 2) continue; // Temporarily remove any CSS height for text height calculation 42 | 43 | var heightStyle = styles.height; 44 | styles.height = 'auto'; 45 | var maxHeightStyle = styles.maxHeight; 46 | styles.maxHeight = 'none'; // If already short enough, we're done 47 | 48 | if (el.offsetHeight <= maxHeight) { 49 | styles.height = heightStyle; 50 | styles.maxHeight = maxHeightStyle; 51 | continue; 52 | } // Binary search for number of words which can fit in allotted height 53 | 54 | 55 | var max = words.length - 1; 56 | var min = 0; 57 | var pivot = void 0; 58 | 59 | while (min < max) { 60 | pivot = min + max + 1 >> 1; // eslint-disable-line no-bitwise 61 | 62 | el[textProp] = spaces ? words.slice(0, pivot).join(' ') : words.slice(0, pivot); 63 | el.insertAdjacentHTML('beforeend', charHtml); 64 | if (el.offsetHeight > maxHeight) max = pivot - 1;else min = pivot; 65 | } 66 | 67 | el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max); 68 | el.insertAdjacentHTML('beforeend', charHtml); 69 | var diff = spaces ? " ".concat(words.slice(max).join(' ')) : words.slice(max); 70 | var shavedText = document.createTextNode(diff); 71 | var elWithShavedText = document.createElement('span'); 72 | elWithShavedText.classList.add(classname); 73 | elWithShavedText.style.display = 'none'; 74 | elWithShavedText.appendChild(shavedText); 75 | el.insertAdjacentElement('beforeend', elWithShavedText); 76 | styles.height = heightStyle; 77 | styles.maxHeight = maxHeightStyle; 78 | } 79 | } 80 | 81 | return shave; 82 | 83 | }))); 84 | -------------------------------------------------------------------------------- /dist/shave.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height 3 | @version v2.5.7 4 | @link https://github.com/dollarshaveclub/shave#readme 5 | @author Jeff Wainwright (jeffry.in) 6 | @license MIT 7 | **/ 8 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).shave=t()}(this,function(){"use strict";return function(e,t){var n=2");"length"in i||(i=[i]);for(var c=0;c>1,l[f]=s?g.slice(0,y).join(" "):g.slice(0,y),l.insertAdjacentHTML("beforeend",r),l.offsetHeight>t?m=y-1:x=y;l[f]=s?g.slice(0,m).join(" "):g.slice(0,m),l.insertAdjacentHTML("beforeend",r);var j=s?" ".concat(g.slice(m).join(" ")):g.slice(m),H=document.createTextNode(j),b=document.createElement("span");b.classList.add(a),b.style.display="none",b.appendChild(H),l.insertAdjacentElement("beforeend",b),h.height=u,h.maxHeight=p}}}}}}); 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shave", 3 | "version": "2.5.7", 4 | "description": "Shave is a javascript plugin that truncates multi-line text within a html element based on set max height", 5 | "main": "dist/shave.js", 6 | "module": "dist/shave.es.js", 7 | "unpkg": "dist/shave.min.js", 8 | "files": [ 9 | "dist", 10 | "src", 11 | "types" 12 | ], 13 | "types": "types/index.d.ts", 14 | "scripts": { 15 | "build": "rollup --config rollup.config.js", 16 | "chore:delete-changelog-branch": "if git show-ref --quiet refs/heads/chore-changelog; then git branch -D chore-changelog; fi", 17 | "chore:branch": "git checkout -b chore-changelog", 18 | "chore:changelog": "conventional-changelog -p eslint -i CHANGELOG.md -s -r 0", 19 | "chore:setup-next-work": "git checkout master && npm run chore:delete-changelog-branch", 20 | "chore:pr": "git add . && git commit -m '[chore] updates changelog' --no-verify && git push origin chore-changelog -f", 21 | "chore:setup-changelog": "git checkout master && git pull", 22 | "chore": "npm run chore:delete-changelog-branch && npm run chore:branch && npm run chore:changelog && npm run chore:pr && npm run chore:setup-next-work", 23 | "eslint": "eslint . --fix", 24 | "eslint:ci": "eslint .", 25 | "postpublish": "git tag $npm_package_version && git push origin --tags && npm run chore", 26 | "prepush": "npm run build && npm test && npm run eslint:ci", 27 | "test": "npm run test:acceptance && npm run test:es-check", 28 | "test:acceptance": "node ./scripts/acceptance.js --coverage", 29 | "test:es-check": "es-check es5 dist/shave.min.js dist/shave.js dist/jquery.shave.js dist/jquery.shave.min.js" 30 | }, 31 | "repository": { 32 | "type": "git", 33 | "url": "git+https://github.com/dollarshaveclub/shave.git" 34 | }, 35 | "keywords": [ 36 | "ellipsis", 37 | "truncate", 38 | "truncation", 39 | "truncated", 40 | "semantic", 41 | "js", 42 | "content", 43 | "shorten", 44 | "javascript", 45 | "text", 46 | "shave", 47 | "trim" 48 | ], 49 | "author": "Jeff Wainwright (jeffry.in)", 50 | "license": "MIT", 51 | "bugs": { 52 | "url": "https://github.com/dollarshaveclub/shave/issues" 53 | }, 54 | "homepage": "https://github.com/dollarshaveclub/shave#readme", 55 | "devDependencies": { 56 | "@babel/core": "^7.7.0", 57 | "@babel/preset-env": "^7.7.0", 58 | "babel-core": "^7.0.0-bridge.0", 59 | "conventional-changelog-cli": "^2.0.11", 60 | "es-check": "5.1.0", 61 | "eslint": "^6.6.0", 62 | "eslint-config-dollarshaveclub": "^3.1.0", 63 | "eslint-plugin-import": "^2.18.0", 64 | "eslint-plugin-node": "^11.0.0", 65 | "eslint-plugin-standard": "^4.0.0", 66 | "husky": "^4.0.2", 67 | "node-qunit-phantomjs": "^2.0.0", 68 | "rollup": "^1.27.8", 69 | "rollup-plugin-babel": "^4.0.0-beta.0", 70 | "rollup-plugin-uglify": "^6.0.1", 71 | "typescript": "^3.0.1" 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from 'rollup-plugin-babel' 2 | import { uglify } from 'rollup-plugin-uglify' 3 | 4 | import { 5 | author, 6 | description, 7 | homepage, 8 | license, 9 | main, 10 | module, 11 | name, 12 | version, 13 | } from './package.json' 14 | 15 | const banner = `/** 16 | ${name} - ${description} 17 | @version v${version} 18 | @link ${homepage} 19 | @author ${author} 20 | @license ${license} 21 | **/` 22 | 23 | const babelSetup = { 24 | babelrc: false, 25 | presets: [['@babel/preset-env', { modules: false }]], 26 | exclude: 'node_modules/**', 27 | } 28 | 29 | const uglifyOutput = { 30 | output: { 31 | comments: (node, comment) => { 32 | const text = comment.value 33 | const type = comment.type 34 | if (type === 'comment2') { 35 | // multiline comment 36 | return /@preserve|@license|@cc_on/i.test(text) 37 | } 38 | }, 39 | }, 40 | } 41 | 42 | const ensureArray = maybeArr => Array.isArray(maybeArr) ? maybeArr : [maybeArr] 43 | 44 | const createConfig = ({ input, output, env } = {}) => { 45 | const plugins = [ 46 | babel(babelSetup), 47 | ] 48 | 49 | if (env === 'production') plugins.push(uglify(uglifyOutput)) 50 | return { 51 | input, 52 | plugins, 53 | output: ensureArray(output).map(format => 54 | Object.assign( 55 | {}, 56 | format, 57 | { 58 | banner, 59 | name, 60 | }, 61 | ), 62 | ), 63 | } 64 | } 65 | 66 | export default [ 67 | createConfig({ 68 | input: 'src/shave.js', 69 | output: [ 70 | { file: main, format: 'umd' }, 71 | { file: module, format: 'es' }, 72 | ], 73 | }), 74 | createConfig({ 75 | input: 'src/shave.js', 76 | output: { 77 | file: 'dist/shave.min.js', 78 | format: 'umd', 79 | }, 80 | env: 'production', 81 | }), 82 | createConfig({ 83 | input: 'src/jquery.shave.js', 84 | output: { 85 | file: 'dist/jquery.shave.min.js', 86 | format: 'umd', 87 | }, 88 | env: 'production', 89 | }), 90 | ] 91 | -------------------------------------------------------------------------------- /scripts/acceptance.js: -------------------------------------------------------------------------------- 1 | const qunit = require('node-qunit-phantomjs') 2 | 3 | qunit('tests/index.html') 4 | -------------------------------------------------------------------------------- /src/jquery.shave.js: -------------------------------------------------------------------------------- 1 | import shave from './shave' 2 | 3 | if (typeof window !== 'undefined') { 4 | const plugin = window.$ || window.jQuery || window.Zepto 5 | if (plugin) { 6 | plugin.fn.shave = function shavePlugin (maxHeight, opts) { 7 | shave(this, maxHeight, opts) 8 | return this 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/shave.js: -------------------------------------------------------------------------------- 1 | export default function shave (target, maxHeight, opts = {}) { 2 | if (typeof maxHeight === 'undefined' || isNaN(maxHeight)) throw Error('maxHeight is required') 3 | let els = (typeof target === 'string') ? document.querySelectorAll(target) : target 4 | if (!els) return 5 | 6 | const character = opts.character || '…' 7 | const classname = opts.classname || 'js-shave' 8 | const spaces = typeof opts.spaces === 'boolean' ? opts.spaces : true 9 | const charHtml = `${character}` 10 | 11 | if (!('length' in els)) els = [els] 12 | for (let i = 0; i < els.length; i += 1) { 13 | const el = els[i] 14 | const styles = el.style 15 | const span = el.querySelector(`.${classname}`) 16 | const textProp = el.textContent === undefined ? 'innerText' : 'textContent' 17 | 18 | // If element text has already been shaved 19 | if (span) { 20 | // Remove the ellipsis to recapture the original text 21 | el.removeChild(el.querySelector('.js-shave-char')) 22 | el[textProp] = el[textProp] // eslint-disable-line 23 | // nuke span, recombine text 24 | } 25 | 26 | const fullText = el[textProp] 27 | const words = spaces ? fullText.split(' ') : fullText 28 | // If 0 or 1 words, we're done 29 | if (words.length < 2) continue 30 | 31 | // Temporarily remove any CSS height for text height calculation 32 | const heightStyle = styles.height 33 | styles.height = 'auto' 34 | const maxHeightStyle = styles.maxHeight 35 | styles.maxHeight = 'none' 36 | 37 | // If already short enough, we're done 38 | if (el.offsetHeight <= maxHeight) { 39 | styles.height = heightStyle 40 | styles.maxHeight = maxHeightStyle 41 | continue 42 | } 43 | 44 | // Binary search for number of words which can fit in allotted height 45 | let max = words.length - 1 46 | let min = 0 47 | let pivot 48 | while (min < max) { 49 | pivot = (min + max + 1) >> 1 // eslint-disable-line no-bitwise 50 | el[textProp] = spaces ? words.slice(0, pivot).join(' ') : words.slice(0, pivot) 51 | el.insertAdjacentHTML('beforeend', charHtml) 52 | if (el.offsetHeight > maxHeight) max = pivot - 1 53 | else min = pivot 54 | } 55 | 56 | el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max) 57 | el.insertAdjacentHTML('beforeend', charHtml) 58 | const diff = spaces ? ` ${words.slice(max).join(' ')}` : words.slice(max) 59 | 60 | const shavedText = document.createTextNode(diff) 61 | const elWithShavedText = document.createElement('span') 62 | elWithShavedText.classList.add(classname) 63 | elWithShavedText.style.display = 'none' 64 | elWithShavedText.appendChild(shavedText) 65 | el.insertAdjacentElement('beforeend', elWithShavedText) 66 | 67 | styles.height = heightStyle 68 | styles.maxHeight = maxHeightStyle 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 |
9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/tests.js: -------------------------------------------------------------------------------- 1 | /* global QUnit, shave, $ */ 2 | 3 | var testText = '

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin imgone orimgone eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium. Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium.Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium.Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium.Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium.Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的

那各相標一來依正員由不古達解工面想推的。

會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium. Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium. Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. ... Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium. Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium. Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandit. Nam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium. Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandiam porta sollicitudin erat, at fermentum eros iaculis ut.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor. Duis varius purus pellentesque luctus vestibulum. In ex dui, maximus vitae nisl a, molestie malesuada purus. Duis semper est in varius mattis. Pellentesque mollis convallis ex eu pretium. Vivamus eleifend nunc a sem euismod, non consequat purus varius. Donec hendrerit eleifend ex ac cursus. Ut ac nibh quis massa rhoncus accumsan. Praesent ultricies arcu quis magna tempus, vitae tristique diam euismod. Proin accumsan quam magna, quis condimentum diam lacinia et. Quisque tempor tellus neque, vitae facilisis dui mollis sit amet. Sed sit amet augue ac mi cursus egestas nec gravida velit. Suspendisse eu nunc tristique lorem eleifend vulputate. Aliquam viverra ex sed augue mollis, eu feugiat purus volutpat. Donec consectetur a lectus ac accumsan. Aenean massa libero, pellentesque a ultrices nec, commodo eget neque. Duis blandit augue et tempus egestas. Aenean facilisis lectus eget venenatis blandiam porta sollicitudin erat, at fermentum eros iaculis ut.

會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的

Testzzzzzz with real words. Test with real wordzzzzz. Testzzzzzzz with real wordzzzzzz. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words. Test with real words.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin consequat eros, non posuere justo hendrerit quis. Integer eget risus dapibus, rutrum nisl sit amet, posuere dui. Cras vitae urna ac urna placerat vulputate. Morbi et tortor vel nisi rutrum consequat. Pellentesque non sem cursus, rhoncus nisi sed, semper quam. Phasellus efficitur iaculis auctor. Pellentesque at aliquam leo. Proin diam nulla, mollis vitae nibh sit amet, interdum suscipit risus. Sed fermentum leo enim, a pretium ipsum sollicitudin non. Nunc tempus nunc sed laoreet porttitor.

'; 4 | 5 | $('#tests').append(testText); 6 | 7 | QUnit.test('run shave on a paragraph with a class', function(assert) { 8 | shave('.test', 50); 9 | assert.equal($('.js-shave').length, 1, 'there should be 1 .js-shave'); 10 | }); 11 | 12 | QUnit.test('run shave a paragraph with an id & unique class', function(assert) { 13 | shave('#test', 70, { classname: 'js-test' }); 14 | assert.equal($('.js-test').length, 1, 15 | 'there should be 1 .js-test'); 16 | }); 17 | 18 | QUnit.test('run shave a paragraph with an id & no class & a special hellip', function(assert) { 19 | shave('#test-2', 70, { character: '🐔', classname: 'js-chicken' }); 20 | assert.equal($('.js-chicken').length, 1, 21 | 'there should be 1 .js-chicken'); 22 | }); 23 | 24 | QUnit.test('run shave a paragraph with an id & no class & a special hellip', function(assert) { 25 | shave('#test-3', 90, { character: '👌', classname: 'js-new-text' }); 26 | assert.equal($('.js-new-text').length, 1, 27 | 'there should be 1 .js-new-text'); 28 | }); 29 | 30 | QUnit.test('run shave iteration', function(assert) { 31 | shave('.test-2', 50, { character: '🙌', classname: 'js-iteration-works' }); 32 | assert.equal($('.js-iteration-works').length, 4, 33 | 'there should be 4 .js-iteration-works'); 34 | }); 35 | 36 | QUnit.test('run shave with non-spaced languages', function(assert) { 37 | shave('.test-3', 50, { character: '...', classname: 'js-non-spaced-lang', spaces: false }); 38 | assert.equal($('.js-non-spaced-lang').length, 2, 39 | 'there should be 2 .js-non-spaced-lang'); 40 | }); 41 | 42 | QUnit.test('run shave with jquery', function(assert) { 43 | $('#test-4').shave(50, { classname: 'js-jquery-shave' }); 44 | assert.equal($('.js-jquery-shave').length, 1, 45 | 'jQuery or Zepto should have been run.'); 46 | }); 47 | 48 | QUnit.test('run shave and check jquery chaining', function(assert) { 49 | $('#test-5').shave(36).css('height', '36px'); 50 | assert.equal($('#test-5').css('height'), '36px', 51 | 'jQuery or Zepto should have been run.'); 52 | }); 53 | 54 | QUnit.test('run shave and check similar max height', function(assert) { 55 | shave('#test-6', 36); 56 | $('#test-5').css('height', '36px'); 57 | assert.equal($('#test-5').css('height'), '36px', 'shave should have still run'); 58 | }); 59 | 60 | QUnit.test('run shave and check similar max height with jQuery', function(assert) { 61 | shave('#test-7', 50, { character: '...', classname: 'js-non-spaced-lang', spaces: false }); 62 | $('#test-7').css('height', '50px').css('max-height', '50px'); 63 | assert.equal($('#test-7').css('height'), '50px', 'shave should have still run'); 64 | }); 65 | 66 | QUnit.test('run shave on a paragraph with a class', function (assert) { 67 | shave('#test-8', 50); 68 | assert.equal($('#test-8').length, 1, 'there should be 1 #test-8'); 69 | }); 70 | 71 | [ 72 | { 73 | spacesOpt: { spaces: true }, 74 | elementId: 'test-9' 75 | }, 76 | { 77 | spacesOpt: { spaces: false }, 78 | elementId: 'test-10' 79 | } 80 | ].forEach(function(test) { 81 | QUnit.test('run shave on the same paragraph multiple times, { spaces: ' + test.spacesOpt.spaces + ' }', function(assert) { 82 | var p = document.getElementById(test.elementId); 83 | shave(p, 50, test.spacesOpt); 84 | var firstShaveText = p.innerText 85 | for (var i = 0; i < 10; i++) { 86 | shave(p, 50, test.spacesOpt); 87 | } 88 | var lastShaveText = p.innerText; 89 | assert.equal(firstShaveText, lastShaveText, 'the innerText should remain the same'); 90 | }); 91 | }); 92 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ 5 | "module": "commonjs", /* Specify module code generation: 'none', commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 6 | // "lib": [], /* Specify library files to be included in the compilation: */ 7 | // "allowJs": true, /* Allow javascript files to be compiled. */ 8 | // "checkJs": true, /* Report errors in .js files. */ 9 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 10 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 11 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 12 | // "outFile": "./", /* Concatenate and emit output to single file. */ 13 | // "outDir": "./", /* Redirect output structure to the directory. */ 14 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 15 | // "removeComments": true, /* Do not emit comments to output. */ 16 | // "noEmit": true, /* Do not emit outputs. */ 17 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 18 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 19 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 20 | 21 | /* Strict Type-Checking Options */ 22 | "strict": true /* Enable all strict type-checking options. */ 23 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 24 | // "strictNullChecks": true, /* Enable strict null checks. */ 25 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 26 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 27 | 28 | /* Additional Checks */ 29 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 30 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 31 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 32 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 33 | 34 | /* Module Resolution Options */ 35 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 36 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 37 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 38 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 39 | // "typeRoots": [], /* List of folders to include type definitions from. */ 40 | // "types": [], /* Type declaration files to be included in compilation. */ 41 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 42 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 43 | 44 | /* Source Map Options */ 45 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 46 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ 47 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 48 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 49 | 50 | /* Experimental Options */ 51 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 52 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 53 | } 54 | } -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Truncates multi-line text to fit within an html element based on a set max-height. 3 | * It then stores the diff of the original text string in a hidden element following the visible text. 4 | * This means the original text remains intact! 5 | */ 6 | export default function shave( 7 | target: string | Element | Element[], 8 | maxHeight: number, 9 | options?: Shave.Options 10 | ): Shave; 11 | 12 | export interface Shave { 13 | } 14 | 15 | export namespace Shave { 16 | export interface Options { 17 | classname?: string, 18 | character?: string, 19 | spaces?: boolean 20 | } 21 | } --------------------------------------------------------------------------------