Skip to content

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 ​

APIStatusNotes
JSON.stringify(value)Supported with Go-shaped errorsReturns [string, error | null], not a thrown exception
JSON.parse<T>(text)Supported with Go-shaped errorsReturns [T, error | null], not a thrown exception
Object.keys(obj)SupportedRuntime helper; returns slice<string>
Object.values(obj)SupportedRuntime helper; returns slice<unknown>
Object.entries(obj)Not currently documented in the runtime surfaceDo 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 ​

APIStatusNotes
console.log(...)SupportedMaps directly to Go fmt.Println(...)
console.error(...)SupportedMaps to fmt.Fprintln(os.Stderr, ...)
NaN / InfinitySupportedExposed as globals mapped to Go math helpers
isNaN(x) / isFinite(x)SupportedGo-backed numeric helpers
Math.*Broadly supportedConstants and common helpers such as floor, ceil, round, pow, sqrt, log, sin, atan2, min, and max

Important caveat:

  • Math operates on float64-shaped values. Do not assume JavaScript's single number mental model is always the right API shape inside Targo code.

Strings and RegExp ​

APIStatusNotes
Common string methodsBroadly supportedtrim, trimStart, trimEnd, toUpperCase, toLowerCase, includes, startsWith, endsWith, indexOf, lastIndexOf, split, replace, replaceAll, repeat, padStart, padEnd, slice, substring, charAt, charCodeAt, and at
str.lengthSupported with Go-shaped semanticsFollows Go len, so re-check Unicode assumptions
RegExp literals and constructorSupportedBacked by Go's RE2 engine
RegExp.test() / RegExp.exec()Supportedexec() returns Array<string> | null
string.match() / matchAll() / search() / replace() / split() with RegExpSupportedRuntime 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 ​

APIStatusNotes
PromiseNot supportedNo JS promise runtime
async/awaitNot supportedUse Go concurrency primitives
setTimeout / setIntervalNot supported as JS timersUse Go time APIs instead
fetchNot supported as a JS globalUse Go packages such as net/http
DOM / browser globalsNot supported by defaultOnly 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.