types

package
v0.0.0-...-ca30569 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Break = &JsonSignal{Value: Null, Type: SignalBreak}
View Source
var Continue = &JsonSignal{Value: Null, Type: SignalContinue}
View Source
var IdentityLambda = NewLambda(func(this *JsonLambda, args []JsonType) (JsonType, error) {
	if len(args) != 1 {
		return nil, burrito.WrappedErrorf("Identity lambda must have exactly 1 argument")
	}
	return args[0], nil
}, "x=>x", []string{"x"}, []string{"x"})
View Source
var Null = &JsonNull{}
View Source
var TypeDescriptors []TypeDescriptor

Functions

func IndexOf

func IndexOf(array interface{}, value interface{}) int

func Init

func Init()

func IsArray

func IsArray(obj interface{}) bool

IsArray returns true if the given interface is an array.

func IsBool

func IsBool(obj interface{}) bool

IsBool returns true if the given interface is a boolean or a JsonBool.

func IsBreak

func IsBreak(value JsonType) bool

func IsContinue

func IsContinue(value JsonType) bool

func IsEqualArray

func IsEqualArray(a, b []JsonType) bool

IsEqualArray returns true if the given JSON arrays are equal.

func IsEqualObject

func IsEqualObject(a, b utils.NavigableMap[string, JsonType]) bool

IsEqualObject returns true if the given JSON objects are equal.

func IsJsonPath

func IsJsonPath(obj interface{}) bool

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

func IsNull

func IsNull(i interface{}) bool

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 IsReservedKey

func IsReservedKey(k string) bool

func IsReturn

func IsReturn(value JsonType) bool

func IsSemver

func IsSemver(obj interface{}) bool

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

func IsSignal

func IsSignal(value interface{}) bool

func IsString

func IsString(obj interface{}) bool

IsString returns true if the given interface is a string.

func ToPrettyString

func ToPrettyString(obj interface{}) string

ToPrettyString converts an interface to a string. In case of an object or array, it will be pretty printed.

func ToString

func ToString(obj interface{}) string

ToString converts an interface to a string.

func TypeName

func TypeName(obj interface{}) string

Types

type JsonAction

type JsonAction int

JsonAction is an enum for the different actions that can be performed via jsonte.

const (
	Value JsonAction = iota
	Iteration
	Literal
	Predicate
)

func (JsonAction) String

func (a JsonAction) String() string

String returns a string representation of the given JsonAction.

type JsonArray

type JsonArray struct {
	Value []JsonType
	// contains filtered or unexported fields
}

func AsArray

func AsArray(obj interface{}) *JsonArray

AsArray returns the given interface as a JSON array.

func CreateRange

func CreateRange(start, end int32) *JsonArray

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

func DeepCopyArray

func DeepCopyArray(object *JsonArray) *JsonArray

DeepCopyArray creates a deep copy of the given JSON array.

func DeleteNullsFromArray

func DeleteNullsFromArray(array *JsonArray) *JsonArray

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

func MergeArray

func MergeArray(template, parent *JsonArray, keepOverrides bool, path string) *JsonArray

MergeArray merges two JSON arrays into a new JSON array.

func NewJsonArray

func NewJsonArray() *JsonArray

func ParseJsonArray

func ParseJsonArray(str []byte) (*JsonArray, error)

ParseJsonArray parses a JSON string into a JSON array. It includes support for comments and detects common syntax errors.

func (*JsonArray) Add

func (t *JsonArray) Add(i JsonType) JsonType

func (*JsonArray) Append

func (t *JsonArray) Append(v ...JsonType) *JsonArray

func (*JsonArray) BoolValue

func (t *JsonArray) BoolValue() bool

func (*JsonArray) Equals

func (t *JsonArray) Equals(value JsonType) bool

func (*JsonArray) Index

func (t *JsonArray) Index(i JsonType) (JsonType, error)

func (*JsonArray) LessThan

func (t *JsonArray) LessThan(other JsonType) (bool, error)

func (*JsonArray) Negate

func (t *JsonArray) Negate() JsonType

func (*JsonArray) Parent

func (t *JsonArray) Parent() JsonType

func (*JsonArray) ParentIndex

func (t *JsonArray) ParentIndex() JsonType

func (*JsonArray) Prepend

func (t *JsonArray) Prepend(v ...JsonType) *JsonArray

func (*JsonArray) Remove

func (t *JsonArray) Remove(i *JsonNumber) (JsonType, error)

func (*JsonArray) RemoveBack

func (t *JsonArray) RemoveBack() (JsonType, error)

func (*JsonArray) RemoveFront

func (t *JsonArray) RemoveFront() (JsonType, error)

func (*JsonArray) RemoveIf

func (t *JsonArray) RemoveIf(i *JsonLambda) (JsonType, error)

func (*JsonArray) StringValue

func (t *JsonArray) StringValue() string

func (*JsonArray) Unbox

func (t *JsonArray) Unbox() interface{}

func (*JsonArray) UpdateParent

func (t *JsonArray) UpdateParent(parent JsonType, parentIndex JsonType)

type JsonBool

type JsonBool struct {
	Value bool
	// contains filtered or unexported fields
}

JsonBool is a struct that represents a boolean JSON value.

func AsBool

func AsBool(obj interface{}) *JsonBool

AsBool converts an interface to a JsonBool.

func False

func False() *JsonBool

func NewBool

func NewBool(value bool) *JsonBool

NewBool creates a new JsonBool with the specified value.

func True

func True() *JsonBool

func (*JsonBool) Add

func (t *JsonBool) Add(i JsonType) JsonType

Add performs addition of the JsonBool with another JsonType.

func (*JsonBool) BoolValue

func (t *JsonBool) BoolValue() bool

BoolValue returns the boolean value of the JsonBool.

func (*JsonBool) Equals

func (t *JsonBool) Equals(value JsonType) bool

Equals checks if the JsonBool is equal to another JsonType.

func (*JsonBool) Index

func (t *JsonBool) Index(i JsonType) (JsonType, error)

Index returns an error since indexing is not supported for booleans.

func (*JsonBool) LessThan

func (t *JsonBool) LessThan(other JsonType) (bool, error)

LessThan compares the JsonBool with another JsonType, returning true if the boolean is false and the other value is true.

func (*JsonBool) Negate

func (t *JsonBool) Negate() JsonType

Negate returns a new JsonBool with the opposite value.

func (*JsonBool) Parent

func (t *JsonBool) Parent() JsonType

func (*JsonBool) ParentIndex

func (t *JsonBool) ParentIndex() JsonType

func (*JsonBool) StringValue

func (t *JsonBool) StringValue() string

StringValue returns the string representation of the JsonBool.

func (*JsonBool) Unbox

func (t *JsonBool) Unbox() interface{}

Unbox returns the JsonBool as a native Go bool.

func (*JsonBool) UpdateParent

func (t *JsonBool) UpdateParent(parent JsonType, parentIndex JsonType)

type JsonLambda

type JsonLambda struct {
	Value         func(this *JsonLambda, args []JsonType) (JsonType, error)
	Arguments     []string
	UsedVariables []string
	String        string
}

JsonLambda is a struct that represents a lambda value.

func NewLambda

func NewLambda(value func(this *JsonLambda, args []JsonType) (JsonType, error), stringValue string, vars, args []string) *JsonLambda

func (*JsonLambda) Add

func (t *JsonLambda) Add(i JsonType) JsonType

func (*JsonLambda) BoolValue

func (t *JsonLambda) BoolValue() bool

func (*JsonLambda) Call

func (t *JsonLambda) Call(args ...JsonType) (JsonType, error)

func (*JsonLambda) Equals

func (t *JsonLambda) Equals(JsonType) bool

func (*JsonLambda) Index

func (t *JsonLambda) Index(i JsonType) (JsonType, error)

func (*JsonLambda) LessThan

func (t *JsonLambda) LessThan(JsonType) (bool, error)

func (*JsonLambda) Negate

func (t *JsonLambda) Negate() JsonType

func (*JsonLambda) Parent

func (t *JsonLambda) Parent() JsonType

func (*JsonLambda) ParentIndex

func (t *JsonLambda) ParentIndex() JsonType

func (*JsonLambda) StringValue

func (t *JsonLambda) StringValue() string

func (*JsonLambda) Unbox

func (t *JsonLambda) Unbox() interface{}

