Created
May 31, 2019 05:27
-
-
Save dbanksdesign/08607f7a39ce150a2c4634fe7b0ae7e2 to your computer and use it in GitHub Desktop.
Style Dictionary Reverse Lookup Format
This file contains hidden or 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
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