Skip to content

Latest commit

 

History

History

jsdelivr-url

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

jsDelivr

Generate a jsDelivr URL for a file hosted in a public GitHub repository.

Usage

var jsdelivr = require( '@stdlib/_tools/utils/jsdelivr-url' );

jsdelivr( opts )

Returns a jsDelivr URL for a file hosted in a public GitHub repository.

var opts = {
    'slug': 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34',
    'file': 'README.md'
};

var url = jsdelivr( opts );
// returns 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@5c53c78310e7c2cb8b3c166555d0fb81a3723f34/README.md'

The function accepts the following options:

  • slug: public GitHub repository slug (required). The slug should include owner and repo information and should include either commit, branch, or tag information. For example,

    • stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34
    • stdlib-js/stdlib/develop
    • ...etc.
  • file: filepath (required). For example,

    • lib/index.js
    • ./README.md
    • ...etc.

Examples

var jsdelivr = require( '@stdlib/_tools/utils/jsdelivr-url' );

var opts = {
    'slug': 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34',
    'file': 'README.md'
};

var url = jsdelivr( opts );

console.log( url );
// => 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@5c53c78310e7c2cb8b3c166555d0fb81a3723f34/README.md'

CLI

Usage

Usage: jsdelivr [options] <file>

Options:

  -h,  --help               Print this message.
  -V,  --version            Print the package version.
       --slug slug          GitHub repository slug (should include branch,
                            commit, or tag info).

Notes

  • If not provided a slug, the module attempts to resolve a slug from a local .git repository located in the current working directory of the calling process. The slug is a combination of remote.origin.url and the current Git hash. For example,

    $ git config --get remote.origin.url
    https://github.com/stdlib-js/stdlib.git
    
    $ git rev-parse HEAD
    5c53c78310e7c2cb8b3c166555d0fb81a3723f34

becomes

var slug = 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34';

Examples

$ jsdelivr README.md --slug 'stdlib-js/stdlib/develop'
https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@develop/README.md

To infer a GitHub repository slug from a local .git repository, omit the slug option.

$ jsdelivr docs/assets/web/logo_header.png
https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@345a31cb0e0cc534ccedaa91775873f3da2038c2/docs/assets/web/logo_header.png