jstext

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Cut(s string, max int) string

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

func DecodeUTF8(b []byte) string

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 Length

func Length(s string) int

Length is the length JavaScript gives s: its UTF-16 units.

func Trim

func Trim(s string) string

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

func Upper(s string) string

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.

Jump to

Keyboard shortcuts

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