string-truncator
TypeScript icon, indicating that this package has built-in type declarations

2.0.18 • Public • Published

string-truncator

Over-engineered string truncation for web UI's

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

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.

ok codsen star

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.18
    1
    • latest

Version History

Package Sidebar

Install

npm i string-truncator

Weekly Downloads

21

Version

2.0.18

License

MIT

Unpacked Size

25.8 kB

Total Files

7

Last publish

Collaborators

  • royston