utils

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 16 Imported by: 1

README

Go Reference Go

Go-Utils

Utility package for Internal Portalnesia

This package converted from Javascript Version of Portalnesia Utils

Install

go get go.portalnesia.com/utils

Example

package main

import (
  utils "go.portalnesia.com/utils"
  "fmt"
)

func main() {
  text := "Hello World"

  slug := utils.Slug(text)
  fmt.Printf("Slugify Format: %s",slug)
}

Go References

pkg.go.dev/go.portalnesia.com/utils

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(s string) string

Clean html format in string

func CleanAndTruncate

func CleanAndTruncate(s string, max int) string

Clean HTML format and truncate string

func FirstLetter

func FirstLetter(s string, max int) string

Parse string to first letter uppercase

Example: "Hello world" => "HM"

If max is less than 1, function return all first letter of strings

func FirstToUpper

func FirstToUpper(text string) string

Capitalize first characters in word

Example: "hello world" => "Hello world"

func IsTrue

func IsTrue(value interface{}) bool

Check if variable is true

func IsTwitterUrl

func IsTwitterUrl(twitterUrl string) bool

Validate Twitter URL

func IsUrl

func IsUrl(stringUrl string) bool

ValidateURL

func NanoId

func NanoId(length ...int) string

Generate random ID

func NanoIdStr added in v1.0.7

func NanoIdStr(str string, length int) string

func NumberSize

func NumberSize(bytes float64, precision int) string

Format bytes to human readable string

Example: 50486525485 => "5.05 GB"

func ParseUrl

func ParseUrl(s string) (string, error)

Parse raw URL to clean URL

Example: "https://portalnesia.com/contact" => "portalnesia.com/contact"

func SeparateNumber

func SeparateNumber(number float64, tags ...language.Tag) string

Comma separate integer

Example: 5000 => "5,000"

func Slug

func Slug(s string) string

Slugify format of string

Example: "hello world" => "hello-world"

func Ternary added in v1.0.7

func Ternary[D any](cond bool, ifTrue D, ifFalse D) D

func Truncate

func Truncate(s string, max int) string

Truncate string

Example: "lorem ipsum lorem ipsum lorem ipsum" => "lorem ipsum lor..."

func UUID added in v1.0.6

func UUID() string

Generate UUID

func Ucwords

func Ucwords(s string) string

Capitalize each words in string

Example: "Hello world" => "Hello World"

func Ulid added in v1.0.7

func Ulid() string

func ValidateEmail

func ValidateEmail(e string) bool

Validate email

Types

type NumberFormatType

type NumberFormatType struct {
	Number int64  `json:"number"`
	Format string `json:"format"`
}

func NumberFormatShort

func NumberFormatShort(n int64) NumberFormatType

Format integer to K,M,B,T format

Example: 64768456 => "64.77 M"

Jump to

Keyboard shortcuts

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