string-truncator
v2.0.18
Published
Over-engineered string truncation for web UI's
Downloads
60
Maintainers
Readme
Install
This package is pure ESM.
npm i string-truncator
Quick Take
import { strict as assert } from "assert";
import { truncate } from "string-truncator";
// maxLen setting means limit length to equivalent of 10
// longest letter lengths (font "Outfit" letter lengths are used)
// and you can override those references with your font-specific lengths
assert.deepEqual(truncate("Supermotodelicious", { maxLen: 10 }), {
result: "Supermotodelic",
addEllipsis: true,
});
assert.deepEqual(
truncate(
"the quick brown fox jumps over the lazy dog and then bites him in the tail and runs away",
{
maxLen: 10,
maxLines: 2,
},
),
{
result: "the quick brown fox jumps over",
addEllipsis: true,
},
);
Documentation
Please visit codsen.com for a full description of the API.
Contributing
To report bugs or request features or assistance, raise an issue on GitHub.
Licence
MIT License.
Copyright © 2010-2024 Roy Revelt and other contributors.