style-dictionary 3.1.0 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/examples/advanced/assets-base64-embed/package.json +1 -1
  2. package/examples/advanced/auto-rebuild-watcher/package.json +1 -1
  3. package/examples/advanced/component-cti/package.json +1 -1
  4. package/examples/advanced/create-react-app/package.json +2 -2
  5. package/examples/advanced/create-react-native-app/package.json +1 -1
  6. package/examples/advanced/custom-file-header/package.json +1 -1
  7. package/examples/advanced/custom-filters/README.md +99 -0
  8. package/examples/advanced/custom-filters/build.js +27 -0
  9. package/examples/advanced/custom-filters/config.json +21 -0
  10. package/examples/advanced/custom-filters/package.json +20 -0
  11. package/examples/advanced/custom-filters/tokens/spacing.json +20 -0
  12. package/examples/advanced/custom-formats-with-templates/package.json +1 -1
  13. package/examples/advanced/custom-parser/package.json +1 -1
  14. package/examples/advanced/custom-transforms/package.json +1 -1
  15. package/examples/advanced/font-face-rules/README.md +71 -0
  16. package/examples/advanced/font-face-rules/package.json +13 -0
  17. package/examples/advanced/font-face-rules/sd.config.js +102 -0
  18. package/examples/advanced/font-face-rules/tokens.json +28 -0
  19. package/examples/advanced/format-helpers/package.json +1 -1
  20. package/examples/advanced/matching-build-files/package.json +1 -1
  21. package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
  22. package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
  23. package/examples/advanced/npm-module/package.json +1 -1
  24. package/examples/advanced/referencing_aliasing/package.json +1 -1
  25. package/examples/advanced/s3/package.json +1 -1
  26. package/examples/advanced/tokens-deprecation/package.json +1 -1
  27. package/examples/advanced/transitive-transforms/package.json +1 -1
  28. package/examples/advanced/transitive-transforms/tokens/color/font.json5 +2 -1
  29. package/examples/advanced/variables-in-outputs/package.json +1 -1
  30. package/examples/advanced/yaml-tokens/package.json +1 -1
  31. package/examples/basic/config.json +17 -3
  32. package/examples/complete/package.json +1 -1
  33. package/index.js +2 -2
  34. package/lib/common/filters.js +30 -0
  35. package/lib/common/formatHelpers/createPropertyFormatter.js +14 -2
  36. package/lib/common/formatHelpers/formattedVariables.js +5 -1
  37. package/lib/common/formatHelpers/getTypeScriptType.js +2 -2
  38. package/lib/common/formatHelpers/index.js +2 -1
  39. package/lib/common/formatHelpers/setSwiftFileProperties.js +55 -0
  40. package/lib/common/formatHelpers/sortByReference.js +7 -0
  41. package/lib/common/formats.js +77 -10
  42. package/lib/common/templates/ios-swift/{class.swift.template → any.swift.template} +6 -3
  43. package/lib/common/transforms.js +2 -2
  44. package/lib/utils/references/getReferences.js +6 -5
  45. package/lib/utils/resolveObject.js +15 -7
  46. package/package.json +25 -24
  47. package/types/index.d.ts +3 -2
  48. package/lib/common/templates/ios-swift/enum.swift.template +0 -26
