All Projects → zhengrenzhe → shear.js

zhengrenzhe / shear.js

Licence: MIT license
✂️truncate text across DOM nodes

Programming Languages

typescript
32286 projects
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to shear.js

Shave
💈 Shave is a 0 dep JS plugin that truncates text to fit within an element based on a set max-height ✁
Stars: ✭ 2,113 (+3363.93%)
Mutual labels:  truncate, ellipsis, multi-line
tailwindcss-truncate-multiline
Tailwind CSS plugin to generate truncate multiline utilities
Stars: ✭ 92 (+50.82%)
Mutual labels:  truncate, ellipsis
v-clamp
Vue directive plugin for text truncate
Stars: ✭ 15 (-75.41%)
Mutual labels:  truncate, ellipsis
ngx-line-truncation
An Angular line truncating solution. Truncate text block by given line number and add ellipsis to the end.
Stars: ✭ 13 (-78.69%)
Mutual labels:  truncate, ellipsis
node-truncate
🐙 Truncate text and keeps urls safe.
Stars: ✭ 52 (-14.75%)
Mutual labels:  truncate
Voca
The ultimate JavaScript string library
Stars: ✭ 3,387 (+5452.46%)
Mutual labels:  truncate
react-middle-truncate
A React component for intelligently truncating text in the middle of the string.
Stars: ✭ 27 (-55.74%)
Mutual labels:  truncate
react-text-more-less
📃React component to show more text or show less
Stars: ✭ 16 (-73.77%)
Mutual labels:  truncate
strings-truncation
Truncate strings with fullwidth characters and ANSI codes.
Stars: ✭ 45 (-26.23%)
Mutual labels:  truncate
shave
💈 Shave is a 0 dep JS plugin that truncates text to fit within an element based on a set max-height ✁
Stars: ✭ 126 (+106.56%)
Mutual labels:  ellipsis
react-ellipsis
A high performance and customized ellipsis component for react, support rich text. 高性能、高度自定义、支持富文本的 react 缩略组件。
Stars: ✭ 63 (+3.28%)
Mutual labels:  ellipsis
angular-ellipsis
A simple lightweight library for Angular which removes excess text and add ellipsis symbol to end of text before text overflows container
Stars: ✭ 16 (-73.77%)
Mutual labels:  ellipsis

shear.js

npm

shear.js is a zero dependency javascript plugin, It uses Selection API to truncate multiple lines of text based on the actual visual content, and return the original and truncated content.

Features

  • the target element need not be set as a block level element
  • truncate across dom nodes within the target element, keep the original dom node within the target element
  • insert the html string at the end of the truncation
  • zero dependency
  • very lightweight (1.9kb)

Browser Support

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Opera
Opera
Safari
Safari
IE9+ / Edge15+ 16+ 16+ 15+ 6+

Install

yarn add shear.js

or

<script src="https://rawgit.com/zhengrenzhe/shear.js/master/dist/shear.js"></script>

Usage

import shear from "shear.js";

display three lines

shear(document.getElementById('target'), 3);

display three lines, add html string at the end of the DOM

shear(document.getElementById('target'),  3, '<span>...(More)</span>');

Example

Codepen

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].