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

cutshort

v1.0.7

Published

CutShort is a javascript plugin to create multiline overflow ellipsis easy.

Downloads

114

Readme

npm

node deps

downloads install

CutShort...

Table of Contents

  1. Install
  2. Introduction
  3. Usage
  4. Options
  5. Methods
  6. Supported browsers
  7. Development

Install with npm:

npm install cutshort

Install with yarn:

yarn add cutshort

CutShort is a libary that makes multiline oveflow easy.

<span class="cut-short">Lorem ipsum...</span>

Now as you created element you want to use CutShort on you have 2 ways to initialize it:

import {CutShortFactory} from 'cutshort';

new CutShortFactory('.cut-short');

or

import {CutShort} from 'cutshort';

new CutShort(document.querySelector('.cut-short'));

After you initalized CutShort it is possible to access the CutShort's instance on its HTMLElement. It is cutShort property of CutShort's HTML element:

const myCutShort = document.querySelector('.cutShort').cutShort;

// Now you can use all cutShort methods like
myCutShort.destroy();

DISCLAMER: Don't use CutShort and CutShortFactory with quering that could target the same element. Trying to initalize CutShort on the same element twice will result in errors.

All options can be passes as attributes on the element. Attributes have higher priority over options.

lines {Number?}

Maximum amount of lines that will be displayed inside CutShort container.

Default: 1

Attribute: cut-short-lines

breakpoints {{[key: Number]: Number}}

Allows to set different amount of displayed lines for different responsive breakpoints (screen sizes). For example:

{
    // when window width is >= 0px
    0: lines, // Added automatically, no need to provide.
    
    // when window width is >= 576px
    578: 2,
    
    // when window width is >= 768px
    768: 3
    
    // when window width is >= 992px
    992: 1
}

Default: {0: lines}

Attribute: cut-short-breakpoints (accepts only valid json format, in case of invalid json, error message is thrown)

excerpt(): Void

Exerpt the content of the element CutShort got initialized on.

destroy(): Void

Destroy the current instance of CutShort

get content: String

Get full not excerpt content of the element CutShort got initialized on.

get options: {lines: Number, breakpoints: {[key: Number]: Number}}

Get options of current CutShort instance.

set content(value: String)

Set new content inside element with CutShort instance.

set options(value: {lines?: Number, breakpoints?: {[key: Number]: Number}})

Set new options for current instance of CutShort.

As long browser you want to support has support for mutationObserver and Set (part of ES6) you are good to go. In other way you need to install appropriate polyfills.

This project uses webpack 4 to compile typescript into javascript. Run npm run watch in terminal start a watch on typescript files and build everything after saving your changes.