{"id":15357222,"url":"https://github.com/gera2ld/npm2url","last_synced_at":"2025-06-25T02:06:53.616Z","repository":{"id":179502464,"uuid":"663589077","full_name":"gera2ld/npm2url","owner":"gera2ld","description":"Convert an NPM package import into a CDN URL.","archived":false,"fork":false,"pushed_at":"2024-12-26T06:57:04.000Z","size":66,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T06:46:15.928Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gera2ld.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-07-07T16:41:24.000Z","updated_at":"2025-03-04T12:55:29.000Z","dependencies_parsed_at":"2025-04-15T06:43:11.592Z","dependency_job_id":"42bcad8f-3c31-450e-b2c3-bffaafb268ee","html_url":"https://github.com/gera2ld/npm2url","commit_stats":null,"previous_names":["gera2ld/npm2url"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/gera2ld/npm2url","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gera2ld%2Fnpm2url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gera2ld%2Fnpm2url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gera2ld%2Fnpm2url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gera2ld%2Fnpm2url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gera2ld","download_url":"https://codeload.github.com/gera2ld/npm2url/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gera2ld%2Fnpm2url/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261789264,"owners_count":23209775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T12:34:05.698Z","updated_at":"2025-06-25T02:06:53.605Z","avatar_url":"https://github.com/gera2ld.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# npm2url\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![JSDocs][jsdocs-src]][jsdocs-href]\n\nConvert an NPM package import into a CDN URL.\n\nThis is useful when you want your users to access the assets without needing to install the dependencies, and not being tied to a certain CDN.\n\n## Installation\n\nInstall package:\n\n```sh\npnpm install npm2url\n```\n\n## Quick Start\n\n```ts\nimport { UrlBuilder, urlBuilder } from \"npm2url\";\n\n// Get the full CDN URL for `npm2url` package, using the default provider\nconsole.log(urlBuilder.getFullUrl(\"npm2url\"));\n// -\u003e https://cdn.jsdelivr.net/npm/npm2url\n\n// Get the full CDN URL for `npm2url` package, specifically using `jsdelivr` provider\nconsole.log(urlBuilder.getFullUrl(\"npm2url\", \"jsdelivr\"));\n// -\u003e https://cdn.jsdelivr.net/npm/npm2url\n\n// You may also create a new instance to hold different properties\nconst anotherBuilder = new UrlBuilder();\nconsole.log(anotherBuilder.getFullUrl(\"npm2url\"));\n```\n\n## Advanced Usage\n\n### Providers\n\n```ts\nimport { urlBuilder } from \"npm2url\";\n\n// Show all available providers\nconsole.log(urlBuilder.providers);\n// -\u003e { jsdelivr: [Function], unpkg: [Function] }\n\n// Show the name of the current provider\nconsole.log(urlBuilder.provider);\n// -\u003e 'jsdelivr'\n```\n\nA provider is a simple function that accepts an npm path and returns a full URL string.\n\n```ts\n// Create a local provider\nconst providerName = \"local\";\nurlBuilder.providers[providerName] = (path: string) =\u003e\n  `http://localhost:8080/assets/${path}`;\n\n// Change the selected provider\nurlBuilder.provider = providerName;\n```\n\nBy default, there are two providers:\n\n- `jsdelivr` (default)\n- `unpkg`\n\n### The fastest provider\n\nUsers from different regions may benefit from different CDNs. So we'd better check the connections to get the best CDN provider.\n\n```ts\nimport { urlBuilder } from \"npm2url\";\n\n// Update the selected provider to the fastest one\nawait urlBuilder.findFastestProvider();\n// `urlBuilder.provider` is updated to the fastest provider\nconsole.log(urlBuilder.getFullUrl(\"npm2url\"));\n// -\u003e The fastest URL\n\n// Or you may hope to get the fastest provider without changing the selected one\nconst fastest = await urlBuilder.getFastestProvider();\n// `urlBuilder.provider` is not changed, pass `fastest` explicitly\nconsole.log(urlBuilder.getFullUrl(\"npm2url\", fastest));\n// -\u003e The fastest URL\n```\n\nNote that an error will be thrown if none of the providers is reachable.\n\n## License\n\nMade with 💛\n\nPublished under [MIT License](./LICENSE).\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/npm2url?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[npm-version-href]: https://npmjs.com/package/npm2url\n[npm-downloads-src]: https://img.shields.io/npm/dm/npm2url?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/npm2url\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/npm2url?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[bundle-href]: https://bundlephobia.com/result?p=npm2url\n[jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[jsdocs-href]: https://www.jsdocs.io/package/npm2url\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgera2ld%2Fnpm2url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgera2ld%2Fnpm2url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgera2ld%2Fnpm2url/lists"}