package/index.js CHANGED
@@ -43,8 +43,8 @@ var StyleDictionary = {
43
43
  format: require('./lib/common/formats'),
44
44
  action: require('./lib/common/actions'),
45
45
  formatHelpers: require('./lib/common/formatHelpers'),
46
- filter: {}, // we need to initialise the object, since we don't have built-in filters
47
- parsers: [], // ditto ^
46
+ filter: require('./lib/common/filters'),
47
+ parsers: [], // we need to initialise the array, since we don't have built-in parsers
48
48
  fileHeader: {},
49
49
 
50
50
  registerTransform: require('./lib/register/transform'),
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
13
+
14
+ /**
15
+ * @namespace Filters
16
+ */
17
+
18
+ module.exports = {
19
+ /**
20
+ * Remove a token from the ditribution output if it contains a key `private` set to true
21
+ *
22
+ * @memberof Filters
23
+ *
24
+ * @param {Object} token
25
+ * @returns {Boolean}
26
+ */
27
+ removePrivate: function(token) {
28
+ return (token && token.private) ? false : true
29
+ }
30
+ }
@@ -42,13 +42,21 @@ const defaultFormatting = {
42
42
  * ```
43
43
  * @param {Object} options
44
44
  * @param {Boolean} options.outputReferences - Whether or not to output references. You will want to pass this from the `options` object sent to the formatter function.
45
+ * @param {Boolean} options.outputReferenceFallbacks - Whether or not to output css variable fallback values when using output references. You will want to pass this from the `options` object sent to the formatter function.
45
46
  * @param {Dictionary} options.dictionary - The dictionary object sent to the formatter function
46
47
  * @param {String} options.format - Available formats are: 'css', 'sass', 'less', and 'stylus'. If you want to customize the format and can't use one of those predefined formats, use the `formatting` option
47
48
  * @param {Object} options.formatting - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: prefix, indentation, separator, suffix, and commentStyle. Those are used to generate a line like this: `${indentation}${prefix}${prop.name}${separator} ${prop.value}${suffix}`
48
49
  * @param {Boolean} options.themeable [false] - Whether tokens should default to being themeable.
49
50
  * @returns {Function}
50
51
  */
51
- function createPropertyFormatter({ outputReferences, dictionary, format, formatting = {}, themeable = false }) {
52
+ function createPropertyFormatter({
53
+ outputReferences = false,
54
+ outputReferenceFallbacks = false,
55
+ dictionary,
56
+ format,
57
+ formatting = {},
58
+ themeable = false
59
+ }) {
52
60
  let {prefix, commentStyle, indentation, separator, suffix} = Object.assign({}, defaultFormatting, formatting);
53
61
 
54
62
  switch(format) {
@@ -106,7 +114,11 @@ function createPropertyFormatter({ outputReferences, dictionary, format, formatt
106
114
  if (ref.value && ref.name) {
107
115
  value = value.replace(ref.value, function() {
108
116
  if (format === 'css') {
109
- return `var(${prefix}${ref.name})`
117
+ if (outputReferenceFallbacks) {
118
+ return `var(${prefix}${ref.name}, ${ref.value})`;
119
+ } else {
120
+ return `var(${prefix}${ref.name})`;
121
+ }
110
122
  } else {
111
123
  return `${prefix}${ref.name}`;
112
124
  }
@@ -34,7 +34,11 @@ const defaultFormatting = {
34
34
  * StyleDictionary.registerFormat({
35
35
  * name: 'myCustomFormat',
36
36
  * formatter: function({ dictionary, options }) {
37
- * return formattedVariables('less', dictionary, options.outputReferences);
37
+ * return formattedVariables({
38
+ * format: 'less',
39
+ * dictionary,
40
+ * outputReferences: options.outputReferences
41
+ * });
38
42
  * }
39
43
  * });
40
44
  * ```
@@ -30,10 +30,10 @@ const { unique } = require('../../utils/es6_');
30
30
  * }).join('\n');
31
31
  * }
32
32
  * });
33
- *
33
+ *```
34
34
  * @param {*} value A value to check the type of.
35
35
  * @return {String} A valid name for a TypeScript type.
36
- * ```
36
+ *
37
37
  */
38
38
  function getTypeScriptType(value) {
39
39
  if (Array.isArray(value)) return getArrayType(value)
@@ -23,5 +23,6 @@
23
23
  iconsWithPrefix: require('./iconsWithPrefix'),
24
24
  sortByReference: require('./sortByReference'),
25
25
  sortByName: require('./sortByName'),
26
- minifyDictionary: require('./minifyDictionary')
26
+ minifyDictionary: require('./minifyDictionary'),
27
+ setSwiftFileProperties: require('./setSwiftFileProperties')
27
28
  }
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
13
+
14
+ /**
15
+ * Outputs an object with swift format configurations. Sets import, object type and access control.
16
+ * @memberof module:formatHelpers
17
+ * @param {Object} options - The options object declared at configuration
18
+ * @param {String} objectType - The type of the object in the final file. Could be a class, enum, struct, etc.
19
+ * @param {String} transformGroup - The transformGroup of the file, so it can be applied proper import
20
+ * @returns {Object}
21
+ */
22
+ function setSwiftFileProperties(options, objectType, transformGroup) {
23
+ if (typeof options.objectType === 'undefined') {
24
+ if (typeof objectType === 'undefined') {
25
+ options.objectType = 'class';
26
+ } else {
27
+ options.objectType = objectType;
28
+ }
29
+ }
30
+
31
+ if (typeof options.import === 'undefined') {
32
+ if (typeof transformGroup === 'undefined') {
33
+ options.import = ['UIKit'];
34
+ } else if (['ios-swift', 'ios-swift-separate'].includes(transformGroup)) {
35
+ options.import = ['UIKit'];
36
+ } else {
37
+ // future swift-ui transformGroup to be added here
38
+ options.import = ['SwiftUI'];
39
+ }
40
+ } else if (typeof options.import === 'string') {
41
+ options.import = [options.import];
42
+ }
43
+
44
+ if (typeof options.accessControl === 'undefined') {
45
+ options.accessControl = 'public ';
46
+ } else {
47
+ if (options.accessControl !== "") {
48
+ options.accessControl = `${options.accessControl} `;
49
+ }
50
+ }
51
+
52
+ return options
53
+ }
54
+
55
+ module.exports = setSwiftFileProperties;
@@ -30,6 +30,13 @@
30
30
  const aComesFirst = -1;
31
31
  const bComesFirst = 1;
32
32
 
33
+ // return early if a or b ar undefined
34
+ if (typeof a === 'undefined') {
35
+ return aComesFirst;
36
+ } else if (typeof b === 'undefined') {
37
+ return bComesFirst;
38
+ }
39
+
33
40
  // If token a uses a reference and token b doesn't, b might come before a
34
41
  // read on..
