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

brf

package module
v0.0.2 Latest Latest
Warning

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

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

README

brf

A small utility package used in several 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

It's mostly functions for working with 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
}

Or for generating summaries of string slices:

// 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()
}

Documentation

Overview

Package brf collects functions with brief output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 Match

func Match(s string, pfx string) string

Match returns the string after the match...

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 set length string 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