Skip to content

Commit

Permalink
Add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jespertheend committed Oct 8, 2022
1 parent f9cbee7 commit 49fa456
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ function sortAndNormalizeModuleSpecifierMap(originalMap, baseURL) {
// 6. If specifierKey ends with U+002F (/), and the serialization of addressURL does not end with U+002F (/), then:
if (specifierKey.endsWith("/") && !addressURL.href.endsWith("/")) {
// 1. The user agent may report a warning to the console indicating that an invalid address was given for the specifier key specifierKey; since specifierKey ends with a slash, the address needs to as well.
console.warn(`An invalid address was given for "${specifierKey}". Since the specifier ended in a slash, the address needs to as well.`);
console.warn(
`An invalid address was given for "${specifierKey}". Since the specifier ended in a slash, the address needs to as well.`,
);

// 2. Set normalized[normalizedSpecifierKey] to null.
normalized[normalizedSpecifierKey] = null;
Expand All @@ -163,7 +165,6 @@ function sortAndNormalizeModuleSpecifierMap(originalMap, baseURL) {

// 7. Set normalized[normalizedSpecifierKey] to addressURL.
normalized[normalizedSpecifierKey] = addressURL;

}

// 3. Return the result of sorting in descending order normalized, with an entry a being less than an entry b if a's key is code unit less than b's key.
Expand Down
29 changes: 29 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Import maps

This module is a JavaScript implementation of the
[Import maps](https://html.spec.whatwg.org/multipage/webappapis.html#import-maps) spec.

## Usage

```js
import { parseImportMap, resolveModuleSpecifier } from "https://deno.land/x/import_maps/mod.js";

const baseUrl = new URL(import.meta.url);
const parsedImportMap = parseImportMap({
imports: {
"std/": "https://deno.land/std/",
}
}, baseUrl);

const resolved = resolveModuleSpecifier(parsedImportMap, baseUrl, "std/http/mod.ts");
console.log(resolved); // URL { href: "https://deno.land/std/http/mod.ts" }
```
Alternatively, you can use `createEmptyImportMap()` to simulate a situation where no import map is provided.
```js
import { createEmptyImportMap, resolveModuleSpecifier } from "https://deno.land/x/import_maps/mod.js";

const importMap = createEmptyImportMap();
resolveModuleSpecifier(parsedImportMap, baseUrl, "https://example.com");
```

0 comments on commit 49fa456

Please sign in to comment.