New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

shave

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shave

Shave is a javascript plugin that truncates multi-line text within a html element based on set max height

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25K
increased by27.75%
Maintainers
2
Weekly downloads
 
Created
Source

shave

npm version 0.0.3 Bower version 0.0.3 Build Status Share

Shave

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:

  • maintains the original text after truncation.
  • does not require other libraries
  • only requires a selector and a max height
  • is very lightweight - ~1.5kb unminified
  • allows for custom ellipsis strings and class names but doesn't over complicate.
  • is additive. It will play nice with other javascript libraries and more truncation features can easily be built with it.

Installing from a package manager

npm

npm i shave --save-dev

bower

bower i shave --save-dev

Usage

  1. Add dist/shave.js.
  2. shave text within the element you'd like to.

Syntax

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: '✁'  });

Examples

Codepen example with plain javascript.

Codepen example with jQuery.

Notes

text-overflow: ellipsis is the way to go when truncating text to a single line. Shave does something very similar but for multiple lines.

Keywords

FAQs

Package last updated on 22 Oct 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc