Documentation
¶
Overview ¶
Package jscompat gives Go code what JavaScript does differently from Go's standard library: string offsets in UTF-16 code units, Math.round's rounding, and, in a js build, the engine's Math functions, Unicode normalization and regular expressions (RegExp).
The functions of this file are plain Go and build everywhere. With goesm, the others call the engine directly through //goesm:import; with Go's own js/wasm port, through syscall/js.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteOffset ¶
ByteOffset returns the byte offset in s of the offset u in UTF-16 code units. An offset between the two halves of a surrogate pair, which Go cannot represent, is that of the character's start; one past the end is len(s).
func Round ¶
Round returns x rounded to the nearest integer as JavaScript's Math.round does: halves round toward positive infinity, so Round(-2.5) is -2, where math.Round(-2.5) is -3.
func UTF16Len ¶
UTF16Len returns the length of s in UTF-16 code units, which is JavaScript's length of the same text. An invalid byte counts as one unit, as the U+FFFD it becomes.
func UTF16Offset ¶
UTF16Offset returns the offset in UTF-16 code units, as JavaScript's string indices and the selection of an input element count, of the byte offset i of s. An offset inside a character is that of the character's start.
Types ¶
This section is empty.