Socket
Book a DemoInstallSign in
Socket

canvas-string-ellipsis

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-string-ellipsis

通过 canvas 测量文字长度,超过长度则使用省略号

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

canvas-string-ellipsis

通过 canvas 测量文字长度,超过长度则使用省略号

有时候我们不得不手动根据长度测量截取字符串,那么这个时候这个就很有用

How to use

npm i canvas-string-ellipsis -S
import cse from 'canvas-string-ellipsis';
const str = 'canvas-string-ellipisis';

const [res, sliced, width] = cse(str, 100)
// res: canvas-string-ellipisis
// sliced: false
// width: 96

const [res2, sliced2, width2] = cse(str, 50)
// res: canvas-stri...
// sliced: true
// width: 50

API 参数

function cse(str: string, maxWidth: number, font?: string): [string, boolean, number]

str

原始字符串

maxWidth

长度

font

canvas font 设置,默认为 14px sans-serif

返回值

返回值有三个组成一个数组,分别为截取后的字符串,是否截取,真实宽度

FAQs

Package last updated on 20 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.