35
42
  if (a.original && dictionary.usesReference(a.original.value)) {
@@ -15,7 +15,7 @@ const fs = require('fs');
15
15
  const path = require('path');
16
16
  const _template = require('lodash/template');
17
17
  const GroupMessages = require('../utils/groupMessages');
18
- const { fileHeader, formattedVariables, getTypeScriptType, iconsWithPrefix, minifyDictionary, sortByReference, createPropertyFormatter, sortByName } = require('./formatHelpers');
18
+ const { fileHeader, formattedVariables, getTypeScriptType, iconsWithPrefix, minifyDictionary, sortByReference, createPropertyFormatter, sortByName, setSwiftFileProperties } = require('./formatHelpers');
19
19
 
20
20
  const SASS_MAP_FORMAT_DEPRECATION_WARNINGS = GroupMessages.GROUP.SassMapFormatDeprecationWarnings;
21
21
 
@@ -107,7 +107,7 @@ module.exports = {
107
107
 
108
108
  // Default the "themeable" option to true for backward compatibility.
109
109
  const { outputReferences, themeable = true } = options;
110
- return '\n' +
110
+ return '\n' +
111
111
  fileHeader({ file, commentStyle: 'long' }) +
112
112
  formattedVariables({ format: 'sass', dictionary, outputReferences, themeable })
113
113
  + '\n' +
@@ -744,6 +744,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
744
744
  },
745
745
 
746
746
  // iOS templates
747
+
747
748
  /**
748
749
  * Creates an Objective-C header file with macros for design tokens
749
750
  *
@@ -902,11 +903,13 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
902
903
  },
903
904
 
904
905
  /**
905
- * Creates a Swift implementation file of a class with values
906
+ * Creates a Swift implementation file of a class with values. It adds default `class` object type, `public` access control and `UIKit` import.
906
907
  *
907
908
  * @memberof Formats
908
909
  * @kind member
909
910
  * @param {Object} options
911
+ * @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) of the generated swift object
912
+ * @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of string
910
913
  * @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date
911
914
  * @param {Boolean} [options.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output.
912
915
  * @example
@@ -916,12 +919,13 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
916
919
  * }
917
920
  * ```
918
921
  */
919
- 'ios-swift/class.swift': function({dictionary, options, file}) {
922
+ 'ios-swift/class.swift': function({dictionary, options, file, platform}) {
920
923
  const template = _template(
921
- fs.readFileSync(__dirname + '/templates/ios-swift/class.swift.template')
924
+ fs.readFileSync(__dirname + '/templates/ios-swift/any.swift.template')
922
925
  );
923
926
  let allTokens;
924
927
  const { outputReferences } = options;
928
+ options = setSwiftFileProperties(options, 'class', platform.transformGroup);
925
929
  const formatProperty = createPropertyFormatter({
926
930
  outputReferences,
927
931
  dictionary,
@@ -940,18 +944,29 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
940
944
  },
941
945
 
942
946
  /**
943
- * Creates a Swift implementation file of an enum with values
947
+ * Creates a Swift implementation file of an enum with values. It adds default `enum` object type, `public` access control and `UIKit` import.
944
948
  *
945
949
  * @memberof Formats
946
950
  * @kind member
947
- * @todo Add example and usage
951
+ * @param {Object} options
952
+ * @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) of the generated swift object
953
+ * @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of string
954
+ * @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date
955
+ * @param {Boolean} [options.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output.
956
+ * @example
957
+ * ```swift
958
+ * public enum StyleDictionary {
959
+ * public static let colorBackgroundDanger = UIColor(red: 1.000, green: 0.918, blue: 0.914, alpha: 1)
960
+ * }
961
+ * ```
948
962
  */
949
- 'ios-swift/enum.swift': function({dictionary, options, file}) {
963
+ 'ios-swift/enum.swift': function({dictionary, options, file, platform}) {
950
964
  const template = _template(
951
- fs.readFileSync(__dirname + '/templates/ios-swift/enum.swift.template')
965
+ fs.readFileSync(__dirname + '/templates/ios-swift/any.swift.template')
952
966
  );
953
967
  let allTokens;
954
968
  const { outputReferences } = options;
969
+ options = setSwiftFileProperties(options, 'enum', platform.transformGroup);
955
970
  const formatProperty = createPropertyFormatter({
956
971
  outputReferences,
957
972
  dictionary,
@@ -963,10 +978,62 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
963
978
  if (outputReferences) {
964
979
  allTokens = [...dictionary.allTokens].sort(sortByReference(dictionary));
965
980
  } else {
966
- allTokens = [...dictionary.allTokens].sort(sortByName)
981
+ allTokens = [...dictionary.allTokens].sort(sortByName);
967
982
  }
968
983
  return template({allTokens, file, options, formatProperty, fileHeader});
969
984
  },
985
+
986
+ /**
987
+ * Creates a Swift implementation file of any given type with values. It has by default `class` object type, `public` access control and `UIKit` import.
988
+ *
989
+ * ```javascript
990
+ * format: 'ios-swift/any.swift',
991
+ * import: ['UIKit', 'AnotherModule'],
992
+ * objectType: 'struct',
993
+ * accessControl: 'internal',
994
+ * ```
995
+ *
996
+ * @memberof Formats
997
+ * @kind member
998
+ * @param {Object} options
999
+ * @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) of the generated swift object
1000
+ * @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of strings
1001
+ * @param {String} [options.objectType=class] - The type of the generated Swift object
1002
+ * @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date
1003
+ * @param {Boolean} [options.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output.
1004
+ * @example
1005
+ * ```swift
1006
+ * import UIKit
1007
+ * import AnotherModule
1008
+ *
1009
+ * internal struct StyleDictionary {
1010
+ * internal static let colorBackgroundDanger = UIColor(red: 1.000, green: 0.918, blue: 0.914, alpha: 1)
1011
+ * }
1012
+ * ```
1013
+ */
1014
+ 'ios-swift/any.swift': function({ dictionary, options, file, platform }) {
1015
+ const template = _template(
1016
+ fs.readFileSync(__dirname + '/templates/ios-swift/any.swift.template')
1017
+ );
1018
+ let allTokens;
1019
+ const { outputReferences } = options;
1020
+ options = setSwiftFileProperties(options, options.objectType, platform.transformGroup);
1021
+ const formatProperty = createPropertyFormatter({
1022
+ outputReferences,
1023
+ dictionary,
1024
+ formatting: {
1025
+ suffix: ''
1026
+ }
1027
+ });
1028
+
1029
+ if (outputReferences) {
1030
+ allTokens = [...dictionary.allTokens].sort(sortByReference(dictionary));
1031
+ } else {
1032
+ allTokens = [...dictionary.allTokens].sort(sortByName);
1033
+ }
1034
+ return template({allTokens, file, options, formatProperty, fileHeader});
1035
+ },
1036
+
970
1037
  // Css templates
971
1038
 
972
1039
  /**
@@ -17,10 +17,13 @@
17
17
  // <%= file.destination %>
18
18
  //
19
19
  <%= fileHeader({file, commentStyle: 'short'}) %>
20
- import UIKit
20
+ <%= options.import.map(function(item) {
21
+ return 'import ' + item
22
+ }).join('\n')
23
+ %>
21
24
 
22
- public class <%= file.className %> {
25
+ <%= options.accessControl %><%= options.objectType %> <%= file.className %> {
23
26
  <%= allTokens.map(function(prop) {
24
- return 'public static let ' + formatProperty(prop);
27
+ return options.accessControl + 'static let ' + formatProperty(prop);
25
28
  }).join('\n ') %>
26
29
  }
@@ -629,7 +629,7 @@ module.exports = {
629
629
  },
630
630
 
631
631
  /**
632
- * Transforms the value from a REM size on web into a scale-independent pixel (sp) value for font sizes on Android. It WILL scale the number by a factor of 16 (common base font size on web).
632
+ * Transforms the value from a REM size on web into a scale-independent pixel (sp) value for font sizes on Android. It WILL scale the number by a factor of 16 (or the value of 'basePxFontSize' on the platform in your config).
633
633
  *
634
634
  * ```js
635
635
  * // Matches: token.attributes.category === 'size' && token.attributes.type === 'font'
@@ -739,7 +739,7 @@ module.exports = {
739
739
  },
740
740
 
741
741
  /**
742
- * 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 (common base font size on web).
742
+ * 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).
743
743
  *
744
744
  * ```kotlin
745
745
  * // Matches: prop.attributes.category === 'size' && prop.attributes.type === 'font'
@@ -28,16 +28,13 @@ const GroupMessages = require('../groupMessages');
28
28
  *
29
29
  * @memberof Dictionary
30
30
  * @param {string} value the value that contains a reference
31
+ * @param {object[]} references array of token's references because a token's value can contain multiple references due to string interpolation
31
32
  * @returns {any}
32
33
  */
33
- function getReferences(value) {
34
+ function getReferences(value, references=[]) {
34
35
  // `this` is the dictionary object passed to formats and actions
35
36
  const self = this;
36
37
  const regex = createReferenceRegex({});
37
- // because a token's value can contain multiple references due to string interpolation
38
- // "{size.padding.base.value} {color.border.primary.value}"
39
- // references is an array of 0 or more references
40
- const references = [];
41
38
 
42
39
  // this will update the references array with the referenced tokens it finds.
43
40
  function findReference(match, variable) {
@@ -70,6 +67,10 @@ function getReferences(value) {
70
67
  if (value.hasOwnProperty(key) && typeof value[key] === 'string') {
71
68
  value[key].replace(regex, findReference);
72
69
  }
70
+ // if it is an object, we go further down the rabbit hole
71
+ if (value.hasOwnProperty(key) && typeof value[key] === 'object') {
72
+ self.getReferences(value[key], references);
73
+ }
73
74
  }
74
75
  }
75
76
 
@@ -85,16 +85,20 @@ function compile_value(value, stack) {
85
85
  // references can be part of the value such as "1px solid {color.border.light}"
86
86
  value.replace(regex, function(match, variable) {
87
87
  variable = variable.trim();
88
- if (options.ignorePaths.indexOf(variable) !== -1) {
89
- return value;
90
- }
91
-
92
- stack.push(variable);
93
88
 
94
89
  // Find what the value is referencing
95
90
  const pathName = getPath(variable, options);
96
91
  const context = getName(current_context, options);
97
92
  const refHasValue = pathName[pathName.length-1] === 'value';
93
+
94
+ if (refHasValue && options.ignorePaths.indexOf(variable) !== -1) {
95
+ return value;
96
+ } else if (!refHasValue && options.ignorePaths.indexOf(`${variable}.value`) !== -1) {
97
+ return value;
98
+ }
99
+
100
+ stack.push(variable);
101
+
98
102
  ref = resolveReference(pathName, updated_object);
99
103
 
100
104
  // If the reference doesn't end in 'value'
@@ -108,7 +112,7 @@ function compile_value(value, stack) {
108
112
  }
109
113
 
110
114
  if (typeof ref !== 'undefined') {
111
- if (typeof ref === 'string') {
115
+ if (typeof ref === 'string' || typeof ref === 'number') {
112
116
  to_ret = value.replace(match, ref);
113
117
 
114
118
  // Recursive, therefore we can compute multi-layer variables like a = b, b = c, eventually a = c
@@ -145,8 +149,12 @@ function compile_value(value, stack) {
145
149
  to_ret = compile_value( to_ret, stack );
146
150
  }
147
151
  }
152
+ // if evaluated value is a number and equal to the reference, we want to keep the type
153
+ if (typeof ref === 'number' && ref.toString() === to_ret) {
154
+ to_ret = ref;
155
+ }
148
156
  } else {
149
- // if evaluated value is not a string, we want to keep the type
157
+ // if evaluated value is not a string or number, we want to keep the type
150
158
  to_ret = ref;
151
159
  }
152
160
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "style-dictionary",
3
- "version": "3.1.0",
3
+ "version": "3.7.1",
4
4
  "description": "Style once, use everywhere. A build system for creating cross-platform styles.",
5
5
  "keywords": [
6
6
  "style dictionary",
@@ -44,7 +44,8 @@
44
44
  "generate-docs": "node ./scripts/generateDocs.js",
45
45
  "serve-docs": "docsify serve docs -p 3000 -P 12345",
46
46
  "install-cli": "npm install -g $(npm pack)",
47
- "release": "git add . && standard-version -a"
47
+ "release": "git add . && standard-version -a",
48
+ "prepare": "husky install"
48
49
  },
49
50
  "standard-version": {
50
51
  "scripts": {
@@ -119,36 +120,36 @@
119
120
  "dependencies": {
120
121
  "chalk": "^4.0.0",
121
122
  "change-case": "^4.1.2",
122
- "commander": "^5.1.0",
123
- "fs-extra": "^8.1.0",
124
- "glob": "^7.1.6",
125
- "json5": "^2.1.3",
123
+ "commander": "^8.3.0",
124
+ "fs-extra": "^10.0.0",
125
+ "glob": "^7.2.0",
126
+ "json5": "^2.2.0",
127
+ "jsonc-parser": "^3.0.0",
126
128
  "lodash": "^4.17.15",
127
129
  "tinycolor2": "^1.4.1"
128
130
  },
129
131
  "devDependencies": {
130
- "@babel/preset-env": "^7.10.2",
131
- "@commitlint/cli": "^11.0.0",
132
- "@commitlint/config-conventional": "^11.0.0",
133
- "babel-jest": "^26.0.1",
132
+ "@babel/preset-env": "^7.16.11",
133
+ "@commitlint/cli": "^16.1.0",
134
+ "@commitlint/config-conventional": "^16.0.0",
135
+ "babel-jest": "^27.4.6",
134
136
  "babel-preset-env": "^1.7.0",
135
- "docsify": "^4.12.1",
137
+ "docsify": "^4.12.2",
136
138
  "docsify-cli": "^4.4.3",
137
- "eslint": "^6.8.0",
138
- "eslint-plugin-jest": "^24.1.3",
139
- "husky": "^4.2.5",
139
+ "eslint": "^8.7.0",
140
+ "eslint-plugin-jest": "^26.0.0",
141
+ "husky": "^7.0.0",
140
142
  "istanbul": "^0.4.5",
141
- "jest": "^26.6.3",
143
+ "jest": "^27.4.7",
142
144
  "jsdoc-escape-at": "^1.0.1",
143
- "jsdoc-to-markdown": "^7.0.1",
145
+ "jsdoc-to-markdown": "^7.1.0",
144
146
  "json5-jest": "^1.0.1",
145
- "jsonc-parser": "^3.0.0",
146
- "less": "^3.11.2",
147
- "lint-staged": "^10.2.7",
148
- "node-sass": "^6.0.1",
149
- "standard-version": "^9.0.0",
150
- "stylus": "^0.54.8",
151
- "tsd": "^0.15.1",
152
- "yaml": "^1.10.0"
147
+ "less": "^4.1.2",
148
+ "lint-staged": "^12.3.1",
149
+ "node-sass": "^7.0.1",
150
+ "standard-version": "^9.3.2",
151
+ "stylus": "^0.56.0",
152
+ "tsd": "^0.19.1",
153
+ "yaml": "^1.10.2"
153
154
  }
154
155
  }
package/types/index.d.ts CHANGED
@@ -20,7 +20,7 @@ import {Dictionary as _Dictionary} from './Dictionary';
20
20
  import {File as _File} from './File';
21
21
  import {FileHeader as _FileHeader} from './FileHeader';
22
22
  import {Filter as _Filter} from './Filter';
23
- import {Format as _Format} from './Format';
23
+ import {Format as _Format, Formatter as _Formatter } from './Format';
24
24
  import {FormatHelpers as _FormatHelpers} from './FormatHelpers';
25
25
  import {Options as _Options} from './Options';
26
26
  import {Parser as _Parser} from './Parser';
@@ -44,6 +44,7 @@ declare namespace StyleDictionary {
44
44
  type Filter = _Filter;
45
45
  type Format = _Format;
46
46
  type FormatHelpers = _FormatHelpers;
47
+ type Formatter = _Formatter;
47
48
  type Options = _Options;
48
49
  type Parser = _Parser;
49
50
  type Platform = _Platform;
@@ -63,7 +64,7 @@ declare namespace StyleDictionary {
63
64
 
64
65
  transform: Record<string, Transform>;
65
66
  transformGroup: Record<string, TransformGroup['transforms']>;
66
- format: Record<string, Format>;
67
+ format: Record<string, Formatter>;
67
68
  action: Record<string, Action>;
68
69
  filter: Record<string, Filter>;
69
70
  fileHeader: Record<string, FileHeader>;
@@ -1,26 +0,0 @@
1
- <%
2
- //
3
- // Copyright 2019 Alaska Air Group or its affiliates. All Rights Reserved.
4
- //
5
- // Licensed under the Apache License, Version 2.0 (the "License").
6
- // You may not use this file except in compliance with the License.
7
- // A copy of the License is located at
8
- //
9
- // http://www.apache.org/licenses/LICENSE-2.0
10
- //
11
- // or in the "license" file accompanying this file. This file is distributed
12
- // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13
- // express or implied. See the License for the specific language governing
14
- // permissions and limitations under the License.
15
- %>
16
- //
17
- // <%= file.destination %>
18
- //
19
- <%= fileHeader({file, commentStyle: 'short'}) %>
20
- import UIKit
21
-
22
- public enum <%= file.className %> {
23
- <%= allTokens.map(function(prop) {
24
- return 'public static let ' + formatProperty(prop);
25
- }).join('\n ') %>
26
- }