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

fx-trunk8

v1.3.3

Published

trunk8 ======

Downloads

6

Readme

trunk8

About

trunk8 is an intelligent text truncation extension to jQuery. When applied to a large block of text, trunk8 will cut off just enough text to prevent it from spilling over.

Unlike conventional truncation that just limits the character length of text, trunk8 measures the content area for spill-over and intelligently chooses the text that best fits in the given space.

Play with the live demo.

Bonus: Global heatmap of trunk8 stargazers.

Usage

Default Settings

$('.too-long').trunk8(); // Lorem ipsum dolor sit amet, consect…

By default, trunk8 will add an ellipsis (…) after the truncated text.

Method Invocation

$('.too-long').trunk8('update', new_string); // Lorem ipsum dolor sit amet, consect…

To invoke built-in trunk8 methods, supply the method name as a string. Method arguments are listed after the method name as necessary. See the section below entitled Methods for a full specification.

Custom Settings

$('.too-long').trunk8({
    fill: '[snip]',
    side: 'center'
}); // Lorem ipsum dol[snip]id est laborum.

You may change the settings at any time by passing an object to trunk8. In the example above, the filler text is overwritten from an ellipsis to a custom string and the placement of the truncation is overwritten from the right side to the center. Continue reading the section below for a full list of customizable settings.

Settings

  • fill (Default: '…') The string to insert in place of the omitted text. This value may include HTML.
  • lines (Default: 1) The number of lines of text-wrap to tolerate before truncating. This value must be an integer greater than or equal to 1.
  • side (Default: 'right') The side of the text from which to truncate. Valid values include 'center', 'left', and 'right'.
  • tooltip (Default: true) When true, the title attribute of the targeted HTML element will be set to the original, untruncated string. Valid values include true and false.
  • width (Default: 'auto') The width, in characters, of the desired text. When set to 'auto', trunk8 will maximize the amount of text without spilling over.
  • parseHTML (Default: 'false') When true, parse and save html structure and restore structure in the truncated text.
  • onTruncate (Callback): Called after truncation is completed.

Public Methods

[Constructor] Initializes the settings and immediately truncates the targeted HTML element. This method is called when arguments are omitted and when the first argument is an object. When supplied with an object, trunk8 will merge the user-defined settings with the predefined settings object and immediately truncate the targeted HTML element with the custom settings.

/* default settings */
$('.too-long').trunk8();

/* custom settings */
$('.too-long').trunk8({
   lines: 2
});

update Updates the text value of the targeted HTML elements while maintaining truncation.

/* Truncate the original text. */
$('.too-long').trunk8(); // Lorem ipsum...

/* Define the new text. */
var new_string = 'Torquent sollicitudin.';

/* Truncate the new text. */
$('.too-long').trunk8('update', new_string); // Torquent so...

revert Reverts the text value of the targeted HTML elements to their untruncated states.

$('.too-long').trunk8('revert'); // Torquent sollicitudin.

getSettings Returns an object representation of the settings currently in effect. Because a return value is expected, this method does not promote the jQuery pattern of method chaining:

/* good */
var setings = $('.too-long').trunk8('getSettings'); // {...}

/* bad */
$('.too-long').trunk8('getSettings').addClass('wrong'); // error

MIT License

Copyright (c) 2012 Rick Viscomi ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.