
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
需求列表:
npm install easyfont --save
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); // 测量文字的宽度
...
this = new EasyFont();
导入需要操作的字符串到操作流中。
参数
返回
标记返回结果,在特定情况这个可能会拯救你的人生
参数
返回
操作类型,暂时可以为measure
和truncate
这两个值
参数
type (Type) 操作类型
measure
:测量字符串,最后返回宽度等信息
truncate
:截断字符串,最后返回截断后的字符串等信息
返回
字符串操作的配置信息
流操作的终止函数,也是获取最后值的函数
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.
FAQs
font processor, DOM中字符的运算(一定字数的文字宽度等)
The npm package easyfont receives a total of 3 weekly downloads. As such, easyfont popularity was classified as not popular.
We found that easyfont demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.