npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

starry-rating

v5.1.0

Published

JavaScript star rating system

Downloads

58

Readme

Starry 🌟🌃💖

Screenshot

Starry Documentation

Installation

Include Starry scripts and stylesheets in your html DOM:

<link rel="stylesheet" type="text/css" href="./dist/starry.min.css" />
<script type='text/javascript' language='javascript' src='./dist/starry.min.js'></script>

Or install Starry as a Node dependency:

$ npm install starry-rating
import Starry from 'starry-rating'

// or with require...
const Starry = require('starry-rating')

How to use

HTML markup

<!-- Use a simple div container which is selectable by id or class -->
<div id="star-rating"></div>

JavaScript API

var starRatingEl = document.getElementById('star-rating');
var starRating = new Starry(starRatingEl);

More complex example

More complex example of a star rating with tooltips and custom icons, which is logging the rating to console. Tooltips have to be rendered in onRender() method by any tooltip library. In this example we use Bootstrap tooltips with jQuery & Popper.js.

var starRatingId = 'ExampleRating'; // Html DOM id + star rating element name
var starRatingEl = document.getElementById(starRatingId);
var starRating = new Starry(starRatingEl, {
	name: starRatingId, // Use a name to determine tooltips for only this Starry element
	labels: [
		'Low',
		'Nice to have',
		'Very nice',
		'Perfect',
		'Excellent'
	],
	onClear: function () {
		$('[data-name="' + starRatingId + '"] [data-tooltip]').tooltip('dispose');
	},
	onRender: function () {
		$('[data-name="' + starRatingId + '"] [data-tooltip]').tooltip({
			trigger: 'hover',
			placement: 'top'
		});
	},
	onRate: function (rating) {
		console.log(rating)
	},
	icons: {
		// File path, uri or base64 string for `src` attribute
		blank: './dist/icons/blank.svg',
		hover: './dist/icons/hover.svg',
		active: './dist/icons/active.svg'
	}
});

Options

| Option | Type | Default | Description | | ------------------- | --------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------ | | name | String | | Name of star rating element. This option is required, if multi rating is disabled. | | stars | Integer | 5 | Number of rating stars. | | multiRating | Boolean | true | Determines whether the user can submit several ratings. | | beginWith | Float | 0 | Preloaded rating in percentage. | | readOnly | Boolean | false | Read only rating stars. | | staticActiveRating | Boolean | true | Show current rating while hovering over rating stars. | | setStarsAfterRating | Boolean | true | Update rating stars after rating to new value. | | labels | Array / Boolean | false | Labels / tooltips for the stars. | | onRate | Function | (rating) => true | Called on rating event. | | onClear | Function | undefined | Called each time when Starry is being destroyed or rebuilt. | | onRender | Function | undefined | Called each time when Starry is build / rendered in html DOM. | | icons | Object | Default Starry icons. | Icon images. Object with properties blank (blank), active (blank) and hover (blank). Use a string for each image source. |

Methods

Get current rating getCurrentRating()
console.log(starRating.getCurrentRating())
Destroy Starry clear()
starRating.clear()
Update Starry with new configurations update(config)

Starry will merge the new configurations into the old ones.

starRating.update({
	readOnly: true,
	beginWith: 50
})
Attach event listener on(eventName, callbackFunction)

Attach an event listener to the star rating.

starRating.on('rate', function (rating) {
	console.log('Rating: ' + rating)
})

Events

| Name | Arguments | Description | | ------ | --------- | -------------------- | | rate | rating | Fired on rating. | | render | | Fired on rendering. | | clear | | Fired on destroying. |

Cookies

Starry use cookies, to save ratings! 🍪

License

The MIT License (MIT) - View LICENSE.md

Resources