func (*JsonLambda) UpdateParent

func (t *JsonLambda) UpdateParent(parent JsonType, parentIndex JsonType)

type JsonNull

type JsonNull struct {
	// contains filtered or unexported fields
}

JsonNull is a struct that represents a null value.

func NullWithParent

func NullWithParent(parent JsonType, parentIndex JsonType) *JsonNull

func (*JsonNull) Add

func (t *JsonNull) Add(i JsonType) JsonType

func (*JsonNull) BoolValue

func (t *JsonNull) BoolValue() bool

func (*JsonNull) Equals

func (t *JsonNull) Equals(value JsonType) bool

func (*JsonNull) Index

func (t *JsonNull) Index(i JsonType) (JsonType, error)

func (*JsonNull) LessThan

func (t *JsonNull) LessThan(other JsonType) (bool, error)

func (*JsonNull) Negate

func (t *JsonNull) Negate() JsonType

func (*JsonNull) Parent

func (t *JsonNull) Parent() JsonType

func (*JsonNull) ParentIndex

func (t *JsonNull) ParentIndex() JsonType

func (*JsonNull) StringValue

func (t *JsonNull) StringValue() string

func (*JsonNull) Unbox

func (t *JsonNull) Unbox() interface{}

func (*JsonNull) UpdateParent

func (t *JsonNull) UpdateParent(parent JsonType, parentIndex JsonType)

type JsonNumber

type JsonNumber struct {
	Value   float64
	Decimal bool
	// contains filtered or unexported fields
}

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

func AsNumber

func AsNumber(obj interface{}) *JsonNumber

AsNumber converts an interface to a JSON number.

func (*JsonNumber) Add

func (t *JsonNumber) Add(i JsonType) JsonType

func (*JsonNumber) BoolValue

func (t *JsonNumber) BoolValue() bool

func (*JsonNumber) Equals

func (t *JsonNumber) Equals(value JsonType) bool

func (*JsonNumber) FloatValue

func (t *JsonNumber) FloatValue() float64

func (*JsonNumber) Index

func (t *JsonNumber) Index(i JsonType) (JsonType, error)

func (*JsonNumber) IntValue

func (t *JsonNumber) IntValue() int32

func (*JsonNumber) LessThan

func (t *JsonNumber) LessThan(other JsonType) (bool, error)

func (*JsonNumber) Negate

func (t *JsonNumber) Negate() JsonType

func (*JsonNumber) Parent

func (t *JsonNumber) Parent() JsonType

func (*JsonNumber) ParentIndex

func (t *JsonNumber) ParentIndex() JsonType

func (*JsonNumber) StringValue

func (t *JsonNumber) StringValue() string

func (*JsonNumber) Unbox

func (t *JsonNumber) Unbox() interface{}

func (*JsonNumber) UpdateParent

func (t *JsonNumber) UpdateParent(parent JsonType, parentIndex JsonType)

type JsonObject

type JsonObject struct {
	Value       *utils.NavigableMap[string, JsonType]
	StackValue  *deque.Deque[*JsonObject]
	StackTarget *JsonObject
	// contains filtered or unexported fields
}

func AsObject

func AsObject(obj interface{}) *JsonObject

AsObject returns the given interface as a JSON object.

func DeepCopyObject

func DeepCopyObject(object *JsonObject) *JsonObject

DeepCopyObject creates a deep copy of the given JSON object.

func DeleteNulls

func DeleteNulls(object *JsonObject) *JsonObject

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

func MergeObject

func MergeObject(template, parent *JsonObject, keepOverrides bool, path string) *JsonObject

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 NewJsonObject

func NewJsonObject() *JsonObject

func ParseJsonObject

func ParseJsonObject(str []byte) (*JsonObject, error)

ParseJsonObject parses a JSON string into a JSON object. It includes support for comments and detects common syntax errors.

func (*JsonObject) Add

func (t *JsonObject) Add(i JsonType) JsonType

func (*JsonObject) BoolValue

func (t *JsonObject) BoolValue() bool

func (*JsonObject) ContainsKey

func (t *JsonObject) ContainsKey(key string) bool

func (*JsonObject) Equals

func (t *JsonObject) Equals(value JsonType) bool

func (*JsonObject) Get

