unpkg-uri
v0.1.0
Published
Generates unpkg.com URI from given npm package name
Readme
unpkg-uri
Generates unpkg.com URI from given npm package name.
unpkg-uri generates unpkg's https://unpkg.com/@:prefix/:package@:version/:file uri from given package name.
Install
$ npm install --save unpkg-uriUsage
const { unpkg } = require('unpkg-uri')
unpkg('unpkg-uri')
//=> 'https://unpkg.com/[email protected]/lib/index.js'
unpkg('unpkg-uri[min.js]')
//=> 'https://unpkg.com/[email protected]/lib/index.min.js'
unpkg('unpkg-uri|file.json')
//=> 'https://unpkg.com/[email protected]/lib/file.json'
unpkg('unpkg-uri/package.json')
//=> 'https://unpkg.com/[email protected]/package.json'
unpkg('[email protected]')
//=> 'https://unpkg.com/[email protected]/lib/index.js'
unpkg('@prefix/unpkg-uri')
//=> 'https://unpkg.com/@prefix/[email protected]/lib/index.js'Note: unpkg-uri does not include UMD builds. Examples above work but fail to run on browsers.
API
unpkg(name[, options])
unpkg makes unpkg.com URI from name.
If installed npm package is found in node_modules of working directory, unpkg reads ${name}/package.json and uses version, unpkg, and main field to determine exact unpkg.com URI.
name
Type: string
name can be one of bellow patterns:
:package:package[:ext]:package|:filename:package/:filepath:package@:version:package@:version[:ext]:package@:version|:filename:package@:version/:filepath@
:prefix/:package@
:prefix/:package[:ext]@
:prefix/:package|:filename@
:prefix/:package/:filepath@
:prefix/:package@:version@
:prefix/:package@:version[:ext]@
:prefix/:package@:version|:filename@
:prefix/:package@:version/:filepath
If :ext is specified, unpkg replaces the unpkg or main field with given extension.
If :filename is specified, unpkg replaces the unpkg or main field with given filename.
If :filepath is specified, unpkg does not use unpkg or main field.
If :version is not specified, unpkg uses the version field in package.json.
options
Type: Object
You can pass :ext, :filename, :filepath, :version by options argument.
options values will be overwritten if the same parameter is specified in name argument.
options.ext
Type: string
Default: 'js'
options.filename
Type: string
options.filepath
Type: string
options.version
Type: string
License
MIT © Tabian Co.
