GithubHelp home page GithubHelp logo

godash's Introduction

!!!THIS PROJECT IS NOT MAINTAINED ANYMORE!!!

You can use https://github.com/alioygur/is package instead of this.

godash

Build Status GoDoc Go Report Card

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 IsEmail(str string) bool
func ExampleIsEmail() {
	fmt.Println(IsEmail("[email protected]"))
	fmt.Println(IsEmail("invalid.com"))
	fmt.Println(IsEmail(`very.(),:;<>[]".VERY."very@\ "very"[email protected]`))
	// Output:
	// true
	// false
	// true
}

Full list of Is* functions;

func IsASCII(s string) bool
func IsAlpha(s string) bool
func IsAlphanumeric(s string) bool
func IsBase64(s 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(s 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(s 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(s string) bool
func IsPort(str string) bool
func IsPositive(value float64) bool
func IsPrintableASCII(s 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(s string) bool
func IsUTFLetter(str string) bool
func IsUTFLetterNumeric(s string) bool
func IsUTFNumeric(s 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)

Examples;

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>
}

func ExampleToCamelCase() {
	fmt.Println(ToCamelCase("camel case"))
	fmt.Println(ToCamelCase("  camel case  "))
	fmt.Println(ToCamelCase("!!!camel case===="))
	fmt.Println(ToCamelCase("camel-case"))
	fmt.Println(ToCamelCase("camel_case"))
	// Output:
	// CamelCase
	// CamelCase
	// CamelCase
	// CamelCase
	// CamelCase
}

func ExampleToSnakeCase() {
	fmt.Println(ToSnakeCase("SnakeCase"))
	fmt.Println(ToSnakeCase("snake case"))
	fmt.Println(ToSnakeCase("  snake case  "))
	fmt.Println(ToSnakeCase("!!!snake case===="))
	fmt.Println(ToSnakeCase("snake-case"))
	fmt.Println(ToSnakeCase("snake_case"))
	// Output:
	// snake_case
	// snake_case
	// snake_case
	// snake_case
	// snake_case
	// snake_case
}

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.

godash's People

Contributors

aliuygur avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.