func (t *JsonObject) Get(key string) JsonType

func (*JsonObject) Index

func (t *JsonObject) Index(i JsonType) (JsonType, error)

func (*JsonObject) IsEmpty

func (t *JsonObject) IsEmpty() bool

func (*JsonObject) Keys

func (t *JsonObject) Keys() []string

func (*JsonObject) LessThan

func (t *JsonObject) LessThan(value JsonType) (bool, error)

func (*JsonObject) Negate

func (t *JsonObject) Negate() JsonType

func (*JsonObject) Parent

func (t *JsonObject) Parent() JsonType

func (*JsonObject) ParentIndex

func (t *JsonObject) ParentIndex() JsonType

func (*JsonObject) Put

func (t *JsonObject) Put(key string, value JsonType)

func (*JsonObject) Remove

func (t *JsonObject) Remove(key string)

func (*JsonObject) Size

func (t *JsonObject) Size() int

func (*JsonObject) StringValue

func (t *JsonObject) StringValue() string

func (*JsonObject) Unbox

func (t *JsonObject) Unbox() interface{}

func (*JsonObject) UpdateParent

func (t *JsonObject) UpdateParent(parent JsonType, parentIndex JsonType)

func (*JsonObject) Values

func (t *JsonObject) Values() []JsonType

type JsonPath

type JsonPath struct {
	Path []JsonType
	// contains filtered or unexported fields
}

JsonPath represents a simplified JSONPath

func AsJsonPath

func AsJsonPath(obj interface{}) *JsonPath

func ParseJsonPath

func ParseJsonPath(path string) (*JsonPath, error)

func (*JsonPath) Add

func (t *JsonPath) Add(i JsonType) JsonType

func (*JsonPath) BoolValue

func (t *JsonPath) BoolValue() bool

BoolValue returns a string representation of the semantic version

func (*JsonPath) Equals

func (t *JsonPath) Equals(value JsonType) bool

Equals returns true if the two semantic versions are equal

func (*JsonPath) Get

func (t *JsonPath) Get(x JsonType) (JsonType, error)

func (*JsonPath) Index

func (t *JsonPath) Index(i JsonType) (JsonType, error)

func (*JsonPath) IsEmpty

func (t *JsonPath) IsEmpty() bool

func (*JsonPath) LessThan

func (t *JsonPath) LessThan(other JsonType) (bool, error)

func (*JsonPath) Negate

func (t *JsonPath) Negate() JsonType

func (*JsonPath) Parent

func (t *JsonPath) Parent() JsonType

func (*JsonPath) ParentIndex

func (t *JsonPath) ParentIndex() JsonType

func (*JsonPath) ParentPath

func (t *JsonPath) ParentPath() *JsonPath

func (*JsonPath) Set

func (t *JsonPath) Set(x, value JsonType) (JsonType, error)

func (*JsonPath) SetIndex

func (t *JsonPath) SetIndex(i, value JsonType) error

func (*JsonPath) StringValue

func (t *JsonPath) StringValue() string

StringValue returns a string representation of the semantic version

func (*JsonPath) Unbox

func (t *JsonPath) Unbox() interface{}

func (*JsonPath) UpdateParent

func (t *JsonPath) UpdateParent(parent JsonType, parentIndex JsonType)

type JsonSignal

type JsonSignal struct {
	Value JsonType
	Type  SignalType
}

func NewReturn

func NewReturn(value JsonType) *JsonSignal

func (*JsonSignal) Add

func (t *JsonSignal) Add(i JsonType) JsonType

func (*JsonSignal) BoolValue

func (t *JsonSignal) BoolValue() bool

func (*JsonSignal) Equals

func (t *JsonSignal) Equals(value JsonType) bool

func (*JsonSignal) Index

func (t *JsonSignal) Index(i JsonType) (JsonType, error)

func (*JsonSignal) LessThan

func (t *JsonSignal) LessThan(other JsonType) (bool, error)

func (*JsonSignal) Negate

func (t *JsonSignal) Negate() JsonType

func (*JsonSignal) Parent

func (t *JsonSignal) Parent() JsonType

func (*JsonSignal) ParentIndex

func (t *JsonSignal) ParentIndex() JsonType

func (*JsonSignal) StringValue

