JS Stdlib
Use this page when you need a quick answer to "does Targo support the JS-flavored API I am reaching for here?"
The key question is not only whether something is supported, but also whether it behaves:
- close to the familiar JS surface
- with Go-shaped return values or control flow
- through runtime-backed Targo types rather than native Go containers
When this page and older notes disagree, trust the current runtime declarations and doc fixtures.
For collection types (Array<T>, Map<K, V>, Set<T>, slice<T>, map<K, V>), see collections.md.
JSON and Object Helpers
| API | Status | Notes |
|---|---|---|
JSON.stringify(value) | Supported with Go-shaped errors | Returns [string, error | null], not a thrown exception |
JSON.parse<T>(text) | Supported with Go-shaped errors | Returns [T, error | null], not a thrown exception |
Object.keys(obj) | Supported | Runtime helper; returns slice<string> |
Object.values(obj) | Supported | Runtime helper; returns slice<unknown> |
Object.entries(obj) | Not currently documented in the runtime surface | Do not assume it exists until the declarations expose it |
If you are serializing or parsing at a package boundary, treat JSON as part of Targo's Go-style error model, not JavaScript exception flow.
Console, Math, and Numeric Globals
| API | Status | Notes |
|---|---|---|
console.log(...) | Supported | Maps directly to Go fmt.Println(...) |
console.error(...) | Supported | Maps to fmt.Fprintln(os.Stderr, ...) |
NaN / Infinity | Supported | Exposed as globals mapped to Go math helpers |
isNaN(x) / isFinite(x) | Supported | Go-backed numeric helpers |
Math.* | Broadly supported | Constants and common helpers such as floor, ceil, round, pow, sqrt, log, sin, atan2, min, and max |
Important caveat:
Mathoperates onfloat64-shaped values. Do not assume JavaScript's singlenumbermental model is always the right API shape inside Targo code.
Strings and RegExp
| API | Status | Notes |
|---|---|---|
| Common string methods | Broadly supported | trim, trimStart, trimEnd, toUpperCase, toLowerCase, includes, startsWith, endsWith, indexOf, lastIndexOf, split, replace, replaceAll, repeat, padStart, padEnd, slice, substring, charAt, charCodeAt, and at |
str.length | Supported with Go-shaped semantics | Follows Go len, so re-check Unicode assumptions |
RegExp literals and constructor | Supported | Backed by Go's RE2 engine |
RegExp.test() / RegExp.exec() | Supported | exec() returns Array<string> | null |
string.match() / matchAll() / search() / replace() / split() with RegExp | Supported | Runtime declarations provide RegExp overloads |
Important caveats:
- RegExp behavior follows RE2 constraints. Do not assume lookahead, lookbehind, or backreferences are available.
- String length and search positions follow Go-oriented indexing rules. Re-check byte-versus-character assumptions when correctness depends on Unicode details.
Unsupported or Risky JS Runtime Assumptions
| API | Status | Notes |
|---|---|---|
Promise | Not supported | No JS promise runtime |
async/await | Not supported | Use Go concurrency primitives |
setTimeout / setInterval | Not supported as JS timers | Use Go time APIs instead |
fetch | Not supported as a JS global | Use Go packages such as net/http |
| DOM / browser globals | Not supported by default | Only rely on them if the target environment explicitly provides them |
Practical Rules
- If the API belongs to JS async runtime behavior, assume it is unavailable until the current declarations prove otherwise.
- If the API looks JS-familiar but returns
[T, error | null], treat it as a Go-shaped boundary, not a JS convenience wrapper. - If behavior depends on string length, indexing, or regex edge cases, verify against current runtime declarations and fixtures rather than guessing from JavaScript habits.