npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multi-clamp

v2.0.2

Published

Simple, efficient and easy-to-use multiline text clamp module. (supports reverse clamp)

Downloads

15,732

Readme

multi-clamp npm

Simple, efficient and easy-to-use multiline text clamp module. (supports reverse clamp)

For React? See react-multi-clamp npm

Samples

  • Default multiline text clamp:

Default multiline text clamp

  • Custom ellipsis:

Custom ellipsis

  • Reverse clamp:

Reversed clamp

Demo Page

Browser compatibility

Supports IE8+ / Android4+ / IOS6+ / etc. Almost all of the common browsers on PC / mobile device.

Installation

You can install multi-clamp from npm:

npm install multi-clamp --save

Usage

Import multi-clamp.

import MultiClamp from 'multi-clamp';

Or use MultiClamp.min.js in browser directly.

<script src="./MultiClamp.min.js"></script>

Just new the multi-clamp constructor.

<div id="textContainer">...much...long...text...</div>

<script>
new MultiClamp(document.getElementById('textContainer'), {
  ellipsis: '...',
  clamp: 3
});
</script>

Options

ellipsis: string || element

Ellipsis can be simple string, HTML string or element object. default: '...'

clamp: number || 'auto'

The max number of lines to show. It will try to fill up the available space when set to string 'auto', and at this point you should set a static height on the text container element. default: 3

reverse: boolean

You can clamp the content from back to front, the ellipsis will be in the front. default: false

splitByWords: boolean

The default behavior is to split by letters. If you want to split by words, set splitByWords to true. default: false

disableCssClamp: boolean

Multi-clamp will use native css clamp(-webkit-line-clamp) in supported browser when the ellipsis is set to '...'. If you don't want to use css clamp, set disableCssClamp to true. default: false

onClampStart: function({ needClamp: boolean }): void || false v1.1.0+

This callback function will be executed when clamp starts, and will not be executed when use native css clamp. Clamp will be prevented when return value is false. default: function() {}

onClampEnd: function({ didClamp: boolean }): void v1.1.0+

This callback function will be executed when clamp ends, and will not be executed when use native css clamp. default: function() {}

Instance method

reload()

Call this method to re-clamp when the text content or style changes

reload(options) v2.0.0+

You can change initial options when reloading through the options param, and use the original text to re-clamp when options.useOriginalText set to true. default: { ...initOptions, useOriginalText: false }

Changelog

v2.0.2

v2.0.1

  • Bugfix. #6

v2.0.0

  • Support change initial options and use the original text to re-clamp. #2
  • Refactoring. #3

v1.1.0

v1.0.3

  • Bugfix. #1

License

MIT