npkg-pin
v0.0.1
Published
Convert NPM imports into UNPKG Pinned URL's
Downloads
3
Maintainers
Readme
About
UNPKG is a CDN built for JS packages. This module converts npm module id's into the optimized UNPKG URL for optimal performance.
Usage
NodeJS
import { unpkg } from 'unpkg-pin';
// Uses version of package found in node_modules (if it exists - otherwise 'latest')
await unpkg('hueman')
// ~> https://cdn.skypack.dev/pin/[email protected]/min/hueman.js
await unpkg('hueman', { pin: false })
// ~> https://cdn.skypack.dev/[email protected]
await unpkg('hueman', { min: false })
// ~> https://cdn.skypack.dev/[email protected]
// Specify version directly
await unpkg('[email protected]')
// ~> https://cdn.skypack.dev/pin/[email protected]/min/hueman.js
Browser Codepen
import { unpkg } from 'https://unpkg.com/unpkg-pin?module'
await unpkg('hueman')
API
unpkg(module_id, is_module)
-> URL
module_id
: String that identifies the package in npm (hueman
,uhtml@latest
,[email protected]
, etc.) (version number optional)is_module
: Whether or not to append?module
to the URL. See unpkg for more information- Returns: Promise that resolves to URL that can be used as an import statement in the browser
Uses the version of the package found in node_modules
. Requires that the module has been installed to the current working directory. May take a few seconds if the package has not been "pinned" on skypack before.
References
License
MIT © Marshall Brandt