importmap

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Imports   Imports   `json:"imports,omitempty"`
	Scopes    Scopes    `json:"scopes,omitempty"`
	Integrity Integrity `json:"integrity,omitempty"`
}

type IImportMap

type IImportMap interface {
	// Resolve performs a module resolution against the import map.
	//
	// Parameters:
	//   - specified: Specifier to resolve
	// Returns the resolved URL string.
	Resolve(specifier string) (string, error)

	// ResolveWithParent performs a module resolution against the import map.
	//
	// Parameters:
	//   - specified: Specifier to resolve
	//   - parentUrl: Parent URL to resolve against
	// Returns the resolved URL string.
	ResolveWithParent(specifier string, parentUrl *url.URL) (string, error)

	// Rebase will rebase the entire import map to a new mapUrl and rootUrl
	//
	// Parameters:
	//   - mapUrl: The new map URL to use
	//   - rootUrl: The new root URL to use
	// Returns IImportMap for chaining
	Rebase(mapUrl *url.URL, rootUrl *url.URL) error

	// Flatten groups the import map scopes to shared URLs to reduce duplicate mappings.
	//
	// For two given scopes, "https://site.com/x/" and "https://site.com/y/",
	// a single scope will be constructed for "https://site.com/" including
	// their shared mappings, only retaining the scopes if they have differences.
	//
	// In the case where the scope is on the same origin as the mapUrl, the grouped
	// scope is determined based on determining the common baseline over all local scopes.
	// Returns IImportMap for chaining
	Flatten() IImportMap

	// CombineSubPaths groups subpath mappings into path mappings when multiple exact subpaths
	// exist under the same path.
	//
	// For two mappings like { "base/a.js": "/a.js", "base/b.js": "/b.js" },
	// these will be replaced with a single path mapping { "base/": "/" }.
	// Groupings are done throughout all import scopes individually.
	//
	// Returns IImportMap for chaining
	CombineSubPaths() IImportMap

	// Replace will replace URLs in the import map in bulk
	// Provide a URL ending in "/" to perform path replacements.
	//
	// Parameters:
	//   - url: URL to replace
	//   - newUrl: URL to replace with
	//
	// Returns IImportMap for chaining
	Replace(url url.URL, newUrl url.URL) IImportMap

	GetIntegrity() Integrity

	GetIntegrityValue(target string, integrity string) (string, error)

	SetIntegrityValue(target string, integrity string) error

	// Set will set a specific entry in the import map.
	Set(name string, target string) IImportMap

	// SetWithParent will set a specific entry in the import map.
	SetWithParent(name string, target string, parent string) IImportMap

	Extend(importMap IImportMap, overrideScopes bool) (IImportMap, error)

	Clone() IImportMap

	GetScopes() Scopes

	GetImports() Imports
}

func LoadFromFile

func LoadFromFile(path string) (IImportMap, error)

LoadFromFile loads the contents of the import map file and returns an IImportMap instance

func New

func New(opts ...Option) (IImportMap, error)

New creates a new IImportMap instance

type Imports

type Imports map[string]string

type Integrity

type Integrity map[string]string

type Option

type Option func(options *Options)

func WithMap

func WithMap(importMap Data) Option

func WithMapUrl

func WithMapUrl(mapUrl *url.URL) Option

func WithRootUrl

func WithRootUrl(rootUrl *url.URL) Option

type Options

type Options struct {
	Map     Data
	MapUrl  *url.URL
	RootUrl *url.URL
}

type Scope

type Scope map[string]string

type Scopes

type Scopes map[string]Scope

Jump to

Keyboard shortcuts

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