format

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package format contains functions for printing and formatting output

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCIIEscapeUnicode

func ASCIIEscapeUnicode(str string) string

ASCIIEscapeUnicode will convert a string into an unicode escaped format

Args:

str (string): String to escape

Returns:

escapedRunes (string): Converted runes in string format

func CalculateQuartiles added in v0.2.5

func CalculateQuartiles(data []int) (int, int, int)

CalculateQuartiles calculates the first, second, and third quartiles of a list of integers and returns the values.

Args: data ([]int): A list of integers

Returns: int: The first quartile value int: The second quartile value int: The third quartile value

func CreateBoxAndWhiskersPlot added in v0.2.5

func CreateBoxAndWhiskersPlot(data []int) (string, int, int, int, int, int)

CreateBoxAndWhiskersPlot creates a box and whiskers plot from a list of integers.

Args:

data ([]int): A list of integers

Returns:
string: A string representation of the box and whiskers plot
int: The minimum value
int: The first quartile value
int: The second quartile value
int: The third quartile value
int: The maximum value

func CreateIgnoreCaseMap added in v0.3.8

func CreateIgnoreCaseMap(freq map[string]int) map[string]int

CreateIgnoreCaseMap creates a new map of item frequencies with all keys with the same case-insensitive value. The new map will have the case-insensitive key as the key and the sum of the frequencies of all keys

Args: freq (map[string]int): A map of item frequencies

Returns: map[string]int: A new map of item frequencies with case-insensitive keys

func CreateVerboseStats

func CreateVerboseStats(freq map[string]int) string

CreateVerboseStats creates a string of verbose statistics about the frequency map including several statistics about the frequency map.

Args:

freq (map[string]int): A map of item frequencies

Returns:

string: A string of verbose statistics

func DeASCIIEscapeUnicode

func DeASCIIEscapeUnicode(str string) string

DeASCIIEscapeUnicode will convert a string from an unicode escaped format to its string representation. This function will only convert the unicode escaped characters if they are in the format \uXXXX where X is a hexadecimal digit.

Args:

str (string): String to unescape

Returns:

unescapedRunes (string): Converted runes in string format

func DecodeInputMap

func DecodeInputMap(input map[string]int, bypass bool, debug bool) map[string]int

DecodeInputMap will decode a map of HTML and unicode escaped strings where possible and return a new map of decoded strings.

Args:

input (map[string]int): A map of input strings
bypass (bool): If true, the map is not used for output or filtering
debug (bool): If true, print additional debug information to stderr

Returns:

(map[string]int): A new map of decoded strings

func DecodeString

func DecodeString(s string) (string, string)

DecodeString is used to URL and HTML decode a string where possible this will only return the decoded string if it is different from the input string

Args:

s (string): Input string

Returns:

htmlDecoded (string): Input string HTML decoded
escapedDecoded (string): Input string unicode escaped decoded

func DehexMap

func DehexMap(input map[string]int, bypass bool, debug bool) map[string]int

DehexMap will decode a map of hex encoded strings and return a new map of decoded strings where possible

Args:

input (map[string]int): A map of hex encoded strings
bypass (bool): If true, the map is not used for output or filtering
debug (bool): If true, print additional debug information to stderr

Returns:

(map[string]int): A new map of decoded strings

func EncodeInputMap

func EncodeInputMap(input map[string]int, bypass bool, debug bool) map[string]int

EncodeInputMap will encode a map of strings to HTML and unicode escaped strings where possible and return a new map of encoded strings

Args:

input (map[string]int): A map of input strings
bypass (bool): If true, the map is not used for output or filtering
debug (bool): If true, print additional debug information to stderr

Returns:

(map[string]int): A new map of encoded strings

func EncodeString

func EncodeString(s string) (string, string)

EncodeString is used to URL and HTML encode a string where possible this will only return the encoded string if it is different from the input string

Args:

s (string): Input string

Returns:

