numero

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 3 Imported by: 0

README

Numero-Go

Build Status Go Report Card GoDoc license

A micro library for converting non-english UTF8 digits. (like ۱=1, ۲=2)

Supported languages

Almost all numbers defined in Unicode are support in Numero.

For more info on supported characters you can visit here

Installation

Use go get on this repository:

$ go get -u github.com/faridgh1991/Numero-Go

Using Numero

On strings for strings:

result = numero.Normalize("1۲۳۰4a۳tس")
// result = "12304a3tس"

Smart numeric convert:

(Convert numbers to Integer or Float based on input string)

result, err = numero.NormalizeAsNumber("1۲۳۰4۳")
// result = 123043
// err = nil

result, err = numero.NormalizeAsNumber("1۲۳۰4۳.۴5")
// result = 123043.45
// err = nil

result, err = numero.NormalizeAsNumber("1۲a۳۰4۳.۴5")
// result = 0
// err = parsing "1۲a۳۰4۳.۴5": invalid syntax

Strip all non numeric chars from a string:

result = numero.RemoveNonDigits("12 345abs")
// result = "12345"

// Or even make exceptions for some chars like 'a' and ' ' (space)
result = numero.RemoveNonDigits("12 345bas", "a ")
// result = "12 345a"

Checking if a string is all numbers

result = numero.DigitOnly("1234567890")
// result = true

result = numero.DigitOnly("1234567890.a")
// result = false

GoDoc

See godoc page.

Documentation

Overview

Package numero is A micro library for converting non-english UTF8 digits. (like ۱=1, ۲=2) . Almost all numbers defined in Unicode is supported in Numero.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Digit added in v1.1.0

func Digit(char rune) (bool, int)

Digit to check character is digit or not and if true return integer value of character

func DigitOnly

func DigitOnly(str string) bool

DigitOnly Checking if a string is all numbers

func Normalize

func Normalize(numberStr string) string

Normalize to Normalize all numbers in input string

func NormalizeAsNumber

func NormalizeAsNumber(numberStr string) (interface{}, error)

NormalizeAsNumber to Convert numbers to Integer or Float based on input string

func RemoveNonDigits

func RemoveNonDigits(str string, exceptions ...rune) string

RemoveNonDigits Strip all non numeric chars from a string

Types

This section is empty.

Jump to

Keyboard shortcuts

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