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 🙏

© 2026 – Pkg Stats / Ryan Hefner

multi-line-omit

v1.0.1

Published

> 多行文本截取 React 组件

Readme

multi-line-truncation

多行文本截取 React 组件

使用要求:容器大小固定、字体大小固定。

原理:利用JS计算字数和实际文本行数进行文本截取。

可支持带有emoji、'\n'换行符的文本

Install

> knpm i @cola/multi-line-truncation -S

Usage

常见场景:用rem作为高清方案

import React from 'react'
import Truncation from '@cola/multi-line-truncation'

const html = document.querySelector('html')
const rate = html.style.fontSize.replace('px', '') // 获取根节点字体大小
const px = 0.3 * rate // 此处计算截取字体大小

class Index extends React.Component {
  render() {
    return (
      <div className="container">
        <Truncation
          text="盲盒,是指消费者不能提前得知具体产品款式的玩具盒子,具有随机属性。只有打开才会知道自己抽到了什么。不确定的刺激会加强重复决策,因此一时间盲盒成了让人上瘾的存在。就这点来看,这和买彩票颇为相像,都有赌运气的成分。" // 目标文本
          contentWidth={window.screen.width - px * 2} // 容器大小,这里是屏幕大小减去两边padding
          fontSize={px} // 字体大小
          maxLine={3} // 最多展示3行
          ellipsisRate={2.5} // 在2.5行左右的地方截取
        />
      </div>
    )
  }
}

API

| 属性 | 类型 | 默认 | 说明 | | ------------ | ------ | --------------------- | ---------------------------------- | | text | string | | 目标文本 | | contentWidth | number | window.screen.width | 容器宽度(px),不同高清方案见上demo | | fontSize | number | 16 | 容器内字体大小 | | maxLine | number | 3 | 最多行数 | | ellipsisRate | number | 2.5 | 截取位置(不包括收起/展开文本) |

定制使用

| 属性 | 类型 | 默认 | 说明 | | ------------ | -------- | ----- | ---------------------------------------------------------- | | foldBtn | node | 收起 | 自定义“收起”按钮 | | expandBtn | node | 全部 | 自定义“展开”按钮 | | expanded | bool | false | 默认是否展开 | | toggleExpand | function | - | 使收起/展开成为受控组件,需配合 expaned 使用,完整demo见下 |