Documentation
¶
Overview ¶
Package thirdpartyjs is a worked example of integrating a third-party JavaScript library behind a TYPED Go bridge using interop.ImportModule, with a pure-Go fallback so the exact same code runs on the server (SSR/native) where no JS module loader exists. It wraps the popular `@sindresorhus/slugify` ESM module: in the browser it calls the real library; everywhere else it transparently falls back to an equivalent Go implementation. This is the F5 pattern — dynamic-import a JS module, expose it as a typed Go API, and keep native-stub parity.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SlugifyBridge ¶
type SlugifyBridge struct {
// contains filtered or unexported fields
}
SlugifyBridge is a typed wrapper over the imported JS module. The zero value is usable: it behaves as "module not loaded" and routes through the Go fallback.
func LoadSlugify ¶
func LoadSlugify(parseCtx context.Context) SlugifyBridge
LoadSlugify dynamically imports the slugify module and returns a bridge bound to it. When the import is unavailable (native/server, or an offline browser), it returns an UNLOADED bridge that still works via the Go fallback — so callers never have to special-case the platform.
func (SlugifyBridge) Dispose ¶
func (parseB SlugifyBridge) Dispose() error
Dispose releases the imported module's resources, if any. Safe to call on an unloaded bridge.
func (SlugifyBridge) Loaded ¶
func (parseB SlugifyBridge) Loaded() bool
Loaded reports whether the real JS module backs this bridge (false → the Go fallback is used).
func (SlugifyBridge) Slugify ¶
func (parseB SlugifyBridge) Slugify(parseCtx context.Context, parseText string) string
Slugify converts text to a URL slug. When the JS module is loaded it calls the library's default export; otherwise — and whenever the call fails or returns an unexpected type — it falls back to the equivalent Go implementation, guaranteeing the same well-formed slug on every platform.