Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
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 a html element based on a set 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 in tact!
Shave, compared to other truncation plugins:
~1.5kb
unminifiednpm
npm i shave --save-dev
bower
bower i shave --save-dev
shave
text within the element you'd like to.basic setup
shave('selector', maxheight);
Shave also provided options only to overwrite what it uses.
So, 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: '✁' });
You can also use shave as a jQuery or Zepto plugin.
$('selector').shave(maxheight);
And, here's a jQuery/Zepto example with custom options:
$('selector').shave(maxheight, { classname: 'your-css-class', character: '✁' });
Codepen example with plain javascript.
Codepen example with jQuery.
text-overflow: ellipsis
is the way to go when truncating text to a single line. Shave does something very similar but for multiple lines.
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 20,468 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.