Skip to content

Instantly share code, notes, and snippets.

@olehmelnyk
Created December 30, 2017 17:47
Show Gist options
  • Save olehmelnyk/0aff52f300ef6f778b3a9ab03b5f7bfd to your computer and use it in GitHub Desktop.
Save olehmelnyk/0aff52f300ef6f778b3a9ab03b5f7bfd to your computer and use it in GitHub Desktop.
Parsing 3rd party website for RGB to Pantone
/**
* Parsing 3rd party website
* not sure how accurate/valid/outdated it is
* and this resource might be closed any time
* but https://github.com/teelaunch/pms-pantone-color-chart
* uses this site here https://github.com/teelaunch/pms-pantone-color-chart/blob/master/pantone.js#L9
* */
async function rgbToPantone(RGB){
return fetch(`http://www.netfront.fr/Services/rgb2pantone/pantone.htm?r=${RGB[0]}&g=${RGB[1]}&b=${RGB[2]}`)
.then(resolve => resolve.text())
.then(html => new DOMParser().parseFromString(html, 'text/html'))
.then(doc => {
let pantone = [];
doc.querySelectorAll('tbody > tr:nth-child(n+3)').forEach( row => {
let data = row.querySelectorAll('td');
pantone.push({
dist: parseFloat(data[0].textContent),
code: data[1].textContent,
hex: data[5].textContent
});
});
return pantone;
})
}
console.log(await rgbToPantone([0,0,0]));
console.log(await rgbToPantone([255,255,255]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment