javascript

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package javascript provides a documentation source adapter that reads JavaScript source code from a local directory (downloaded from GitHub). It parses raw JS source via tree-sitter to extract classes, functions, module exports, and JSDoc without making any network calls during parsing.

The adapter is configurable for any JavaScript library (Node.js, React, Express, Lodash, etc.) via LibraryConfig.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAxiosFactory

func NewAxiosFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewAxiosFactory creates a Source for the Axios HTTP client.

func NewD3Factory

func NewD3Factory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewD3Factory creates a Source for the D3.js visualization library. The d3/d3 umbrella repo only re-exports submodules, so this indexes the d3-selection core module, which carries the canonical DOM-selection API.

func NewExpressFactory

func NewExpressFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewExpressFactory creates a Source for the Express.js web framework.

func NewFastifyFactory

func NewFastifyFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewFastifyFactory creates a Source for the Fastify web framework.

func NewHapiFactory

func NewHapiFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewHapiFactory creates a Source for the Hapi web framework.

func NewKoaFactory

func NewKoaFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewKoaFactory creates a Source for the Koa web framework.

func NewLodashFactory

func NewLodashFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewLodashFactory creates a Source for the Lodash utility library.

func NewMeteorFactory

func NewMeteorFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewMeteorFactory creates a Source for the Meteor framework.

func NewMochaFactory

func NewMochaFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewMochaFactory creates a Source for the Mocha testing framework.

func NewMoleculerFactory

func NewMoleculerFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewMoleculerFactory creates a Source for the Moleculer microservices framework.

func NewNodeJSFactory

func NewNodeJSFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewNodeJSFactory creates a Source for the Node.js standard library.

func NewReactFactory

func NewReactFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewReactFactory creates a Source for the React UI library.

func NewRemixFactory

func NewRemixFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewRemixFactory creates a Source for the Remix framework.

func NewRestifyFactory

func NewRestifyFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewRestifyFactory creates a Source for the Restify framework.

func NewSailsFactory

func NewSailsFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewSailsFactory creates a Source for the Sails.js MVC framework.

func NewSvelteKitFactory

func NewSvelteKitFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewSvelteKitFactory creates a Source for the SvelteKit framework.

func NewWSFactory

func NewWSFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewWSFactory creates a Source for the ws WebSocket library. Replaces Polka, whose single-file source carries no JSDoc to index.

func NewWebpackFactory

func NewWebpackFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)

NewWebpackFactory creates a Source for the Webpack module bundler.

Types

type LibraryConfig

type LibraryConfig struct {
	// ID is the canonical library ID (e.g., "/javascript/express").
	ID string

	// Name is the human-readable library name (e.g., "Express.js").
	Name string

	// Description is a short summary of what the library provides.
	Description string

	// SourceURL is the GitHub repository URL.
	SourceURL string

	// Version is the library version being indexed.
	Version string

	// SourceDirs are relative paths within the repo to scan for JS source.
	// If empty, the root directory is scanned.
	SourceDirs []string

	// BlobRef is the git ref for source-code links (e.g., "v4.18.2").
	// Defaults to "main" if empty.
	BlobRef string
}

LibraryConfig describes a JavaScript library to index.

type Option

type Option func(*Source)

Option customises a Source at construction time.

func WithConfig

func WithConfig(cfg LibraryConfig) Option

WithConfig sets the library configuration.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source is a documentation source adapter that reads JavaScript source code from a local directory. It implements the source.Source interface.

func New

func New(repoPath string, opts ...Option) *Source

New constructs a new JavaScript Source pointing at a local directory. The index is initialised to an empty (non-nil) state so that DetectWrapper and ResolveWrapperURL are safe to call before DiscoverEntities.

func (*Source) DetectWrapper

func (s *Source) DetectWrapper(method *source.Method) (bool, string, string)

DetectWrapper analyzes a method's source code for wrapper patterns.

func (*Source) DiscoverEntities

func (s *Source) DiscoverEntities(ctx context.Context, fetch source.FetchFunc) ([]string, error)

DiscoverEntities walks the local repository and returns a sorted list of entity identifiers. The fetch parameter is unused — all discovery reads files locally.

func (*Source) ID

func (s *Source) ID() string

ID returns the canonical library ID.

func (*Source) Meta

func (s *Source) Meta() source.LibraryMeta

Meta returns metadata for the library record.

func (*Source) ParseEntity

func (s *Source) ParseEntity(ctx context.Context, entityID string, content []byte) (*source.Entity, []string, error)

ParseEntity parses a single entity from file content, identified by entityID. Returns the entity data plus a list of method identifiers to crawl next.

func (*Source) ParseMethod

func (s *Source) ParseMethod(ctx context.Context, methodID string, content []byte) (*source.Method, error)

ParseMethod parses a single method from file content.

func (*Source) ParseSourceCode

func (s *Source) ParseSourceCode(entityID string, content []byte) (string, error)

ParseSourceCode extracts just the source code of a specific entity or method from file content.

func (*Source) ResolveWrapperURL

func (s *Source) ResolveWrapperURL(targetName, targetKind, entitySlug string) string

ResolveWrapperURL constructs the identifier to fetch the wrapped target's source. Returns an empty string if the target cannot be resolved.

Jump to

Keyboard shortcuts

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