Generate a RawGit URL for a file hosted in a public GitHub repository.
var rawgit = require( '@stdlib/_tools/utils/rawgit-url' );Returns a RawGit URL for a file hosted in a public GitHub repository.
var opts = {
'slug': 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34',
'file': 'README.md'
};
var url = rawgit( opts );
// returns 'https://cdn.rawgit.com/stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34/README.md'The function accepts the following options:
-
slug: public GitHub repository slug (required). The slug should include
ownerandrepoinformation and should include eithercommit,branch, ortaginformation. For example,stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34stdlib-js/stdlib/develop- ...etc.
-
file: filepath (required). For example,
lib/index.js./README.md- ...etc.
-
cdn:
booleanindicating whether to return a CDN URL. Default:true.
By default, the function returns a CDN URL. To return a (non-production) URL for development or testing, set the cdn option to false.
var opts = {
'slug': 'stdlib-js/stdlib/develop',
'file': 'lib/node_modules/@stdlib/index.js',
'cdn': false
};
var url = rawgit( opts );
// returns 'https://rawgit.com/stdlib-js/stdlib/develop/lib/node_modules/@stdlib/index.js'var rawgit = require( '@stdlib/_tools/utils/rawgit-url' );
var opts = {
'cdn': true,
'slug': 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34',
'file': 'README.md'
};
var url = rawgit( opts );
console.log( url );
// => 'https://cdn.rawgit.com/stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34/README.md'Usage: rawgit [options] <file>
Options:
-h, --help Print this message.
-V, --version Print the package version.
--no-cdn Return a dev/testing URL.
--slug slug GitHub repository slug (should include branch,
commit, or tag info).
-
If not provided a
slug, the module attempts to resolve aslugfrom a local.gitrepository located in the current working directory of the calling process. Theslugis a combination ofremote.origin.urland 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';$ rawgit README.md --slug 'stdlib-js/stdlib/develop'
https://cdn.rawgit.com/stdlib-js/stdlib/develop/README.mdTo infer a GitHub repository slug from a local .git repository, omit the slug option.
$ rawgit docs/assets/web/logo_header.png
https://cdn.rawgit.com/stdlib-js/stdlib/345a31cb0e0cc534ccedaa91775873f3da2038c2/docs/assets/web/logo_header.png