Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Add colors methods to Function.prototype
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
CHANGELOG.md
LICENSE-MIT
README.md
grunt.js
package.json

README.md

fn-colors Donate on Gittip

Add colors methods to Function.prototype

WARNING: This will result in context (i.e. this) loss every time unless you use .bind.

Getting Started

Install the module with: npm install fn-colors

var fn_colors = require('fn-colors');
console.log.green('Hello World!'); // 'Hello World!' in green

Documentation

Currently, only default colors and styles work. fn-colors returns the colors which has a proxied addProperty(color, func), allowing you to add colors one-by-one.

If you are dying for your setTheme support, please create an issue. I am pretty fast at responding and patching. However, this was a side project of a side project of a side project.

How does it work?

fn-colors operates by directly extending Function.prototype. For each color added, it adds a getter property which will colorize any function it is invoke on.

To dive deeper, it receives console.log as its context (i.e. this) when console.log.green is run. It wraps the function (console.log in this case) and returns a special function (i.e. colorizedFn) such that any time it is invoked, it maps all the string arguments into colorized strings.

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 via grunt and test via npm test.

License

Copyright (c) 2013 Todd Wolfson

Licensed under the MIT license.

Something went wrong with that request. Please try again.