utils

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const USE_STD_STREAM string = "-"

USE_STD_STREAM set as filepath string value indicates that standard streams should be used as I/O targets.

Variables

This section is empty.

Functions

func FormatCurrency added in v0.7.0

func FormatCurrency(amount, decimalSeparator string) string

FormatCurrency removes all "cosmetic" separators from the amount and changes decimal separators to the decimalSeparator. The function assumes that the decimal separator in the input is either ',' or '.'.

func GeneratePresetsFile

func GeneratePresetsFile() error

GeneratePresetsFile writes an empty presets file to current user's home directory. If the file is already present, it returns an error.

Types

type Params

type Params struct {
	// Path to the input CSV file.
	Input string `json:"input"`

	// Path to the output CSV file.
	Output string `json:"output"`

	// Overwrite output file if it exists.
	Overwrite bool `json:"overwrite"`

	// Collection of parameters describing the structure of input
	// and the desired output CSV data.
	Format Preset `json:"format"`
}

Params is a collection of parameters required for CSV file rewriting.

func (*Params) ApplyPreset

func (p *Params) ApplyPreset(preset Preset)

ApplyPreset sets preset as the new value for Params.Format field.

type Preset

type Preset struct {
	// Input file encoding.
	Encoding string `json:"encoding"`

	// Pattern for output CSV file.
	Pattern string `json:"pattern"`

	// Character serving as comma in the input file.
	InputComma string `json:"input_comma"`

	// Indicates whether the header should be skipped.
	SkipHeader bool `json:"skip_header"`

	// This string will be inserted as the first row.
	NewHeader string `json:"new_header"`

	// Use CRLF instead of LF in the output file
	UseCRLF bool `json:"crlf"`

	// Decimal separator for currency.
	CurrSep string `json:"curr_sep"`
}

Preset stores a combination of pattern and encoding. Presets can be written to the presets file to facilitate reuse.

func LoadPreset

func LoadPreset(name string) (Preset, error)

LoadPreset returns a Preset of the specified name from the presets file. If the Preset is not found, an error message is returned.

Jump to

Keyboard shortcuts

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