utils

package
v0.0.0-...-581c726 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsArray

func AsArray(obj interface{}) []interface{}

AsArray returns the given interface as a JSON array.

func AsObject

func AsObject(obj interface{}) map[string]interface{}

AsObject returns the given interface as a JSON object.

func CreateRange

func CreateRange(start, end int32) []interface{}

CreateRange creates a range of numbers from start to end as a JSON array.

func DeepCopyArray

func DeepCopyArray(object []interface{}) []interface{}

DeepCopyArray creates a deep copy of the given JSON array.

func DeepCopyObject

func DeepCopyObject(object map[string]interface{}) map[string]interface{}

DeepCopyObject creates a deep copy of the given JSON object.

func DeleteNulls

func DeleteNulls(object map[string]interface{}) map[string]interface{}

DeleteNulls removes all keys with null values from the given JSON object.

func DeleteNullsFromArray

func DeleteNullsFromArray(array []interface{}) []interface{}

DeleteNullsFromArray removes all keys inside elements of JSON object type with null values from the given JSON array.

func IndexOf

func IndexOf[T any](object []T, value T) int

func IsArray

func IsArray(obj interface{}) bool

IsArray returns true if the given interface is an array.

func IsEqual

func IsEqual(a, b interface{}) bool

IsEqual returns true if the given interfaces are equal.

func IsEqualArray

func IsEqualArray(a, b []interface{}) bool

IsEqualArray returns true if the given JSON arrays are equal.

func IsEqualObject

func IsEqualObject(a, b map[string]interface{}) bool

IsEqualObject returns true if the given JSON objects are equal.

func IsNumber

func IsNumber(obj interface{}) bool

IsNumber returns true if the given interface is a number.

func IsObject

func IsObject(obj interface{}) bool

IsObject returns true if the given interface is an object.

func IsSemver

func IsSemver(obj interface{}) bool

IsSemver returns true if the given interface is a semver object.

func MergeArray

func MergeArray(template, parent []interface{}) []interface{}

MergeArray merges two JSON arrays into a new JSON array.

func MergeObject

func MergeObject(template, parent map[string]interface{}) map[string]interface{}

MergeObject merges two JSON objects into a new JSON object. If the same value, that is not an object or an array exists in both objects, the value from the second object will be used.

func ToBoolean

func ToBoolean(obj interface{}) bool

ToBoolean converts an interface to a boolean.

func ToString

func ToString(obj interface{}) string

ToString converts an interface to a string.

func UnescapeString

func UnescapeString(str string) string

UnescapeString removes quotes and unescapes a string.

func UnwrapContainers

func UnwrapContainers(obj interface{}) interface{}

UnwrapContainers removes all containers from the given interface. Currently only unpacks JsonNumber into an actual number with correct type.

Types

type JsonFunction

type JsonFunction func(args []interface{}) (interface{}, error)

JsonFunction is a function that can be executed.

type JsonNumber

type JsonNumber struct {
	Number
	Value   float64
	Decimal bool
}

JsonNumber is a struct that represents a number, that can be either integer or decimal.

func ToNumber

func ToNumber(obj interface{}) JsonNumber

ToNumber converts an interface to a JSON number.

func (JsonNumber) BoolValue

func (n JsonNumber) BoolValue() bool

func (JsonNumber) FloatValue

func (n JsonNumber) FloatValue() float64

func (JsonNumber) IntValue

func (n JsonNumber) IntValue() int32

func (JsonNumber) StringValue

func (n JsonNumber) StringValue() string

type Number

type Number interface {
	// IntValue returns the number as an integer.
	IntValue() int
	// FloatValue returns the number as a float.
	FloatValue() float64
	// BoolValue returns the number as a boolean.
	BoolValue() bool
	// StringValue returns the number as a string.
	StringValue() string
}

Number is an interface that represents a number, that can be either integer or decimal.

type Semver

type Semver struct {
	Major int
	Minor int
	Patch int
}

Semver represents a semantic version

func ParseSemverArray

func ParseSemverArray(version []interface{}) (Semver, error)

ParseSemverArray parses an array representation of a semantic version

func ParseSemverString

func ParseSemverString(version string) (Semver, error)

ParseSemverString parses a string representation of a semantic version

func ToSemver

func ToSemver(obj interface{}) Semver

func (Semver) CompareTo

func (s Semver) CompareTo(other Semver) int

CompareTo compares two semantic versions. Returns 0 if they are equal, -1 if the receiver is less than the argument, and 1 if the receiver is greater than the argument.

func (Semver) Equals

func (s Semver) Equals(other Semver) bool

Equals returns true if the two semantic versions are equal

func (Semver) String

func (s Semver) String() string

String returns a string representation of the semantic version

Jump to

Keyboard shortcuts

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