func (t *JsonSignal) StringValue() string

func (*JsonSignal) Unbox

func (t *JsonSignal) Unbox() interface{}

func (*JsonSignal) UpdateParent

func (t *JsonSignal) UpdateParent(parent JsonType, parentIndex JsonType)

type JsonString

type JsonString struct {
	Value string
	// contains filtered or unexported fields
}

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

func AsString

func AsString(obj interface{}) *JsonString

AsString converts an interface to a string.

func NewString

func NewString(value string) *JsonString

func (*JsonString) Add

func (t *JsonString) Add(i JsonType) JsonType

func (*JsonString) BoolValue

func (t *JsonString) BoolValue() bool

func (*JsonString) Equals

func (t *JsonString) Equals(value JsonType) bool

func (*JsonString) Index

func (t *JsonString) Index(index JsonType) (JsonType, error)

func (*JsonString) LessThan

func (t *JsonString) LessThan(other JsonType) (bool, error)

func (*JsonString) Negate

func (t *JsonString) Negate() JsonType

func (*JsonString) Parent

func (t *JsonString) Parent() JsonType

func (*JsonString) ParentIndex

func (t *JsonString) ParentIndex() JsonType

func (*JsonString) StringValue

func (t *JsonString) StringValue() string

func (*JsonString) Unbox

func (t *JsonString) Unbox() interface{}

func (*JsonString) UpdateParent

func (t *JsonString) UpdateParent(parent JsonType, parentIndex JsonType)

type JsonType

type JsonType interface {
	// StringValue returns the value as a string.
	StringValue() string
	// BoolValue returns the number as a boolean.
	BoolValue() bool
	// Equals returns true if the value is equal to the given value.
	Equals(value JsonType) bool
	// LessThan returns true if the value is less than the given value.
	LessThan(value JsonType) (bool, error)
	// Unbox returns the value without any containers.
	Unbox() interface{}
	// Negate returns the value negated with a minus operator.
	Negate() JsonType
	// Index returns the value at the given index.
	Index(index JsonType) (JsonType, error)
	// Add returns the sum of the value and the given value.
	Add(index JsonType) JsonType
	// Parent returns the parent of the value or nil.
	Parent() JsonType
	// ParentIndex returns the index of the value in the parent or nil.
	ParentIndex() JsonType
	// UpdateParent updates the parent of the value.
	UpdateParent(parent JsonType, parentIndex JsonType)
}

func Box

func Box(obj interface{}) JsonType

func MergeJSON

func MergeJSON(template, parent JsonType, keepOverrides bool) (JsonType, error)

func NaN

func NaN() JsonType

type Number

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

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
	// contains filtered or unexported fields
}

Semver represents a semantic version

func AsSemver

func AsSemver(obj interface{}) *Semver

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 (*Semver) Add

func (t *Semver) Add(i JsonType) JsonType

func (*Semver) BoolValue

func (t *Semver) BoolValue() bool

BoolValue returns a string representation of the semantic version

func (*Semver) CompareTo

func (t *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 (t *Semver) Equals(value JsonType) bool

Equals returns true if the two semantic versions are equal

func (*Semver) Index

func (t *Semver) Index(i JsonType) (JsonType, error)

func (*Semver) IsEmpty

func (t *Semver) IsEmpty() bool

func (*Semver) LessThan

func (t *Semver) LessThan(other JsonType) (bool, error)

func (*Semver) Negate

func (t *Semver) Negate() JsonType

func (*Semver) Parent

func (t *Semver) Parent() JsonType

func (*Semver) ParentIndex

func (t *Semver) ParentIndex() JsonType

func (*Semver) StringValue

func (t *Semver) StringValue() string

StringValue returns a string representation of the semantic version

func (*Semver) Unbox

func (t *Semver) Unbox() interface{}

func (*Semver) UpdateParent

func (t *Semver) UpdateParent(parent JsonType, parentIndex JsonType)

type SignalType

type SignalType int
const (
	SignalReturn SignalType = iota
	SignalBreak
	SignalContinue
)

type TypeDescriptor

type TypeDescriptor struct {
	Type   reflect.Type
	Name   string
	IsType func(interface{}) bool
	AsType func(interface{}) JsonType
}

Jump to

Keyboard shortcuts

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