Last active
October 1, 2018 09:31
-
-
Save glenndevenish/1ad6013a8c07beba22720d1902589b70 to your computer and use it in GitHub Desktop.
Gets RGB, HEX, and CMYK values from a Pantone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
How to use: | |
Go to pantone.com | |
open console | |
paste the below function | |
Run with getPantoneData('123 c').then(...) | |
It returns an object with the format: | |
{ | |
pantone: '123-C', | |
rgb: [255, 199, 44], | |
hex: 'FFC72C', | |
cmyk: [0, 19, 98, 0] | |
} | |
*/ | |
function getPantoneData(pantone) { // pantone in format '123-C', '124 cp', etc | |
const colourString = pantone.trim().replace(/ /g, '-').toLocaleUpperCase() // format string to url end | |
return fetch('https://www.pantone.com/color-finder/' + colourString) | |
.then(r=>r.text()) | |
.then(data => { | |
stripped = data.replace(/\s*/g, '') | |
regex = /spanclass="values">([A-Z0-9]{6}|\d+)/g // Regex to find hex/numbers from the html string | |
arr = [] | |
while(match = regex.exec(stripped)) { // = assigns, rather than == (catches nulls) | |
arr.push(match[1]) | |
} | |
return { | |
pantone: colourString.replace('-', ' '), | |
rgb: [arr[0], arr[1], arr[2]], | |
hex: arr[3], | |
cmyk: [arr[4], arr[5], arr[6], arr[7]] | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basic usage:
Get hex values from array of pantones: