パッケージの詳細

ellipsed

nzambello3kMIT1.6.0

A JavaScript library for multilined text ellipsis

readme

Ellipsed

license   GitHub forks GitHub stars
npm version npm compatibility

contributions welcome Join the chat at https://gitter.im/ellipsed/Lobby   Demo

What is Ellipsed?

Ellipsed is a JavaScript library for generating multi-lined ellipsed text.
Indicating the number of visible lines, it will truncate the text at the correct position in targeted elements.

Example screenshot

Demo

You can see the demo here: https://nzambello.github.io/ellipsed/

The example/ directory of this repo contains the demo showed above. To start it on your local machine, clone the repository and install it by following the installation instructions below, then start it with npm start (or with yarn start).

Install

# Yarn
yarn add ellipsed

# NPM
npm install --save ellipsed

# Bower
bower install ellipsed

Usage

Call the ellipsis method with three parameters:

ellipsis(selector, rows, options);
  • selector - A CSS selector string or the DOM Node or Node List used to target the element for truncation
  • rows - An integer value used as the number of rows that should be visible, following words will be trucated with the replaceStr (default is '...').
  • options - Allows an options object to be passed to further customise the functionality. See options section below for details.

If responsive option is set, the function returns the ID of the listener returned by setTimeout. It can be useful to clear resize handler timeout.

Options

Options can be passed through the method using the third parameter, which provides greater control.

Name Type Default Description
replaceStr string '...' The string that substituted following the trucated string.
responsive boolean false If true, the method is re-called on resize event, so the number of rows is preserved.
debounceDelay integer 250 If responsive option is set, it's the delay value for resizing events debouncing.
delimiter string ' ' Use '' for text written in languages such as Japanese, Chinese, etc. since there's usually no space break in such languages; or for text contains long word (word that is longer than the width of the container).

Import

Ellipsed is provided as a UMD module.

You can use it as a ES6 module:

import { ellipsis } from 'ellipsed';

As a CommonJS module:

var { ellipsis } = require('ellipsed');

As an AMD module:

require([
  'ellipsed'
], function(ellipsed) {
  var ellipsis = ellipsed.ellipsis;
});

Or as a global module in the browser:

var ellipsis = window.ellipsed.ellipsis;

Performance

It seems that having multiple calls of ellipsis with responsive option enabled would add multiple event listeners and would be recommended to use a single call with a multiple selector. A single event listener should be more efficient and events handling more fluid.

Browser support

The library has been tested on:

  • Google Chrome 60+
  • Firefox 55+
  • Safari 10+
  • Edge 14+
  • IE 9+

Contributing

New contributors are warmly welcome, see the CONTRIBUTING.md file for other information.

Many thanks to @nekorina for project's logo.

更新履歴

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

v1.6.0

  • Bump tar from 4.4.15 to 4.4.19 #58
  • Bump minimist from 1.2.0 to 1.2.5 #57
  • Bump path-parse from 1.0.6 to 1.0.7 #56
  • Bump tar from 4.4.11 to 4.4.15 #55
  • Bump hosted-git-info from 2.8.4 to 2.8.9 #54
  • Bump lodash from 4.17.19 to 4.17.21 #53
  • Bump ini from 1.3.5 to 1.3.7 #52
  • Bump mixin-deep from 1.3.1 to 1.3.2 #48
  • Bump acorn from 7.0.0 to 7.2.0 #47
  • Bump lodash from 4.17.10 to 4.17.19 #51
  • feat: add ts typings declarations 24d7674

v1.5.0

1 June 2020

v1.4.2

14 October 2019

  • fixed mobile scroll, triggered ellipsed only if screen-width changes #44

v1.4.1

23 September 2019

  • Fix escaped tags when a text doesn't need ellipsing #43
  • upgraded deps e41bf31

v1.4.0

