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"`
}
Data is the representation of the import map json file contents
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 returns the integrity attribute of the import map, which holds all the integrity values.
GetIntegrity() Integrity
// GetIntegrityValue returns the integrity value of the specified target.
//
// Parameters:
// - target: The target to get the integrity value for
// - integrity: The expected integrity value
//
// Returns the integrity value, error if there was an error.
GetIntegrityValue(target string, integrity string) (string, error)
// SetIntegrityValue sets the integrity value of the specified target
//
// Parameters:
// - target: The target to set the integrity value for
// - integrity: The integrity value to be set
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 will extend the import map with another import map
Extend(importMap IImportMap, overrideScopes bool) (IImportMap, error)
// Clone will clone the import map
Clone() IImportMap
// GetScopes returns the scopes attribute of the import map
GetScopes() Scopes
// GetImports returns the imports attribute of the import map
GetImports() Imports
}
func LoadFromFile ¶
func LoadFromFile(path string) (IImportMap, error)
LoadFromFile loads the contents of the import map file and returns an IImportMap instance
Click to show internal directories.
Click to hide internal directories.