🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

vimagination.zapto.org/tsserver

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/tsserver

Go Modules
Version
v1.2.0
Version published
Created
Source

tsserver

CI Go Reference Go Report Card

-- import "vimagination.zapto.org/tsserver"

Package tsserver implements a simple wrapper around fs.FS to intercept calls to open Javascript files, and instead open their Typescript equivalents and generate the Javascript, commenting out any typescipt parts.

Highlights

  • Wrap any fs.FS implementation.
  • Automatically transpiles Typescript files to Javascript.
  • Customisable error output.

Usage

package main

import (
	"fmt"
	"io"
	"io/fs"
	"os"
	"strings"
	"time"

	"vimagination.zapto.org/tsserver"
)

type memFS map[string]string

func (m memFS) Open(path string) (fs.File, error) {
	if str, ok := m[path]; ok {
		return &memFile{
			name:   path,
			Reader: strings.NewReader(str),
			size:   len(str),
		}, nil
	}

	return nil, fs.ErrNotExist
}

type memFile struct {
	name string
	*strings.Reader
	size int
}

func (m *memFile) Stat() (fs.FileInfo, error) { return m, nil }
func (m *memFile) Close() error               { return nil }
func (m *memFile) Name() string               { return m.name }
func (m *memFile) Size() int64                { return int64(m.size) }
func (m *memFile) Mode() fs.FileMode          { return fs.ModePerm }
func (m *memFile) ModTime() time.Time         { return time.Now() }
func (m *memFile) IsDir() bool                { return false }
func (m *memFile) Sys() any                   { return m }

func main() {
	files := tsserver.WrapFS(memFS{
		"main.ts": "function hello(name: string) {console.log('Hello ' + name);}\n\nhello('Bob');",
	})

	file, err := files.Open("main.js")
	if err != nil {
		fmt.Println(err)

		return
	}
	defer file.Close()

	io.Copy(os.Stdout, file)

	// Output:
	// function hello(name/*: string*/) {console.log('Hello ' + name);}
	//
	// hello('Bob');
}

Documentation

Full API docs can be found at:

https://pkg.go.dev/vimagination.zapto.org/tsserver

FAQs

Package last updated on 09 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts