Skip to content

Instantly share code, notes, and snippets.

@dbanksdesign
Created May 31, 2019 05:27
Show Gist options
  • Save dbanksdesign/08607f7a39ce150a2c4634fe7b0ae7e2 to your computer and use it in GitHub Desktop.
Save dbanksdesign/08607f7a39ce150a2c4634fe7b0ae7e2 to your computer and use it in GitHub Desktop.
Style Dictionary Reverse Lookup Format
module.exports = function(dictionary, platform) {
// This will store the references
const toRet = {};
dictionary.allProperties.forEach((token) => {
let original = token.original.value;
// If the token has a reference, store it
if (typeof original === 'string' && original.indexOf('{') > -1) {
let reference = original.replace(/{|}/g,'');
// Add an array to the lookup object if it is not there
toRet[reference] = toRet[reference] || [];
// Add the token's path to the reference array
toRet[reference].push(token.path.join('.'))
}
});
// Output a simple JSON string
return JSON.stringify(toRet, null, 2);
}
// File will look like this:
/*
{
"color.base.white.value": [
"color.background.base",
"color.font.inverse.base"
],
"color.base.blue_grey.100.value": [
"color.background.alt",
"color.background.disabled"
],
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment