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 🙏

© 2024 – Pkg Stats / Ryan Hefner

easyfont

v1.0.16

Published

font processor, DOM中字符的运算(一定字数的文字宽度等)

Downloads

4

Readme

font

需求列表:

  • [x] 智能多行省略,JavaScript截断文字(尾部空格,自定义省略符号等)beta
  • [x] 计算文字的宽度(给一串文字,告诉你它的宽度)

Install

npm install easyfont --save

Usage

import EasyFont from 'easyfont';

// 例子采用ES7语法,需你自行替换到当前工程语言环境,建议使用ES7,为啥?看着舒服,读起来简单明了 ^o^
// 截断字符
const omit = async (str) => {
  const result = await new EasyFont().pipe(str)
          .operation('truncate')
          .option({ width: 270, row: 2, fontSize: 14, fontFamily: "'PingFang SC', sans-serif" })
          .value();
  return result;
}

// 获取文字宽度
const measure = async (str) => {
  const result = await new EasyFont().pipe(str)
          .operation('measure')
          .option({ fontSize: 14, fontFamily: "'PingFang SC', sans-serif" })
          .value();
  return result;
}
...
const res1 = await omit('Skylor.min is very handsome!');
const res2 = await measure('Skylor.min is very handsome!');
console.log(res1.result); // 省略后的字符,或许这就是你需要的 ^o^
console.log(res2.width); // 测量文字的宽度
...

Option

  • fontSize -> set font size.
  • fontFamily -> set font family, eg: 'PingFang SC', sans-serif.
  • fontWeight -> set font weight, eg: bold.
  • src -> set font src, (use for custom font family, deprecated!)
  • width -> set font box width.
  • row -> omit the number of rows.
  • lack -> at the end of the space num.
  • ellipsis -> custom apostrophes.

Method

this = new EasyFont();

pipi(string)

导入需要操作的字符串到操作流中。

  • 参数

    1. string (String) 导入的字符串
  • 返回

id(any)

标记返回结果,在特定情况这个可能会拯救你的人生

  • 参数

    1. any (Any) 标记的记号,可以是任何你想放进去的格式
  • 返回

operation(type)

操作类型,暂时可以为measuretruncate这两个值

  • 参数

    1. type (Type) 操作类型

      • measure:测量字符串,最后返回宽度等信息

      • truncate:截断字符串,最后返回截断后的字符串等信息

  • 返回

option(option)

字符串操作的配置信息

  • 参数
    • option (Object) 配置,具体见上面的配置
  • 返回

value()

流操作的终止函数,也是获取最后值的函数

  • 返回
    • Promise 返回一个promise,值为操作的结果值。

License

MIT License

Copyright (c) 2017 fang.yongle

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.