import { default } from "https://deno.land/x/text_clipper@2.1.0/mod.ts";
Clips a string to a maximum length. If the string exceeds the length, it is truncated and an indicator (an ellipsis, by default) is appended.
In detail, the clipping rules are as follows:
- The resulting clipped string may never contain more than maxLength characters. Examples:
- clip("foo", 3) => "foo"
- clip("foo", 2) => "f…"
- The indicator is inserted if and only if the string is clipped at any place other than a
newline. Examples:
- clip("foo bar", 5) => "foo …"
- clip("foo\nbar", 5) => "foo"
- If the html option is true and valid HTML is inserted, the clipped output must also be valid HTML. If the input is not valid HTML, the result is undefined (not to be confused with JS' "undefined" type; some errors might be detected and result in an exception, but this is not guaranteed).