18 November 2018

  • updated some packages and fixed package.json 38c02e1
  • docs: add demonstration for text with no space break 📝 4b3fed6
  • feat: optional delimiter param ✨ af67b4a
  • fix README b4aeda3
  • restored package version f2b27ff
  • Bump version number to 1.3.2 🔖 5980bc7
  • docs: update usage instruction 📝 393589c

v1.3.1

24 December 2017

  • fix for formatted content f6929eb

v1.3.0

23 December 2017

  • added support for formatted content in html 2fae137

v1.2.0

11 December 2017

  • Added logo #34
  • simplify code and make input reactive #31
  • WIP: Improved handling of responsive option #29
  • Code styling and workaround for #27 #28
  • Fixed responsive reloading c52d022
  • added controls on demo page to avoid null number of rows eacaf30
  • fix logo url in demo page b3f5a36
  • Thanks to nekorina for the logo 81fd92f
  • fix logo url in demo page b984d83
  • added docs in README for return value (fixes issue #30) d08d099
  • added -o option to serve for development demo page web server d90c031

v1.0.1

25 October 2017

  • fix responsive option resize handler calls d208161

v1.0.0

24 October 2017

  • Added resize handling for multiple calls with responsive options (optimized with debouncing) #25
  • added ie 9+ support to readme #24
  • reverted test example js; added throttling and debounce for responsive option d3b86dc
  • started working on multiple responsive calls issue 733b553
  • added debouncing delay parameter in options in README d6025ec
  • added prettier refs in CONTRIBUTING 347aa0f
  • added prettier write to build command cecba44

v0.4.2

13 October 2017

  • Add prettier as pre-commit hook #21
  • Some changes in readme #23
  • Added browser compatibility tests info in README #20
  • added browser compatibility tests in README 698ed0f
  • fix README 73e8fff
  • added supported browsers versions 6a2ac3c
  • added supported browsers versions e677cd0
  • added screenshot 6dc23ef
  • fix readme 690544f
  • fix README image URL 2f995cf

v0.4.1

10 October 2017

  • Added responsive option #19
  • initial implementation of responsive option bdc68bb
  • added responsive option on readme 5232ec5

v0.4.0

3 October 2017

  • Added replacement string option #16
  • Updated formatting on Readme #13
  • Removed for..of for browser compatibility #12
  • fix typo for contributing md #9
  • Reworked readme #8
  • wip: functions instead of for 8516b7e
  • Added examples to readme 1c87da7
  • changed some names 216d951
  • added demo input for replaceStr f7e956f
  • fix contributing.md b1f068e
  • improved contributing.md 4303a63
  • Moved contributions badge 7216d8b
  • Add a Gitter chat badge to README.md #15 2b0f4dd
  • WIP: functions f88b9c8

v0.3.0

19 September 2017

  • Changed default export to named export. Some other minor cleanup. #5
  • fix license references 2034812
  • 0.2.4: updated package.json with new license and demo 61c4ff1

v0.2.4

13 September 2017

  • updated package.json with new license and demo homepage 28701d3
  • 0.2.3: handled license, readme and demo e94512d

v0.2.3

13 September 2017

v0.2.2

13 September 2017

v0.2.1

12 September 2017

  • Reconfigured babel to transpile to umd format #4
  • Optimized calls to getComputedStyle #3
  • More es6 #2
  • Added eslint and babel. Switched to es6. #1
  • structure, components e1723f0
  • updated LICENSE bda69e0
  • Create LICENCE cf2f378
  • fix: now it's working well; added test page d34313b
  • Create LICENSE 74ebe6d
  • first working version 7662b9d
  • aggiunta label licenza RMS nel codice 8c3102e
  • added bower registration 33817c7
  • moved file for example/ 96432b8
  • initial commit d4f9924
  • Create CONTRIBUTING.md bbb3697
  • fix text attribute for nested nodes ffc36c5
  • added README f820e55
  • updated package.json for npm 79997b9
  • improving, fix d4b95e8
  • Update README.md 182eefb
  • temporary fix for example f88b818
  • Update bower.json 03638d4
  • Update README.md 52e41f3
  • removed useless jquery import in example 01f70e3