Skip to content

adraffy/go-ens-normalize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-ens-normalize

0-dependancy ENSIP-15 in Go

go get github.com/adraffy/go-ens-normalize@v0.1.0

Primary API

// global functions will panic on invalid names
ensip15.Normalize("RaFFY🚴‍♂️.eTh") // "raffy🚴‍♂.eth"

// works like Normalize()
ensip15.Beautify("1⃣2⃣.eth"); // "1️⃣2️⃣.eth"

// member functions return ("", err) on invalid names
ens := ensip15.Shared()
norm, err := ens.Normalize("a_")

Singleton

ens := ensip15.Shared() // singleton
ens := ensip15.New() // new instance

nf := ensip15.Shared().NF() // singleton
nf := nf.New() // new instance

Error Handling

All errors are safe to print.

Utilities

Normalize name fragments for substring search:

ensip15.Shared().NormalizeFragment("AB--", false) // "ab--"
ensip15.Shared().NormalizeFragment("..\u0300", false) // "..̀"
ensip15.Shared().NormalizeFragment("\u03BF\u043E", false) // "οо"
// note: Normalize() errors on these inputs

Construct safe strings:

ensip15.Shared().SafeCodepoint(0x303) // "◌̃ {303}"
ensip15.Shared().SafeCodepoint(0xFE0F) // "{FE0F}"
ensip15.Shared().SafeImplode([]rune{0x303, 0xFE0F}) // "◌̃{FE0F}"

Unicode Normalization Forms

ensip15.Shared().NF().NFC([]rune{0x65, 0x300}) // [0xE8]
ensip15.Shared().NF().NFD([]rune{0xE8})        // [0x65, 0x300]

Build

  1. Sync and Compress
  2. go test ./...