Skip to content

Commit

Permalink
chore(transforms): consistent usage of 'token' instead of 'prop' (amz…
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-deramond authored Mar 16, 2023
1 parent e7800b9 commit e5ce325
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ const StyleDictionary = require('style-dictionary').extend('config.json');
StyleDictionary.registerTransform({
name: 'time/seconds',
type: 'value',
matcher: function(prop) {
return prop.attributes.category === 'time';
matcher: function(token) {
return token.attributes.category === 'time';
},
transformer: function(prop) {
return (parseInt(prop.original.value) / 1000).toString() + 's';
transformer: function(token) {
return (parseInt(token.original.value) / 1000).toString() + 's';
}
});

Expand Down
12 changes: 6 additions & 6 deletions docs/extending.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const StyleDictionary = require('style-dictionary').extend('config.json');
StyleDictionary.registerTransform({
name: 'time/seconds',
type: 'value',
matcher: function(prop) {
return prop.attributes.category === 'time';
matcher: function(token) {
return token.attributes.category === 'time';
},
transformer: function(prop) {
return (parseInt(prop.original.value) / 1000).toString() + 's';
transformer: function(token) {
return (parseInt(token.original.value) / 1000).toString() + 's';
}
});

Expand All @@ -40,8 +40,8 @@ const StyleDictionary = require('style-dictionary').extend('config.json');
StyleDictionary.registerTransform({
name: 'name/uppercase',
type: 'name',
transformer: function(prop) {
return prop.path.join('_').toUpperCase();
transformer: function(token) {
return token.path.join('_').toUpperCase();
}
});

Expand Down
30 changes: 15 additions & 15 deletions lib/common/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ module.exports = {
* Transforms the value into a Color class for Compose
*
* ```kotlin
* // Matches: prop.attributes.category === 'color'
* // Matches: token.attributes.category === 'color'
* // Returns:
* Color(0xFF009688)
* ```
Expand All @@ -422,8 +422,8 @@ module.exports = {
'color/composeColor': {
type: 'value',
matcher: isColor,
transformer: function (prop) {
var str = Color(prop.value).toHex8();
transformer: function (token) {
var str = Color(token.value).toHex8();
return 'Color(0x' + str.slice(6) + str.slice(0,6) + ')'
}
},
Expand Down Expand Up @@ -742,7 +742,7 @@ module.exports = {
* Transforms the value from a REM size on web into a scale-independent pixel (sp) value for font sizes in Compose. It WILL scale the number by a factor of 16 (or the value of 'basePxFontSize' on the platform in your config).
*
* ```kotlin
* // Matches: prop.attributes.category === 'size' && prop.attributes.type === 'font'
* // Matches: token.attributes.category === 'size' && token.attributes.type === 'font'
* // Returns:
* "16.0.sp"
* ```
Expand All @@ -752,10 +752,10 @@ module.exports = {
'size/compose/remToSp': {
type: 'value',
matcher: isFontSize,
transformer: function(prop, options) {
const val = parseFloat(prop.value);
transformer: function(token, options) {
const val = parseFloat(token.value);
const baseFont = getBasePxFontSize(options);
if (isNaN(val)) throwSizeError(prop.name, prop.value, 'sp');
if (isNaN(val)) throwSizeError(token.name, token.value, 'sp');
return (val * baseFont).toFixed(2) + '.sp';
}
},
Expand All @@ -765,7 +765,7 @@ module.exports = {
* Transforms the value from a REM size on web into a density-independent pixel (dp) value for font sizes in Compose. It WILL scale the number by a factor of 16 (or the value of 'basePxFontSize' on the platform in your config).
*
* ```kotlin
* // Matches: prop.attributes.category === 'size' && prop.attributes.type !== 'font'
* // Matches: token.attributes.category === 'size' && token.attributes.type !== 'font'
* // Returns:
* "16.0.dp"
* ```
Expand All @@ -775,10 +775,10 @@ module.exports = {
'size/compose/remToDp': {
type: 'value',
matcher: isNotFontSize,
transformer: function(prop, options) {
const val = parseFloat(prop.value);
transformer: function(token, options) {
const val = parseFloat(token.value);
const baseFont = getBasePxFontSize(options);
if (isNaN(val)) throwSizeError(prop.name, prop.value, 'dp');
if (isNaN(val)) throwSizeError(token.name, token.value, 'dp');
return (val * baseFont).toFixed(2) + '.dp';
}
},
Expand All @@ -787,7 +787,7 @@ module.exports = {
* Adds the .em Compose extension to the end of a number. Does not scale the value
*
* ```kotlin
* // Matches: prop.attributes.category === 'size' && prop.attributes.type === 'font'
* // Matches: token.attributes.category === 'size' && token.attributes.type === 'font'
* // Returns:
* "16.0em"
* ```
Expand All @@ -797,9 +797,9 @@ module.exports = {
'size/compose/em': {
type: 'value',
matcher: isFontSize,
transformer: function(prop) {
const val = parseFloat(prop.value);
if (isNaN(val)) throwSizeError(prop.name, prop.value, 'em');
transformer: function(token) {
const val = parseFloat(token.value);
if (isNaN(val)) throwSizeError(token.name, token.value, 'em');
return val + '.em';
}
},
Expand Down

0 comments on commit e5ce325

Please sign in to comment.