ellipsis

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 0 Imported by: 21 modules, 26 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ellipsis

Go module to insert an ellipsis into the middle of a long string in order to shorten it.

Shorten(s, w) limits the result to w Unicode code points (runes); nonpositive widths return an empty string, and widths 1–3 keep the last w runes when shortening.

Install

go get github.com/jftuga/ellipsis

License

MIT License

Example

package main

import (
	"fmt"
	"github.com/jftuga/ellipsis"
)

func main() {
	s := "abcdefghijklmnopqurstvwxyz"
	for i := 0; i <= 26; i++ {
		s := ellipsis.Shorten(s, i)
		fmt.Printf("%2d %s\n", i, s)
	}
}

Output

 0 
 1 z
 2 yz
 3 xyz
 4 ...z
 5 a...z
 6 a...yz
 7 ab...yz
 8 ab...xyz
 9 abc...xyz
10 abc...wxyz
11 abcd...wxyz
12 abcd...vwxyz
13 abcde...vwxyz
14 abcde...tvwxyz
15 abcdef...tvwxyz
16 abcdef...stvwxyz
17 abcdefg...stvwxyz
18 abcdefg...rstvwxyz
19 abcdefgh...rstvwxyz
20 abcdefgh...urstvwxyz
21 abcdefghi...urstvwxyz
22 abcdefghi...qurstvwxyz
23 abcdefghij...qurstvwxyz
24 abcdefghij...pqurstvwxyz
25 abcdefghijk...pqurstvwxyz
26 abcdefghijklmnopqurstvwxyz

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shorten

func Shorten(s string, w int) string

Shorten will insert "..." into the middle of a long string to shorten it to at most w Unicode code points (runes). Nonpositive widths return an empty string; widths 1–3 keep the last w runes.

Types

This section is empty.

Directories

Path Synopsis
main.go -John Taylor Dec-31-2020
main.go -John Taylor Dec-31-2020

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址