1.0.0 • Published 10 years ago

shields-badge-url-custom v1.0.0

Weekly downloads
13
License
MIT
Repository
github
Last release
10 years ago

Custom Badge URLs

NPM version Build Status Coverage Status Dependencies

Creates Shields.io badge URLs for custom badges.

Installation

$ npm install shields-badge-url-custom

Usage

var urls = require( 'shields-badge-url-custom' );

urls( opts )

Creates Shields.io badge URLs for custom badges.

var opts = {
	'label': 'build',
	'status': 'passing',
	'color': 'brightgreen'
};

var out = urls( opts );
/*
	{
		"image": "https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat"
	}
*/ 

The function accepts the following options:

  • label: (required) badge label.
  • status: (required) badge status.
  • color: (required) badge color. A color may be either a named (e.g., brightgreen, green, yellow, red, etc) or HEX (e.g., 474747, eeeeee, etc).
  • style: badge style. Default: flat.
  • format: badge format. Default: svg.
  • logo: badge logo (>= 14px high and provided as a data URI).
  • width: badge width (pixels).
  • llink: left side link. (note: must be provided with a right side link.)
  • rlink: right side link. (note: must be provided with a left side link.)

Examples

var mnames = require( 'datasets-male-first-names-en' );
var fnames = require( 'datasets-female-first-names-en' );
var randc = require( 'rand-color-hexadecimal' );
var urls = require( 'shields-badge-url-custom' );

// Badges for everyone! Create random personalized greeting badges...
var badge;
var len;
var idx;
var n;
var i;

len = mnames.length + fnames.length;
for ( i = 0; i < len; i++ ) {
	if ( len%2 === 0 ) {
		idx = Math.floor( Math.random()*fnames.length );
		n = fnames[ idx ];
	} else {
		idx = Math.floor( Math.random()*mnames.length );
		n = mnames[ idx ];
	}
	badge = urls({
		'label': 'Hello,',
		'status': n + '!',
		'color': randc()
	});
	console.log( badge );
}

To run the example code from the top-level application directory,

$ node ./examples/index.js

CLI

Installation

To use the module as a general utility, install the module globally

$ npm install -g shields-badge-url-custom

Usage

Usage: shields-custom --label=<label> --status=<status> --color=<color> [options]

Options:

  -h,  --help                Print this message.
  -V,  --version             Print the package version.
       --label label         Badge label.
       --status status       Badge status.
       --color color         Badge color.
       --style style         Badge style. Default: 'flat'.
       --format format       Badge format. Default: 'svg'.
       --logo logo           Badge logo.
       --width width         Badge logo width (pixels).
       --llink link          Left side badge link.
       --rlink link          Right side badge link.

Examples

$ shields-custom --label=beep --status=boop --color="474747"
# => {"image":"https://img.shields.io/badge/beep-boop-474747.svg?style=flat"}

Tests

Unit

This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

Browser Support

This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:

$ make test-browsers

To view the tests in a local web browser,

$ make view-browser-tests

License

MIT license.

Copyright

Copyright © 2016. Athan Reines.