Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

line-clamp

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

line-clamp

Truncate multi-line text in a DOM element.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-31.91%
Maintainers
1
Weekly downloads
 
Created
Source

line-clamp npm Version Build Status

Truncate multi-line text in a DOM element.

Features

  • Exit if we detect that no truncation is necessary (ie. content does not overflow container).
  • Allows use of a custom string instead of an ellipsis.

Limitations

Usage

HTML
<div class="line-clamp-wrapper">
  <div class="line-clamp">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</div>
CSS
.line-clamp-wrapper {
  height: 60px;
  overflow: hidden;
}
.line-clamp {
  width: 100px;
  line-height: 20px;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
JavaScript
import lineClamp from 'line-clamp';

lineClamp({
  lineCount: 3,
  lineHeight: 20
})(element);

Example

To run the example, do:

$ git clone https://github.com/yuanqing/line-clamp
$ npm install
$ npm install --global gulp
$ gulp example --open

API

import lineClamp from 'line-clamp';

lineClamp(options)(element)

  • options — An object literal:

    KeyDescriptionDefault
    ellipsisCharacterThe string to append to the truncated text.\u2026
    lineCountRequired. The number of lines to show.undefined
    lineHeightRequired. The pixel line-height of each line. Specify just the number eg. 20 instead of 20px.undefined
  • element — A DOM element.

See Usage above for the accompanying CSS.

Installation

Install via npm:

$ npm i --save line-clamp

Prior art

License

MIT

Keywords

FAQs

Package last updated on 13 Mar 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