Documentation
¶
Overview ¶
Package js reproduces the JavaScript primitives the contract leans on.
Every function here exists because a Go idiom would produce different bytes: `len()` counts bytes where `.length` counts UTF-16 units; `strconv.Atoi` rejects what `Number()` accepts; `url.QueryEscape` and `encodeURIComponent` disagree on `!'()*~` and the space; Go's base64url decoder is strict where Buffer's is lenient; `html.EscapeString` writes `"` where the hand-rolled esc() wrote `"`. Each is pinned by golden/facts/{coerce,esc,json-numbers}.json.
Index ¶
- Variables
- func B64(b []byte) string
- func B64Decode(s string) ([]byte, error)
- func B64URL(b []byte) string
- func B64URLDecode(s string) ([]byte, error)
- func Base36(n int64) string
- func DecodeURIComponent(s string) (string, bool)
- func EncodeURIComponent(s string) string
- func IsFinite(f float64) bool
- func IsInteger(f float64) bool
- func LastWins(pairs []KV) ([]string, map[string]string)
- func Len(s string) int
- func NumberString(f float64) string
- func PadEnd(s string, n int) string
- func ParseNumber(s string) float64
- func Slice(s string, start, end int) string
- func ToString(v any) string
- func Truncate(s string, n int) string
- type KV
Constants ¶
This section is empty.
Variables ¶
var Esc = strings.NewReplacer("&", "&", "<", "<", ">", ">", `"`, """, "'", "'").Replace
Esc is the hand-rolled HTML escaper from scheduler.ts: exactly these five, exactly these entities (`"` for the double quote, where Go's html.EscapeString writes `"`).
Functions ¶
func B64URLDecode ¶
B64URLDecode is Buffer.from(s, 'base64url'): LENIENT — accepts padding, the standard `+/` alphabet, and ignores whitespace. A provider's ID token segment with `=` padding verifies under Bun; it must here too.
func DecodeURIComponent ¶
DecodeURIComponent is decodeURIComponent: %XX sequences to bytes, which must form valid UTF-8; `+` is NOT a space. The error is JS's URIError.
func EncodeURIComponent ¶
EncodeURIComponent keeps A–Z a–z 0–9 - _ . ! ~ * ' ( ) and percent-encodes everything else (UTF-8 bytes, uppercase hex). Not url.QueryEscape: that one turns a space into `+`, escapes `!'()*` and leaves `~` — and a client_secret_basic credential is built from this.
func LastWins ¶
LastWins collapses pairs the way Object.fromEntries does: the last value for a key wins, first appearance decides order.
func ParseNumber ¶
ParseNumber is `Number(s)`: trims ASCII whitespace, "" → 0, accepts 0x/0o/0b prefixes, a decimal with an optional exponent, Infinity; anything else is NaN.
Types ¶
type KV ¶
type KV struct{ K, V string }
KV is one query pair.
func ParseQuery ¶
ParseQuery is `new URLSearchParams(raw)`: split on `&`, each pair on the FIRST `=`, `+` is a space, percent-escapes decoded where valid and left literal where not, `;` is an ordinary character, empty pairs skipped. The order is the order on the wire.