{"name":"@import-maps/resolve","version":"0.2.6","publishConfig":{"access":"public"},"description":"Read and resolve urls via an import map","license":"MIT","repository":{"type":"git","url":"git+https://github.com/open-wc/open-wc.git","directory":"packages/import-maps-resolve"},"author":{"name":"open-wc"},"homepage":"https://github.com/open-wc/open-wc/tree/master/packages/import-maps-resolve","main":"dist/index.js","scripts":{"build":"babel src --out-dir dist --copy-files --include-dotfiles","prepublishOnly":"npm run build && ../../scripts/insert-header.js","start":"npm run build && node ./dist/index.js","test":"npm run test:node","test:node":"mocha --require @babel/register","test:watch":"onchange 'src/**/*.js' 'test/**/*.js' -- npm run test --silent"},"keywords":["import-map","import-maps"],"devDependencies":{"@babel/cli":"^7.8.4","@babel/core":"^7.9.0","@babel/preset-env":"^7.9.0","@babel/register":"^7.9.0","babel-plugin-transform-dynamic-import":"^2.1.0","onchange":"^5.2.0"},"bugs":{"url":"https://github.com/open-wc/open-wc/issues"},"_id":"@import-maps/resolve@0.2.6","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-IdI5OwfV/YB/zAhsTFNnN54U718VOpDaUQEUyoZ+r+jpyUnaOchmJAw8l9UsDI23AyHBKZOwEwU6eqjSn2M6Wg==","shasum":"27a97d0f069c7f3512eb9c1517bb7ee946ae6930","tarball":"http://registry-npm.ywwl.com/@import-maps/resolve/download/@import-maps/resolve-0.2.6.tgz","fileCount":7,"unpackedSize":22005,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJek4e4CRA9TVsSAnZWagAARWoP+wc+8KYhgc2TEAZSouqf\nWupjTflT/tQn9yfvDk0VDgTF3wWR1jdVOrDfV04A44BZ2KO8eEAgK2XmKjAG\nzGc5PacK0cZIf4bKm04FQ2fId1G3v16ONe6UycF7qIxr6dPzb1d+nYL0g5kB\n9lTUqnOpJfQTqM9HvDtLblW23OK1a1QgCLtPv8E7Y/7m2B6Sr4NHgozDrlfT\nZHaqrw16bwaTZQ0gGpikOMVS6ZFTSiv+gItjtycIjYWC/9ZY5j8JugFrFipJ\ndjPtwMoGdu+vy10HWfP3Ci5Myg8EyF3aMqTT0o2nMTX0rYJX8xD8MT1TLi3u\nkN5d3XqrfXcLkxN1XDTJ3yLDazTSLxcBcB231RCasTpQr2tiAV1mHkOlm+RL\nkRc3duulDjapI47nRhZi1X5nnrSxkYXCBIZFU+P80OnhYTnpAbGEEr88Kgdr\n34WtH1ChzYv7dnL9YcA97Q4OSAEUYaEk3YTmak3ugENlYq2wpo7k0JsEiFd0\n1aMMIdAhp25X2tuUeNmt5Mb25PV4j3p46ZTAg1k/4ktnWRykyMUDJ6OfrHyK\nMD4iWGqK21bsjzFP2LEpLTgzOjJs+qIAzdq6drC+T8oHf2FoF8ENl50u/aHa\nQ9Es1FBGv3aQwSKtCb2f1iuzk0KEdHaUhY/WV4HM1wTp1bJ8kvnRxMlwbIT8\neVXM\r\n=F71L\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEVUX7hut348Y2OftsfdXZOFSIyamETsa91NW1U3QAXdAiEAsXDTly62Khucn8aKMP0hqEeXHyVb/QAVTmtynOWjOTg="}],"size":6292,"noattachment":false,"key":"/@import-maps/resolve/-/@import-maps/resolve-0.2.6.tgz"},"maintainers":[{"name":"d4kmor","email":"d4kmor@gmail.com"}],"_npmUser":{"name":"d4kmor","email":"d4kmor@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/resolve_0.2.6_1586726840050_0.9299390455330172"},"_hasShrinkwrap":false,"readme":"# Resolve import-maps\n\nLibrary for parsing and resolving [import maps](https://github.com/WICG/import-maps).\n\n## Usage\n\n```bash\nnpm i --save-dev @import-maps/resolve\n```\n\n### Base URL\n\nParsing and resolving import maps requires a base URL. This is an instance of the `URL` constructor.\n\nThis can be a browser URL:\n\n```js\nconst myUrl = new URL('https://www.example.com/');\n```\n\nOr a file URL when working with a file system. The `pathToFileURL` function is useful for converting a file path to a URL object:\n\n```js\nimport path from 'path';\nimport { pathToFileURL } from 'url';\n\nconst fileUrl1 = new URL('file:///foo/bar');\nconst fileUrl2 = pathToFileURL(path.join(process.cwd(), 'foo', 'bar'));\n```\n\n### Parsing an import map from a string\n\nThe `parseFromString` function parses an import map from a JSON string. It returns the parsed import map object to be used when resolving import specifiers.\n\n```js\nimport { parseFromString } from '@import-maps/resolve';\n\n// get the import map from somewhere, for example read it from a string\nconst importMapString = '{ \"imports\": { \"foo\": \"./bar.js\" } }';\n// create a base URL to resolve imports relatively to\nconst baseURL = new URL('https://www.example.com/');\n\nconst importMap = parseFromString(importMapString, baseURL);\n```\n\n### Parsing an import map from an object\n\nIf you already have an object which represents the import map, it still needs to be parsed to validate it and to prepare it for resolving. You can use the `parse` function for this.\n\n```js\nimport { parse } from '@import-maps/resolve';\n\n// get the import map from somewhere, for example read it from a string\nconst rawImportMap = { imports: { foo: './bar.js' } };\n// create a base URL to resolve imports relatively to\nconst baseURL = new URL('https://www.example.com/');\n\nconst importMap = parse(rawImportMap, baseURL);\n```\n\n### Resolving imports\n\nOnce you've created a parsed import map, you can start resolving specifiers. The `resolve` function returns an object with the resolved URL as well as a boolean whether the import was matched. When a bare import is not found in the import map, resolve returns null. When a relative import isn't found, the resolved URL is returned, and matched will be set to false.\n\n```js\nimport { resolve } from '@import-maps/resolve';\n\nconst importMapString = '{ \"imports\": { \"foo\": \"./bar.js\" } }';\nconst baseURL = new URL('https://www.example.com/');\nconst importMap = parseFromString(importMapString, baseURL);\n\nconst scriptUrl = new URL('https://www.example.com/my-app.js');\n\n// resolvedImport: https://www.example.com/bar.js, matched: true\nconst { resolvedImport, matched } = resolve('foo', baseURL, scriptUrl);\n\n// resolvedImport: https://www.example.com/x.js, matched: false\nconst { resolvedImport, matched } = resolve('./x.js', baseURL, scriptUrl);\n\n// resolvedImport: null, matched: false\nconst { resolvedImport, matched } = resolve('bar', baseURL, scriptUrl);\n```\n\nIf you need to use the resolved path on the file system, you can use the `fileURLToPath` utility:\n\n```js\nimport { fileURLToPath } from 'url';\nimport { resolve } from '@import-maps/resolve';\n\nconst { resolvedImport } = resolve(importMapString, baseURL, scriptUrl);\n\n// the fully resolved file path\nconsole.log(fileURLToPath(resolvedImport));\n```\n\n## Acknowledgments\n\nThis implementation is heavily based on the [import-maps reference implementation](https://github.com/WICG/import-maps/tree/master/reference-implementation).\n","publish_time":1586726840215,"_cnpm_publish_time":1586726840215,"dist-tags":{"latest":"2.0.0"}}