From 60d9a66c136bee2bb20f5b8ad1ca42055230daa4 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Mon, 24 Sep 2018 11:08:13 -0400 Subject: [PATCH] Add Is helpers --- generate/static/value.go | 10 ++++++++++ value.go | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/generate/static/value.go b/generate/static/value.go index a47a653..e7e72cb 100644 --- a/generate/static/value.go +++ b/generate/static/value.go @@ -41,3 +41,13 @@ func GetJSValue(v interface{}) interface{} { } return v } + +func (v Value) IsUndefined() bool { return v.Type() == js.TypeUndefined } +func (v Value) IsNull() bool { return v.Type() == js.TypeNull } +func (v Value) IsNullOrUndefined() bool { return v.IsNull() || v.IsUndefined() } +func (v Value) IsBoolean() bool { return v.Type() == js.TypeBoolean } +func (v Value) IsNumber() bool { return v.Type() == js.TypeNumber } +func (v Value) IsString() bool { return v.Type() == js.TypeString } +func (v Value) IsSymbol() bool { return v.Type() == js.TypeSymbol } +func (v Value) IsObject() bool { return v.Type() == js.TypeObject } +func (v Value) IsFunction() bool { return v.Type() == js.TypeFunction } diff --git a/value.go b/value.go index a47a653..e7e72cb 100644 --- a/value.go +++ b/value.go @@ -41,3 +41,13 @@ func GetJSValue(v interface{}) interface{} { } return v } + +func (v Value) IsUndefined() bool { return v.Type() == js.TypeUndefined } +func (v Value) IsNull() bool { return v.Type() == js.TypeNull } +func (v Value) IsNullOrUndefined() bool { return v.IsNull() || v.IsUndefined() } +func (v Value) IsBoolean() bool { return v.Type() == js.TypeBoolean } +func (v Value) IsNumber() bool { return v.Type() == js.TypeNumber } +func (v Value) IsString() bool { return v.Type() == js.TypeString } +func (v Value) IsSymbol() bool { return v.Type() == js.TypeSymbol } +func (v Value) IsObject() bool { return v.Type() == js.TypeObject } +func (v Value) IsFunction() bool { return v.Type() == js.TypeFunction }