Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

release 0.0.1

  • Loading branch information...
commit 5edf98c107529a3ccdbade71237bbe6b91519652 0 parents
@niftylettuce niftylettuce authored
103 .gitignore
@@ -0,0 +1,103 @@
+
+# ------------------------------------------------------------------------------
+# Common Node files and folders
+# https://github.com/github/gitignore/blob/master/Node.gitignore
+# ------------------------------------------------------------------------------
+
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
+
+
+# ------------------------------------------------------------------------------
+# Nodemon
+# ------------------------------------------------------------------------------
+
+.monitor
+
+
+# ------------------------------------------------------------------------------
+# JSHint
+# ------------------------------------------------------------------------------
+
+jshint
+
+
+# ------------------------------------------------------------------------------
+# Numerous always-ignore extensions
+# ------------------------------------------------------------------------------
+
+*.diff
+*.err
+*.orig
+*.rej
+*.swo
+*.swp
+*.vi
+*~
+*.sass-cache
+
+
+# ------------------------------------------------------------------------------
+# Files from other repository control systems
+# ------------------------------------------------------------------------------
+
+.hg
+.svn
+.CVS
+
+
+# ------------------------------------------------------------------------------
+# Your ideas
+# ------------------------------------------------------------------------------
+
+.idea
+
+
+# ------------------------------------------------------------------------------
+# OS X and other IDE's folder attributes
+# ------------------------------------------------------------------------------
+
+.DS_Store
+Thumbs.db
+.cache
+.project
+.settings
+.tmproj
+*.esproj
+nbproject
+*.sublime-project
+*.sublime-workspace
+
+
+# ------------------------------------------------------------------------------
+# Dreamweaver added files
+# ------------------------------------------------------------------------------
+
+_notes
+dwsync.xml
+
+
+# ------------------------------------------------------------------------------
+# Komodo
+# ------------------------------------------------------------------------------
+
+*.komodoproject
+.komodotools
+
+
+# ------------------------------------------------------------------------------
+# Add your custom excludes below
+# ------------------------------------------------------------------------------
50 .jshintrc
@@ -0,0 +1,50 @@
+{
+ "predef": [
+ "jasmine",
+ "spyOn",
+ "it",
+ "console",
+ "describe",
+ "expect",
+ "beforeEach",
+ "waits",
+ "waitsFor",
+ "runs",
+ "alert",
+ "confirm",
+ "Modernizr",
+ "impress",
+ "exports",
+ "self"
+ ],
+
+ "node" : true,
+ "es5" : true,
+ "browser" : true,
+ "jquery": true,
+
+ "boss" : false,
+ "curly": false,
+ "debug": false,
+ "devel": false,
+ "eqeqeq": true,
+ "evil": true,
+ "forin": false,
+ "immed": false,
+ "laxbreak": true,
+ "laxcomma": true,
+ "newcap": true,
+ "noarg": true,
+ "noempty": false,
+ "nonew": false,
+ "nomen": false,
+ "onevar": false,
+ "plusplus": false,
+ "regexp": false,
+ "undef": true,
+ "sub": true,
+ "strict": false,
+ "white": false,
+ "indent": 2,
+ "asi": true
+}
116 Readme.md
@@ -0,0 +1,116 @@
+
+# PMS Pantone® Color Chart
+
+**NOTE:** PANTONE® and other Pantone, Inc. trademarks are the property of [Pantone, Inc.][1]
+
+This module finds the nearest PMS color using hex or rgb colors from CLI or as a dependency.
+
+
+## Install
+
+```bash
+npm install -g pantone
+```
+
+
+## CLI
+
+Let's try to find the nearest PMS color to [Teelaunch's][2] blue in hex:
+
+![Teelaunch Logo](https://d33304ifi1rp4s.cloudfront.net/img/teelaunch-logo.png "Teelaunch Logo")
+
+```bash
+pantone -hex 2A70AE
+```
+
+Or we could use the rgb values:
+
+```bash
+pantone -rgb 42,112,174
+```
+
+Output in table format on command line:
+
+```bash
+┌───────┬─────────────────┬────┬─────┬─────┬─────────┐
+│ dist │ name │ r │ g │ b │ hex │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.023 │ 660 │ 66 │ 107 │ 186 │ #426BBA │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.037 │ 2728 │ 51 │ 66 │ 181 │ #3342B5 │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.042 │ 285 │ 26 │ 117 │ 207 │ #1A75CF │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.046 │ 7455 │ 77 │ 89 │ 171 │ #4D59AB │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.050 │ 653 │ 54 │ 87 │ 140 │ #36578C │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.053 │ 7459 │ 71 │ 153 │ 181 │ #4799B5 │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.055 │ 641 │ 0 │ 120 │ 173 │ #0078AD │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.056 │ 307 │ 0 │ 120 │ 171 │ #0078AB │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.057 │ 647 │ 38 │ 87 │ 135 │ #265787 │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.058 │ 7462 │ 13 │ 92 │ 145 │ #0D5C91 │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.064 │ Process Blue 2X │ 0 │ 119 │ 191 │ #0077BF │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.064 │ 801 2X │ 0 │ 137 │ 175 │ #0089AF │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.064 │ 3015 │ 0 │ 102 │ 158 │ #00669E │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.065 │ 7468 │ 0 │ 121 │ 156 │ #00789C │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.066 │ 314 │ 0 │ 133 │ 161 │ #0085A1 │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.066 │ 633 │ 0 │ 128 │ 158 │ #00809E │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.066 │ 2945 │ 0 │ 87 │ 166 │ #0057A6 │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.070 │ 7473 │ 54 │ 163 │ 145 │ #36A391 │
+├───────┼─────────────────┼────┼─────┼─────┼─────────┤
+│ 0.071 │ 640 │ 0 │ 140 │ 186 │ #008CBA │
+└───────┴─────────────────┴────┴─────┴─────┴─────────┘
+```
+
+
+## Dependency
+
+```bash
+cd ~/project
+npm install pantone
+```
+
+```js
+var pantone = require('pantone')
+
+// rgb usage
+
+pantone({ r: 42, g: 112, b: 174 }, rgbCallback)
+
+function rgbCallback(err, results) {
+ if (err) throw new Error(err)
+ console.log(results)
+}
+
+// hex usage
+
+pantone({ hex: '#2A70AE' }, hexCallback) // you can also use `rgb` instead of `hex`
+
+function hexCallback(err, results) {
+ if (err) throw new Error(err)
+ console.log(results)
+}
+```
+
+## Links
+
+* Website: <http://www.pantone.com/>
+* Twitter: <http://twitter.com/pantone>
+* Facebook: <https://www.facebook.com/PantoneColor>
+
+[1]: http://www.pantone.com/
+[2]: https://teelaunch.com
+
51 bin/pantone
@@ -0,0 +1,51 @@
+#!/usr/bin/env node
+
+var program = require('commander')
+ , pkg = require('../package.json')
+ , version = pkg.version
+ , pantone = require('../pantone')
+ , Table = require('cli-table')
+
+function range(val) {
+ return val.split(',').map(Number)
+}
+
+program
+ .version(version)
+ .option('-rgb, --rgb <r>,<g>,<b>', 'lookup using rgb values', range)
+ .option('-hex, --hex <000000>', 'lookup using hex value')
+ .parse(process.argv)
+
+program.hex = program.hex || ''
+program.rgb = program.rgb || [ 0, 0, 0 ]
+
+var options = {
+ r : program.rgb[0] || 0
+ , g : program.rgb[1] || 0
+ , b : program.rgb[2] || 0
+ , rgb : program.hex
+}
+
+pantone(options, callback)
+
+function callback(err, results) {
+ if (err) throw err
+
+ var table = new Table({
+ head: [ 'dist', 'name', 'r', 'g', 'b', 'hex' ]
+ })
+
+ for(var i=0; i<results.length; i+=1) {
+ var row = results[i]
+ table.push([
+ row.dist
+ , row.name
+ , row.r
+ , row.g
+ , row.b
+ , row.hex
+ ])
+ }
+ console.log(table.toString())
+
+}
28 package.json
@@ -0,0 +1,28 @@
+{
+ "name": "pantone"
+ , "description": "Find the nearest PMS color using hex or rgb colors from CLI or as a dependency."
+ , "version": "0.0.1"
+ , "author": "Nick Baugh <niftylettuce@gmail.com>"
+ , "contributors": [
+ { "name": "Nick Baugh", "email": "niftylettuce@gmail.com" }
+ ]
+ , "keywords": [ "pantone", "pms", "color", "chart", "printing" ]
+ , "homepage": "https://github.com/teelaunch/pms-pantone-color-chart"
+ , "repository": {
+ "type": "git"
+ , "url": "https://github.com/teelaunch/pms-pantone-color-chart.git"
+ }
+ , "engines": {
+ "node": "0.8.x"
+ , "npm": "1.1.x"
+ }
+ , "main": "pantone"
+ , "bin": { "pantone": "./bin/pantone" }
+ , "dependencies": {
+ "request": "2.12.0"
+ , "cheerio": "0.10.5"
+ , "underscore": "1.4.3"
+ , "commander": "1.1.1"
+ , "cli-table": "0.2.0"
+ }
+}
91 pantone.js
@@ -0,0 +1,91 @@
+
+// # pantone
+
+var request = require('request')
+ , cheerio = require('cheerio')
+ , querystring = require('querystring')
+ , _ = require('underscore')
+
+// Optiman's query url
+var url = 'http://www.netfront.fr/Services/rgb2pantone/pantone.htm' // ?r=0&g=0&b=0&rgb=000000'
+
+// default options
+var defaults = {
+ r : 0
+ , g : 0
+ , b : 0
+ , rgb : ''
+}
+
+// globals to reduce callback nesting
+var options, callback
+
+// main function with callback
+function pantone(_options, _callback) {
+
+ options = _options
+ callback = _callback
+
+ // check types
+ if (typeof options !== 'object')
+ return callback(new Error('pantone - `options` is not an object'))
+
+ if (typeof callback !== 'function')
+ throw new Error('pantone - `callback` is not a function')
+
+ // if user passed defaults.hex convert it to defaults.rgb
+ if ('hex' in defaults) {
+ if (typeof defaults.hex === 'string') {
+ defaults.rgb = defaults.hex
+ }
+ delete defaults.hex
+ }
+
+ // set defaults
+ options = _.defaults(options, defaults)
+
+ // prepare querystring
+ var qs = querystring.stringify(options)
+
+ // send request
+ request(url + '?' + qs, sendRequest)
+
+}
+
+var rows = []
+
+function sendRequest(err, res, body) {
+
+ if (err) {
+ err.message = err.message + '\nPlease visit https://github.com/teelaunch/pms-pantone-color-chart/ to report issues.'
+ return callback(err)
+ }
+
+ var $ = cheerio.load(body)
+
+ if ($('#content table').length === 0)
+ return callback(new Error('pantone - color match not available for your request'))
+
+ $('#content table tr').each(parseTable);
+
+ // remove header row
+ rows = rows.slice(2, rows.length)
+
+ callback(null, rows)
+
+}
+
+function parseTable(i,tr) {
+ var $ = require('cheerio')
+ , $td = $(tr).find('td')
+ rows.push({
+ dist : $td.eq(0).text()
+ , name : $td.eq(1).text()
+ , r : parseInt($td.eq(2).text(), 10)
+ , g : parseInt($td.eq(3).text(), 10)
+ , b : parseInt($td.eq(4).text(), 10)
+ , hex : $td.eq(5).text()
+ })
+}
+
+module.exports = pantone
Please sign in to comment.
Something went wrong with that request. Please try again.