htmlEncoded (string): Input string HTML encoded
escapedEncoded (string): Input string unicode escaped encoded

func FilterTopN added in v0.3.2

func FilterTopN(freq map[string]int, n int) map[string]int

FilterTopN removes all but the top N items from a map of item frequencies and returns a new map

Args: freq (map[string]int): A map of item frequencies n (int): The number of items to retain

Returns: map[string]int: A new map of the top N item frequencies

func HexEncodeMap

func HexEncodeMap(input map[string]int, bypass bool, debug bool) map[string]int

HexEncodeMap will encode a map of strings to hex encoded strings where possible and return a new map of encoded strings

Args:

input (map[string]int): A map of input strings
bypass (bool): If true, the map is not used for output or filtering
debug (bool): If true, print additional debug information to stderr

Returns:

(map[string]int): A new map of encoded strings

func PrintArrayToMarkdown added in v0.3.6

func PrintArrayToMarkdown(freq map[string]int, command string)

PrintArrayToMarkdown prints an array of items to stdout in markdown format including the item and the frequency.

Args: freq (map[string]int): A map of item frequencies command (string): The command that was run

Returns: None

func PrintArrayToSTDOUT

func PrintArrayToSTDOUT(freq map[string]int, verbose bool)

PrintArrayToSTDOUT prints an array of items to stdout

Args:

items (map[string]int): A map of item frequencies
verbose (bool): If true, the count is printed

Returns:

None

func PrintStatsToSTDOUT

func PrintStatsToSTDOUT(freq map[string]int, verbose bool, maxItems int)

PrintStatsToSTDOUT prints statistics about the frequency map to stdout including several statistics about the frequency map. If verbose is true, additional information is printed and increased number of items are printed. Items are printed in graph format with a # for each unit of item.

Args:

freq (map[string]int): A map of item frequencies
verbose (bool): If true, additional information is printed
maxItems (int): The maximum number of items to print

Returns:

None

func RemoveLengthRange

func RemoveLengthRange(freq map[string]int, start int, end int) map[string]int

RemoveLengthRange removes items from a map that are outside of a length range or not equal to the start of the end if no end is provided. The length of the range is inclusive.

Args:

freq (map[string]int): A map of item frequencies
start (int): The start of the length range
end (int): The end of the length range

Returns:

(map[string]int): A new map of item frequencies within the length range

func RemoveMinimumFrequency

func RemoveMinimumFrequency(freq map[string]int, minF int) map[string]int

RemoveMinimumFrequency removes items from a map that are below a minimum frequency threshold and returns a new map

Args:

freq (map[string]int): A map of item frequencies
minF (int): The minimum frequency threshold

Returns:

(map[string]int): A new map of item frequencies above the minimum threshold

func RetainRemove

func RetainRemove(textMap map[string]int, retainMap map[string]int, removeMap map[string]int, debugInt int) (map[string]int, error)

RetainRemove compares a string against a list of words to retain and remove

Args:

text (map[string]int): The text to process
retainMap (map[string]int): A map of words to retain
removeMap (map[string]int): A map of words to remove
debugInt (int): Represents the level of verbosity for debug output

Returns:

(map[string]int): A new map of words that have been retained and removed
(error): An error if the text map is empty

func SaveArrayToJSON

func SaveArrayToJSON(path string, freq map[string]int) error

SaveArrayToJSON saves an array of items to a JSON file at the specified path with a generated filename. The filename is generated with the format "ptt-<timestamp>.json" where the timestamp is the current time in RFC3339 format.

Args:

path (string): The path to save the JSON file
items (map[string]int): A map of item frequencies

Returns:

error: An error if the file cannot be saved

func StatClassifyToken

func StatClassifyToken(s string) []string

StatClassifyToken classifies a token into a set of categories based on the token's content. "Short" and "long" are relative to ten characters currently.

Args:

s (string): The token to classify

Returns:

[]string: A list of categories that the token belongs to

Types

This section is empty.

Jump to

Keyboard shortcuts

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