js

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT, MIT Imports: 8 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 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

Constants

This section is empty.

Variables

View Source
var Esc = strings.NewReplacer("&", "&amp;", "<", "&lt;", ">", "&gt;", `"`, "&quot;", "'", "&#39;").Replace

Esc is the hand-rolled HTML escaper from scheduler.ts: exactly these five, exactly these entities (`&quot;` for the double quote, where Go's html.EscapeString writes `&#34;`).

Functions

func B64

func B64(b []byte) string

B64 is Buffer.toString('base64'): standard alphabet, padded.

func B64Decode

func B64Decode(s string) ([]byte, error)

B64Decode is Buffer.from(s, 'base64'): lenient about padding and alphabet.

func B64URL

func B64URL(b []byte) string

B64URL is Buffer.toString('base64url'): unpadded, URL alphabet.

func B64URLDecode

func B64URLDecode(s string) ([]byte, error)

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 Base36

func Base36(n int64) string

Base36 is `n.toString(36)`.

func DecodeURIComponent

func DecodeURIComponent(s string) (string, bool)

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

func EncodeURIComponent(s string) string

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 IsFinite

func IsFinite(f float64) bool

IsFinite is Number.isFinite.

func IsInteger

func IsInteger(f float64) bool

IsInteger is Number.isInteger.

func LastWins

func LastWins(pairs []KV) ([]string, map[string]string)

LastWins collapses pairs the way Object.fromEntries does: the last value for a key wins, first appearance decides order.

func Len

func Len(s string) int

Len is `.length`: UTF-16 code units.

func NumberString

func NumberString(f float64) string

NumberString is String(number).

func PadEnd

func PadEnd(s string, n int) string

PadEnd is `s.padEnd(n)` counting UTF-16 units.

func ParseNumber

func ParseNumber(s string) float64

ParseNumber is `Number(s)`: trims ASCII whitespace, "" → 0, accepts 0x/0o/0b prefixes, a decimal with an optional exponent, Infinity; anything else is NaN.

func Slice

func Slice(s string, start, end int) string

Slice is `s.slice(start, end)` over UTF-16 units (end < 0 means "to the end").

func ToString

func ToString(v any) string

ToString is String(v) for a YAML/JSON scalar: nil → "", bool → "true"/"false", numbers via NumberString, strings as-is. What spec.ts's asString() does to a value on its way into a stack name.

func Truncate

func Truncate(s string, n int) string

Truncate keeps the first n runes — the port's deliberate reading of `.slice(0, 300)` on an error message, which in JS can split a surrogate pair; cutting on a rune boundary is the safe superset.

Types

type KV

type KV struct{ K, V string }

KV is one query pair.

func ParseQuery

func ParseQuery(raw string) []KV

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.

Jump to

Keyboard shortcuts

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