/godash

A utility library in Go inspired by lodash

Primary LanguageGoMIT LicenseMIT

godash

Build Status GoDoc Go Report Card

Attention: this package is under development

A utility library in Golang inspired by lodash

installation

go get gopkg.in/alioygur/godash.v0

Contribute

we are waiting your contribution

  • Report problems
  • Add/Suggest new features/recipes
  • Improve/fix documentation

Many thanks to our contributors: contributors

Is* (collection of checking)

An Example;

func ExampleIsEmail() {
	fmt.Println(IsEmail("jhon@example.com"))
	fmt.Println(IsEmail("invalid.com"))
	fmt.Println(IsEmail("jhon doe@mail.com"))
	// Output:
	// true
	// false
	// false
}

Full list of Is* functions;

func IsASCII(str string) bool
func IsAlpha(str string) bool
func IsAlphanumeric(str string) bool
func IsBase64(str string) bool
func IsByteLength(str string, min, max int) bool
func IsCreditCard(str string) bool
func IsDNSName(str string) bool
func IsDataURI(str string) bool
func IsDialString(str string) bool
func IsDivisibleBy(str, num string) bool
func IsEmail(str string) bool
func IsFilePath(str string) (bool, int)
func IsFloat(str string) bool
func IsFullWidth(str string) bool
func IsHalfWidth(str string) bool
func IsHexadecimal(str string) bool
func IsHexcolor(str string) bool
func IsIP(str string) bool
func IsIPv4(str string) bool
func IsIPv6(str string) bool
func IsISBN(str string, version int) bool
func IsISBN10(str string) bool
func IsISBN13(str string) bool
func IsISO3166Alpha2(str string) bool
func IsISO3166Alpha3(str string) bool
func IsInRange(value, left, right float64) bool
func IsInt(str string) bool
func IsJSON(str string) bool
func IsLatitude(str string) bool
func IsLongitude(str string) bool
func IsLowerCase(str string) bool
func IsMAC(str string) bool
func IsMatches(str, pattern string) bool
func IsMongoID(str string) bool
func IsMultibyte(str string) bool
func IsNatural(value float64) bool
func IsNegative(value float64) bool
func IsNonNegative(value float64) bool
func IsNonPositive(value float64) bool
func IsNull(str string) bool
func IsNumeric(str string) bool
func IsPort(str string) bool
func IsPositive(value float64) bool
func IsPrintableASCII(str string) bool
func IsRGBcolor(str string) bool
func IsRequestURI(rawurl string) bool
func IsRequestURL(rawurl string) bool
func IsSSN(str string) bool
func IsSemver(str string) bool
func IsStringLength(str string, params ...string) bool
func IsStringMatches(s string, params ...string) bool
func IsURL(str string) bool
func IsUTFDigit(str string) bool
func IsUTFLetter(str string) bool
func IsUTFLetterNumeric(str string) bool
func IsUTFNumeric(str string) bool
func IsUUID(str string) bool
func IsUUIDv3(str string) bool
func IsUUIDv4(str string) bool
func IsUUIDv5(str string) bool
func IsUpperCase(str string) bool
func IsVariableWidth(str string) bool
func IsWhole(value float64) bool

To* (collection of converting)

An Example;

func ExampleToBoolean() {
	fmt.Println(ToBoolean("True"))
	fmt.Println(ToBoolean("true"))
	fmt.Println(ToBoolean("1"))
	fmt.Println(ToBoolean("False"))
	fmt.Println(ToBoolean("false"))
	fmt.Println(ToBoolean("0"))
	// Output:
	// true <nil>
	// true <nil>
	// true <nil>
	// false <nil>
	// false <nil>
	// false <nil>
}

Full list of To* functions;

func ToBoolean(str string) (bool, error)
func ToCamelCase(s string) string
func ToFloat(str string) (float64, error)
func ToInt(str string) (int64, error)
func ToJSON(obj interface{}) (string, error)
func ToSnakeCase(str string) string
func ToString(obj interface{}) string

for more documentation godoc

Thanks & Authors

I use code/got inspiration from these excellent libraries:

  • asaskevich/govalidator [Go] Package of validators and sanitizers for strings, numerics, slices and structs
  • lodash/lodash A modern JavaScript utility library delivering modularity, performance, & extras.