tools

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tools provides numeric and string utility functions ported from SVGO's lib/svgo/tools.js.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupOutData

func CleanupOutData(data []float64, params *CleanupOutDataParams, command byte) string

CleanupOutData converts a row of numbers to an optimized string view.

Example: [0, -1, .5, .5] → "0-1 .5.5"

func DecodeSVGDataURI

func DecodeSVGDataURI(str string) string

DecodeSVGDataURI decodes a data URI back to an SVG string.

func EncodeSVGDataURI

func EncodeSVGDataURI(str string, dataType string) string

EncodeSVGDataURI encodes an SVG string as a data URI. Type can be "base64", "enc" (URI encoded), or "unenc" (unencoded).

func FindReferences

func FindReferences(attribute, value string) []string

FindReferences extracts all URL/href references from an attribute value.

func HasScripts

func HasScripts(node *svgast.Element) bool

HasScripts checks if a node contains any scripts. This checks the node's own properties, not parents or children.

func IncludesURLReference

func IncludesURLReference(body string) bool

IncludesURLReference checks if a string contains a url(#ref) reference.

func RemoveLeadingZero

func RemoveLeadingZero(value float64) string

RemoveLeadingZero removes the leading zero from floating-point numbers.

Examples: 0.5 → ".5", -0.5 → "-.5"

func ToFixed

func ToFixed(num float64, precision int) float64

ToFixed rounds a number to the specified precision. Unlike fmt.Sprintf, this returns a float64.

Types

type CleanupOutDataParams

type CleanupOutDataParams struct {
	NoSpaceAfterFlags  bool
	LeadingZero        bool
	NegativeExtraSpace bool
}

CleanupOutDataParams controls numeric output formatting.

Jump to

Keyboard shortcuts

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