Skip to content

Humanizer can/should support truncating a string to a certain length whilst adding ellipsis #80

@janv8000

Description

@janv8000

What do you guys/gals think about the following:

var longPieceOfText = "This is some text that's too large to display into a column in a table (HTML), but should present nicely when truncated to a certain length";
Assert.That(longPieceOfText.TrimTo(10), Is.EqualTo("This is s…")); 

Possible variations include trimming to the last word

Assert.That(longPieceOfText.TrimTo(10,Option.RespectWords), Is.EqualTo("This is some …")); 

Trimming to the last word but respecting the length as absolute maximum

Assert.That(longPieceOfText.TrimTo(10,Option.RespectWords | ,Option.ConsiderLengthAbsolute), Is.EqualTo("This is …")); 

See also https://github.com/HubSpot/humanize#truncate

If it's desirable I might start hacking on a PR this week...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions