![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Shave is a javascript plugin that truncates multi-line text within a html element based on set max height
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 <span>
element following the visible text. This means the original text remains intact!
Shave, compared to other truncation plugins:
~1.5kb
unminifiednpm
npm install shave --save
bower
bower install shave --save
yarn
yarn add shave
Add dist/shave.js to your html
Or as a module
import shave from 'shave';
Basic setup
shave('selector', maxheight);
// shave('.shave-selector', 0) for example
Shave also provided options only to overwrite what it uses.
If you'd like have custom class names and not use .js-shave
:
shave('selector', maxheight, {classname: 'classname'});
Or if you'd like to have custom characters (instead of the standard ellipsis):
shave('selector', maxheight, {character: '✁'});
Or both:
shave('selector', maxheight, {classname: 'classname', character: '✁' });
Without spaces:
shave({ spaces: false });
You can also use shave as a jQuery or Zepto plugin. As of Shave >= v2, use dist/jquery.shave.js for jQuery/Zepto.
$('selector').shave(maxheight);
And here's a jQuery/Zepto example with custom options:
$('selector').shave(maxheight, { classname: 'your-css-class', character: '✁' });
If you're using a non-spaced language, you can support shave by setting an option spaces
to false
.
$('selector').shave(maxheight, { classname: 'your-css-class', character: '✁', spaces: false });
Codepen example with plain javascript.
Codepen example with jQuery.
Codepen example with a non-spaced language.
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 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.
Shave implements a binary search to truncate text in the most optimal way possible.
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.
Here are some super basic examples of shave with window resize and click events. 🙌
Shave works in all modern browsers and was tested in some not so modern browsers (like Internet Explorer 8) - it works there too. 🍻
Created and maintained by Jeff Wainwright with Dollar Shave Club Engineering.
FAQs
Shave is a javascript plugin that truncates multi-line text within a html element based on set max height
The npm package shave receives a total of 7,306 weekly downloads. As such, shave popularity was classified as popular.
We found that shave demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.