Parse parses an importmap from a JSON string.
(baseUrl *url.URL, data []byte)
| 119 | |
| 120 | // Parse parses an importmap from a JSON string. |
| 121 | func Parse(baseUrl *url.URL, data []byte) (im *ImportMap, err error) { |
| 122 | var importMapRaw ImportMapJson |
| 123 | if err = json.Unmarshal(data, &importMapRaw); err != nil { |
| 124 | return |
| 125 | } |
| 126 | scopes := make(map[string]*Imports) |
| 127 | for scope, imports := range importMapRaw.Scopes { |
| 128 | scopes[scope] = newImports(imports) |
| 129 | } |
| 130 | im = &ImportMap{ |
| 131 | baseUrl: baseUrl, |
| 132 | config: importMapRaw.Config, |
| 133 | Imports: newImports(importMapRaw.Imports), |
| 134 | scopes: scopes, |
| 135 | integrity: newImports(importMapRaw.Integrity), |
| 136 | } |
| 137 | return |
| 138 | } |
| 139 | |
| 140 | // Config returns the config of the import map. |
| 141 | func (im *ImportMap) Config() Config { |
no test coverage detected