unpkg-pin
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published
unpkg-pin Logo

unpkg-pin

Convert NPM imports into UNPKG Pinned URL's

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/hueman@v2.1.1-ElNqhC8YFxLlgRtjjL9o/min/hueman.js

await unpkg('hueman', { pin: false })
// ~> https://cdn.skypack.dev/hueman@2.1.1

await unpkg('hueman', { min: false })
// ~> https://cdn.skypack.dev/hueman@2.1.1

// Specify version directly
await unpkg('hueman@2.0.0')
// ~> https://cdn.skypack.dev/pin/hueman@v2.0.0-Eh8v1x3dV0iEyJ9rG915/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, themepark@1.0.0, 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

Package Sidebar

Install

npm i unpkg-pin

Weekly Downloads

7

Version

1.0.0

License

MIT

Unpacked Size

14.1 kB

Total Files

9

Last publish

Collaborators

  • marshallcb