-
-
Save paulmsmith/5f726e0108d460f809426ce20ce15e28 to your computer and use it in GitHub Desktop.
Generate EightShapes Contrast Grid URL from Brand.ai styles
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
/* | |
Generate EightShapes Contrast Grid URL from Brand.ai styles | |
Usage: | |
node contrast-grid-url.js [URL] | |
[URL] should be the URL to your Brand.ai JSON styles data export. Note that | |
you may need to wrap the URL in quotes. | |
---------------------------------------------------------------------------- | |
Copyright 2017 James Nash | |
Permission is hereby granted, free of charge, to any person obtaining a | |
copy of this software and associated documentation files (the "Software"), | |
to deal in the Software without restriction, including without limitation | |
the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
and/or sell copies of the Software, and to permit persons to whom the | |
Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
IN THE SOFTWARE. | |
---------------------------------------------------------------------------- | |
*/ | |
'use strict'; | |
const https = require('https'); | |
https.get( | |
process.argv[2], // Should be the URL to the Brand.ai JSON styles | |
(res) => { | |
let body = ''; | |
res.on('data', (chunk) => { | |
body += chunk; | |
}); | |
res.on('end', () => { | |
let data = JSON.parse(body); | |
let colorText = ''; | |
let colors = data.list.colors; | |
let paletteColors; | |
for(let i=0; i<colors.length; ++i){ | |
paletteColors = colors[i].colors; | |
for(let j=0; j<paletteColors.length; ++j){ | |
colorText += paletteColors[j].value + ', '; | |
colorText += paletteColors[j].name + "\n"; | |
} | |
} | |
process.stdout.write( | |
'http://contrast-grid.eightshapes.com/?background-colors=&foreground-colors=' + | |
encodeURIComponent(colorText) + | |
'&es-color-form__tile-size=compact' + | |
"\n" | |
); | |
}); | |
}).on('error', (e) => { | |
console.error(e); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment