Help us shape the future of Go! Take the 2026 Go Developer Survey

brf

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: MIT Imports: 2 Imported by: 4

README

brf

brf is a small package, used in a few of my open source projects:

  • git-in-sync: Keep all of your git repos in sync across multiple computers
  • js2x: Convert Javascript to Markdown and beyond with js2x
  • wrangler: Wrangle up macOS user accounts and groups

Functions in package brf filter, reduce or transform strings and string slices.

The name is a reduction of the word "brief".

Strings

// Summary returns a set length string summarizing the contents of a string slice.
func Summary(sl []string, l int) string {

	if len(sl) == 0 {
		return ""
	}

	var csl []string // check slice
	var b bytes.Buffer

	for _, s := range sl {
		lc := len(strings.Join(csl, ", ")) // (l)ength(c)heck
		switch {
		case lc <= l-10 && len(s) <= 20: //
			csl = append(csl, s)
		case lc <= l && len(s) <= 12:
			csl = append(csl, s)
		}
	}

	b.WriteString(strings.Join(csl, ", "))

	if len(sl) != len(csl) {
		b.WriteString("...")
	}

	return b.String()
}

String Slices

// NoBlanks returns a string slice with no blank entries.
func NoBlanks(bsl []string) (sl []string) {
	for i := range bsl {
		if bsl[i] != "" {
			sl = append(sl, bsl[i])
		}
	}
	return sl
}
// ExcludePrefix returns a string slice, excluding entries with the prefix.
func ExcludePrefix(esl []string, pfx string) (sl []string) {
	for _, s := range esl {
		if strings.HasPrefix(s, pfx) {
			continue
		} else {
			sl = append(sl, s)
		}
	}
	return sl
}

Documentation

Overview

Package brf collects functions with brief output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After added in v0.0.4

func After(s string, m string) string

After returns the substring after a matching substring.

func ExcludePrefix

func ExcludePrefix(esl []string, pfx string) (sl []string)

ExcludePrefix returns a string slice, excluding entries with the prefix.

func ExcludeStrings

func ExcludeStrings(msl []string, esl []string) (sl []string)

ExcludeStrings returns a string slice, excluding the entries from a second slice.

func First

func First(s string) string

First returns the first line from a multi line string.

func LowerKebab

func LowerKebab(s string) string

LowerKebab converts a string to lower kebab case

func NoBlanks

func NoBlanks(bsl []string) (sl []string)

NoBlanks returns a string slice with no blank entries.

func OnlyPrefix

func OnlyPrefix(psl []string, pfx string) (sl []string)

OnlyPrefix returns a string slice, with only entries with the matching prefix.

func Reduce

func Reduce(dsl []string) (sl []string)

Reduce returns a string slice with no duplicate entries.

func Summary

func Summary(sl []string, l int) string

Summary returns a string $l characters long, summarizing the contents of a string slice.

func Trim

func Trim(s string) string

Trim trims trailing spaces and "\n" markings from a string...

Types

This section is empty.

Jump to

Keyboard shortcuts

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