Documentation
¶
Overview ¶
Package jstext does to text what the reference SDK's JavaScript does to it, so a key, an address or a name is read the same in every KeyGrant SDK: String.prototype.trim, String.prototype.toUpperCase, lengths counted in UTF-16 units, and TextDecoder's reading of UTF-8.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SpaceClass = func() string { var b strings.Builder b.WriteString("[") for _, r := range jsSpaces { fmt.Fprintf(&b, `\x{%x}`, r) } b.WriteString("]") return b.String() }()
SpaceClass is JavaScript's \s as a Go regexp character class: WhiteSpace and LineTerminator, the very set trim removes (Go's \s is ASCII only).
Functions ¶
func Cut ¶
Cut is s cut to at most max UTF-16 units without splitting a character: a character above U+FFFF that would straddle the cut is left out whole, as the reference drops the high surrogate its slice leaves at the end.
func DecodeUTF8 ¶
DecodeUTF8 is TextDecoder's decode of b with its defaults (UTF-8, not fatal, BOM not ignored): each maximal invalid subsequence becomes one U+FFFD, as the Encoding Standard's UTF-8 decoder says, and one leading byte-order mark is dropped.
func Trim ¶
Trim is String.prototype.trim: the white space and line terminators JavaScript removes from both ends (U+FEFF among them, U+0085 not).
func Upper ¶
Upper is String.prototype.toUpperCase: the locale-independent full case mapping, so the sharp s (U+00DF) becomes "SS" as it does in JavaScript (strings.ToUpper keeps it). The table is what the Node named in tables.go answers, of the Unicode version named there: regenerate it (scripts/gen-jstext.mjs) when the reference moves to a Node with a newer one. Invalid UTF-8 reads as U+FFFD; a JavaScript string holds none, so callers refuse it before it gets here.
Types ¶
This section is empty.