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

ministyle

v0.1.4

Published

Minimal chainable semantic output styler/writer

Downloads

5,311

Readme

ministyle

Build Status Dependency Status NPM version

Minimal semantic output styler API with default implementations.

A pluggable output styler/coloriser interface to embed in (development) tools and reporters. Offers a standard interface for customisable styled text output. The minimalistic API allows for overwrites to suit any environment.

Intend as companion to miniwrite (et al).

API

Main usage:

// standard console colors
var ms = ministyle.ansi();

// semantic stylers (and color conventions)
var str = ms.muted('ignorable grey');
var str = ms.plain('plain main');
var str = ms.accent('flashy cyan');
var str = ms.signal('bright magenta');
var str = ms.success('good green');
var str = ms.warning('annoying yellow');
var str = ms.error('bad red');

// usage
console.log('this is ' + ms.success('very amaze'));

Bundled implementations:

// default
var ms = ministyle.base();
// return as-is
var ms = ministyle.plain();
// ansi terminal codes
var ms = ministyle.ansi();

// html spans with default colors
var ms = ministyle.html();
// html spans with css class
var ms = ministyle.css();

// colors.js getters
var ms = ministyle.colorjs();
// grunt v0.4.x
var ms = ministyle.grunt();

// blank chars
var ms = ministyle.empty();

// dev style wraps with [style:names])
var ms = ministyle.dev();

Advanced sub types

Apply each style in-order

// standard methods will pass the value though each sub-style and return the result
var ms = ministyle.stack(styles);
ms.enabled = true;
ms.stack = [];

Peek and update string:

// standard methods pass value through callback
var ms = ministyle.peek(callback, main, alt?);
ms.enabled = true;
ms.callback = function(str, type, main, alt); //return new string, or false to send input to alt
ms.target = otherStyleA;
ms.alt = otherStyleB;

Toggle to alternative:

// standard methods will use main if enabled, otherwise alt
var ms = ministyle.toggle(main, alt?);
ms.main = otherStyleA;
ms.alt = otherStyleB;
ms.enabled = true;
ms.toggle();
// hacky
ms.active = otherStyleC; 

Build your own

var obj = {
	plain: function (str) {
		return str;
	},
	success: function (str) {
		return str;
	},
	accent: function (str) {
		return str;
	},
	signal: function (str) {
		return str;
	},
	warning: function (str) {
		return str;
	},
	error: function (str) {
		return str;
	},
	muted: function (str) {
		return str;
	}
};

Examples

Make it bigger:

var ms = ministyle.plain();
ms.error = ms.success = function(str) {
	return str.toUpperCase();
};

Safe html:

var ms = ministyle.peek(ministyle.escapeHTML, ministyle.css());

Installation

$ npm install ministyle --save

Future

  1. Code/style generator to replicate style-type logic (needs to be efficient though).

History

  • 0.1.4 - Update to fix npm's README
  • 0.1.2 - Added signal colour, enabled strict mode, split in internal modules
  • 0.1.0 - Added tests, publishing to npm.
  • 0.0.1 - Extracted styling from miniwrite.

Build

Install development dependencies in your git checkout:

$ npm install

Build and run tests:

$ grunt

See the Gruntfile.js for additional commands.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Note: this is an opinionated module: please create a ticket to discuss any big ideas. Pull requests for bug fixes are of course always welcome.

License

Copyright (c) 2013 Bart van der Schoor

Licensed under the MIT license.