Skip to content

Instantly share code, notes, and snippets.

@james-nash
Last active December 23, 2022 07:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save james-nash/39bd715d57a31c3de4cb96b58ca0d627 to your computer and use it in GitHub Desktop.
Save james-nash/39bd715d57a31c3de4cb96b58ca0d627 to your computer and use it in GitHub Desktop.
Generates EightShapes Contrast Grid or Christopher Geary's "Contrast" tool URLs from InVision DSM or Brand.ai design tokens.
/*
Generates EightShapes Contrast Grid or Christopher Geary's "Contrast" tool
URLs from InVision DSM or Brand.ai.
Usage for Contrast Grid URL:
node contrast-grid-url.js [URL]
Usage for Contrast URL:
node contrast-grid-url.js [URL] --crgeary
[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-2020 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');
function generateEightShapesUrl(colors) {
let colorText = '';
for(let j=0; j<colors.length; ++j){
colorText += colors[j].value + ', ';
colorText += colors[j].name + "\n";
}
return 'http://contrast-grid.eightshapes.com/?background-colors=&foreground-colors=' +
encodeURIComponent(colorText) +
'&es-color-form__tile-size=compact'
}
function generateCrGearyContrastUrl(colors) {
let colorText = '';
for(let i=0; i<colors.length; ++i){
colorText += colors[i].value.substr(1) + (i < (colors.length - 1) ? ',' : '');
}
return 'https://contrast.crgeary.com/#' + colorText;
}
let outputDsmLink = true;
if (process.argv[3] === '--crgeary') {
outputDsmLink = false;
}
https.get(
process.argv[2], // Should be the URL to the InVision DSM / Brand.ai JSON styles
(res) => {
let body = '';
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
let data = JSON.parse(body);
let colorPalettes = data.list.colors;
let colors = [];
for(let i=0; i<colorPalettes.length; ++i) {
colors = colors.concat(colorPalettes[i].colors);
}
process.stdout.write(`${outputDsmLink ? generateEightShapesUrl(colors) : generateCrGearyContrastUrl(colors)}\n`);
});
}).on('error', (e) => {
console.error(e);
}
);
@alexa1829
Copy link

Best AI Content Write and AI Images Generator from Text Prompts: https://writerzingo.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment