Skip to content

Commit

Permalink
feat(json-nested): Add JSON nested transform
Browse files Browse the repository at this point in the history
Added JSON nested transform, Added test for it and Documentation update

re amzn#139
  • Loading branch information
davixyz committed Oct 19, 2018
1 parent 15c876d commit b24a6aa
Show file tree
Hide file tree
Showing 4 changed files with 2,028 additions and 2,092 deletions.
18 changes: 18 additions & 0 deletions docs/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ Creates a JSON file of just the assets defined in the style dictionary.

* * *

### json/nested


Creates a JSON that contains the original structure of the object without the value property.

**Example**
```json
{
"color": {
"base": {
"red": "#ff000"
}
}
}
```

* * *

### sketch/palette


Expand Down
35 changes: 35 additions & 0 deletions lib/common/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ function iconsWithPrefix(prefix, properties, config) {
})
.value().join('\n');
}

function minifyDictionary(obj) {
var toRet = {};
if (obj.hasOwnProperty('value')) {
return obj.value;
} else {
for(var name in obj) {
if(obj.hasOwnProperty(name)) {
toRet[name] = minifyDictionary(obj[name]);
}
}
}
return toRet;
}
/**
* @namespace Formats
*/
Expand Down Expand Up @@ -323,6 +337,27 @@ module.exports = {
return JSON.stringify({asset: dictionary.properties.asset}, null, 2);
},

/**
* Creates a JSON nested file of the style dictionary.
*
* @memberof Formats
* @kind member
* @example
* ```json
* {
* "color": {
* "base": {
* "red": "#ff000"
* }
* }
* }
* ```
*/
'json/nested': function(dictionary) {
return JSON.stringify(minifyDictionary(dictionary.properties), null, 2);
},


/**
* Creates a sketchpalette file of all the base colors
*
Expand Down
Loading

0 comments on commit b24a6aa

Please sign in to comment.