feat(json/original): Add json/original format
Issue #727
Description of changes:
-
The json/original format allows you to leave only those keys that were specified in the original object without additional metadata. More info #727.
-
Added dictionary filtered function: In:
- obj - The object to filter. You will most likely pass
dictionary.tokens.colorto it. - exclude - The keys that need to be excluded from the filtered object
- target - The keys that must be included in the result object.
Out: the object which contains only given keys.
- obj - The object to filter. You will most likely pass
Tested with the Figma Tokens plugin.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Hi @theKosh , thanks for your contribution!
This is a good idea, but needs some changes.
I'll add all of the comments below as a review, but I wanted to try to capture all the thinking in one spot:
- Adding a function to filter token metadata is a great idea that may have utility for a wide variety of SD users. Can we get another function that does the same exact thing but uses an "include" list instead of an "exclude" list?
- Adding a format for this is.... confusing. Formats are intended to be for platform style usage elsewhere. I'm unclear how this would be widely beneficial - or rather, how this would be useful to many/most StyleDictionary users
- There are a couple things that need to be cleaned, like changing the version number / package.lock
Thanks again for your contribution! Looking forward to adding in this functionality.
Hi @chazzmoney.
Can we get another function that does the same exact thing but uses an "include" list instead of an "exclude" list?
Yes, okay, I'll do it.
Adding a format for this is.... confusing. Formats are intended to be for platform style usage elsewhere. I'm unclear how this would be widely beneficial - or rather, how this would be useful to many/most StyleDictionary users
For example:
- When you need to change tokens via transform, but you need to leave the json format as the original one, since you don't need extra metadata. In my case, for the web, I applied the rule
"transforms['color/css2']". - When tokens are generated for many platforms, but no changes are required for one of them, at the same time, it is more convenient for developers to have everything in one place in the build folder along with the processed assets. In this case, we can do it through the
fs.copyfilesyncfunction, but doing it through the format is more flexible, since it allows you to use transforms, manage assets, etc.
There is a discussion of the problem in this topic.
There are a couple things that need to be cleaned, like changing the version number / package.lock
I'll fix it.
Thanks for the detailed code review. I'll try to do everything in my spare time.
Hi, @chazzmoney.
I fixed all the errors and added the excludeTokensMetadata method as you asked.
Sorry it took so long — I got tied up at work.