Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

javascript-text-truncate

PascaleBeier32MITdeprecated3.0.0

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

Truncate text in elements

JavaScript, Truncate, Text

readme

JavaScriptTextTruncate

An amazingly small, dependency-less utility for text truncation. Less than 1 KByte!

Download

# Get it with npm ...
$ npm i javascript-text-truncate
# Or clone it from GitHub
$ git clone https://github.com/PascaleBeier/JavaScriptTextTruncate

Usage

<div class="truncate">
Est soluta rerum velit quasi quos et esse. Velit dolore quis autem distinctio dolor molestiae placeat. Rerum est magni quae et quo non voluptatem exercitationem. Molestiae et voluptas perferendis deserunt velit voluptatem. Earum quo consequuntur velit tempore cum nihil sint omnis.
Soluta est vel sed id molestiae recusandae non. In harum minima aut pariatur quam eligendi dolores. Consequatur quod deleniti adipisci corporis totam. Non autem rerum iusto vero accusantium numquam nesciunt sequi.
</div>

Browser Global

<script src="javascript-text-truncate.min.js"></script>
<script>
    truncate({
        el: '.truncate',
        length: 255,
        seperator: 'Read More ...'
    });
</script>

ES6

import * as truncate from 'javascript-text-truncate'

truncate({
    el: '.truncate',
    length: 255,
    seperator: 'Read More ...'
})

Options


truncate({
    el: '.truncate', // Element containg text to be truncated. Defaults to null.
    length: 255, // Truncate text after the given amount of charakters. Defaults to 255.
    seperator: 'Read More ...' // Text to be placed after the truncated text. Defaults to 'Read More ...'
})

CHANGELOG

See CHANGELOG.

LICENSE

See LICENSE.

changelog

3.0.0

Simplified API and updated tooling.

Changes

  • This library exposes a single method: truncate(). In the past, it did expose a class.

Tooling

  • Switched from babel-preset-es2015 to babel-preset-env
  • Updated DevDependencies

2.0.1

Changes

  • Changed ouput filename to javascript-text-truncate.min.js
  • Switched from babel-cli to babel-core
  • Updated webpack to 2.1.0-beta.25
  • Updated development dependencies
  • Updated example
  • Fixed .editorconfig
  • Updated README

2.0.0

Updated API. Read about breaking changes below.

Bug Fixes

  • Do not try iterating over null

Breaking Changes

  • rename window object from JavaScriptTextTruncate to TruncatedText
  • rename className to el
  • use querySelectorAll instead of getElementsByClassName

The other option keys remain the same. For example

this:

new JavaScriptTextTruncate({
    className: 'truncate'
})

... becomes ...

new TruncatedText({
    el: '.truncate'
})

1.0.0

Initial Release