https://github.com/tenphi/node-color
NodeJS module for CSS color manipulations. The project is DEPRECATED.
https://github.com/tenphi/node-color
Last synced: about 1 month ago
JSON representation
NodeJS module for CSS color manipulations. The project is DEPRECATED.
- Host: GitHub
- URL: https://github.com/tenphi/node-color
- Owner: tenphi
- License: mit
- Created: 2012-02-10T18:18:34.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2012-02-11T07:05:13.000Z (over 14 years ago)
- Last Synced: 2025-01-26T18:15:46.323Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 102 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
With this module you can simple manipulate color`s parameters.
Just create one:
```javascript
var color = require('color');
color('#39f');
color([51, 153, 255]); // rgb
color([114, .5, .5], 'hsl'); // hsl
```
You can also set additional parameter for opacity:
```javascript
var clr = color([51, 153, 255, .5]); // 50% opacity
```
Now you can use LESS-like API for change color parameters:
```javascript
clr.lighten(.1); // return a color which is 10% *lighter* than base color
clr.darken(.1); // return a color which is 10% *darker* than base color
clr.saturate(.1); // return a color 10% *more* saturated than base color
clr.desaturate(.1); // return a color 10% *less* saturated than base color
clr.fadein(.1); // return a color 10% *less* transparent than base color
clr.fadeout(.1); // return a color 10% *more* transparent than base color
clr.fade(.5); // return base color with 50% transparency
clr.spin(10); // return a color with a 10 degree larger in hue than base color
clr.spin(-10); // return a color with a 10 degree smaller hue than base color
clr.mix(clr2); // return a mix of base color and other color
```
Now, you can fetch your color:
```javascript
color('#39f').toString(); // "#3399ff"
color('#39f') + ''; // "#3399ff"
color('#39f').hex(); // "#3399ff"
color('#39f').rgb(); // rgb(51, 153, 255)
color([153, 153, 255, .5]); // rgba(51, 153, 255, 0.5)
```
Get/set absolute parameters of color:
```javascript
clr.lightness(.5).lightness(); // .5
clr.saturation(.5).saturation(); // .5
clr.hue(180).hue(); // 180
clr.fade(.5).fade(); // .5
```
It's not all! Also you have a really nice function that can calculate and set real (visible) lightness of your color. This value between 0 to 360. Check this out:
```javascript
color('#39f').luminance(); // 144.8760297633808
color('#39f').luminance(200).hex(); // "#9fcfff"
```
It can be very useful!
Luminance calculating by following formula: `Math.sqrt(red*red*.241 + green*green*.691+blue*blue*.068);`
Color module can store your colors. For example, this is some Twitter Bootstrap colors that defined by default:
```javascript
color({
black: '#000',
grayDarker: '#222',
grayDark: '#333',
gray: '#555',
grayLight: '#999',
grayLighter: '#eee',
white: '#fff',
blue: '#049cdb',
green: '#46a546',
red: '#9d261d',
yellow: '#ffc40d',
orange: '#f89406',
pink: '#c3325f',
purple: '#7a43b6'
});
_.color('myColor', '#303639'); /* store one color */
```
And then select them by their names:
```javascript
color('purple').lighten(.1).hex(); // "#8752bf"
```
If you have some ideas how improve this module you can send them to my email: tenphi@gmail.com
Enjoy!