Nancy's Preferred Machete

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

    1.1.7 • 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-2022 Roy Revelt and other contributors.

    ok codsen star

    Install

    npm i string-truncator

    DownloadsWeekly Downloads

    15

    Version

    1.1.7

    License

    MIT

    Unpacked Size

    30.9 kB

    Total Files

    10

    Last publish

    Collaborators

    • royston