style-dictionary 4.0.0-prerelease.13 → 4.0.0-prerelease.15

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 (132) 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 +1 -1
  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/package.json +1 -1
  8. package/examples/advanced/custom-formats-with-templates/package.json +1 -1
  9. package/examples/advanced/custom-parser/package.json +1 -1
  10. package/examples/advanced/custom-transforms/package.json +1 -1
  11. package/examples/advanced/font-face-rules/package.json +1 -1
  12. package/examples/advanced/format-helpers/package.json +1 -1
  13. package/examples/advanced/matching-build-files/package.json +1 -1
  14. package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
  15. package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
  16. package/examples/advanced/npm-module/package.json +1 -1
  17. package/examples/advanced/referencing_aliasing/package.json +1 -1
  18. package/examples/advanced/s3/package.json +1 -1
  19. package/examples/advanced/tokens-deprecation/package.json +1 -1
  20. package/examples/advanced/transitive-transforms/package.json +1 -1
  21. package/examples/advanced/variables-in-outputs/package.json +1 -1
  22. package/examples/advanced/yaml-tokens/package.json +1 -1
  23. package/lib/StyleDictionary.js +47 -13
  24. package/lib/buildFile.d.ts +4 -1
  25. package/lib/buildFile.js +15 -12
  26. package/lib/buildFiles.d.ts +7 -4
  27. package/lib/buildFiles.js +16 -10
  28. package/lib/cleanActions.d.ts +7 -4
  29. package/lib/cleanActions.js +12 -9
  30. package/lib/cleanDir.d.ts +1 -1
  31. package/lib/cleanDir.js +4 -3
  32. package/lib/cleanDirs.d.ts +1 -1
  33. package/lib/cleanDirs.js +12 -9
  34. package/lib/cleanFile.d.ts +1 -1
  35. package/lib/cleanFile.js +1 -1
  36. package/lib/cleanFiles.d.ts +1 -1
  37. package/lib/cleanFiles.js +12 -9
  38. package/lib/common/actions.js +28 -23
  39. package/lib/common/formatHelpers/createPropertyFormatter.d.ts +3 -1
  40. package/lib/common/formatHelpers/createPropertyFormatter.js +7 -8
  41. package/lib/common/formatHelpers/fileHeader.d.ts +2 -2
  42. package/lib/common/formatHelpers/fileHeader.js +5 -3
  43. package/lib/common/formatHelpers/formattedVariables.d.ts +3 -1
  44. package/lib/common/formatHelpers/formattedVariables.js +3 -0
  45. package/lib/common/formatHelpers/getTypeScriptType.d.ts +4 -2
  46. package/lib/common/formatHelpers/getTypeScriptType.js +3 -2
  47. package/lib/common/formatHelpers/iconsWithPrefix.d.ts +4 -1
  48. package/lib/common/formatHelpers/iconsWithPrefix.js +6 -3
  49. package/lib/common/formatHelpers/minifyDictionary.d.ts +2 -1
  50. package/lib/common/formatHelpers/minifyDictionary.js +5 -4
  51. package/lib/common/formatHelpers/sortByReference.js +3 -3
  52. package/lib/common/formats.js +147 -130
  53. package/lib/common/templates/android/colors.template.d.ts +1 -1
  54. package/lib/common/templates/android/colors.template.js +2 -2
  55. package/lib/common/templates/android/dimens.template.d.ts +1 -1
  56. package/lib/common/templates/android/dimens.template.js +2 -2
  57. package/lib/common/templates/android/fontDimens.template.d.ts +1 -1
  58. package/lib/common/templates/android/fontDimens.template.js +2 -2
  59. package/lib/common/templates/android/integers.template.d.ts +1 -1
  60. package/lib/common/templates/android/integers.template.js +2 -2
  61. package/lib/common/templates/android/resources.template.d.ts +3 -1
  62. package/lib/common/templates/android/resources.template.js +6 -4
  63. package/lib/common/templates/android/strings.template.d.ts +1 -1
  64. package/lib/common/templates/android/strings.template.js +2 -2
  65. package/lib/common/templates/compose/object.kt.template.d.ts +1 -1
  66. package/lib/common/templates/compose/object.kt.template.js +1 -1
  67. package/lib/common/templates/flutter/class.dart.template.d.ts +1 -1
  68. package/lib/common/templates/flutter/class.dart.template.js +1 -1
  69. package/lib/common/templates/ios/colors.h.template.d.ts +1 -1
  70. package/lib/common/templates/ios/colors.h.template.js +1 -1
  71. package/lib/common/templates/ios/colors.m.template.d.ts +1 -1
  72. package/lib/common/templates/ios/colors.m.template.js +2 -2
  73. package/lib/common/templates/ios/macros.template.d.ts +1 -1
  74. package/lib/common/templates/ios/macros.template.js +2 -2
  75. package/lib/common/templates/ios/plist.template.d.ts +1 -1
  76. package/lib/common/templates/ios/plist.template.js +6 -6
  77. package/lib/common/templates/ios/singleton.h.template.d.ts +1 -1
  78. package/lib/common/templates/ios/singleton.h.template.js +1 -1
  79. package/lib/common/templates/ios/singleton.m.template.d.ts +1 -1
  80. package/lib/common/templates/ios/singleton.m.template.js +3 -3
  81. package/lib/common/templates/ios/static.h.template.d.ts +1 -1
  82. package/lib/common/templates/ios/static.h.template.js +1 -1
  83. package/lib/common/templates/ios/static.m.template.d.ts +1 -1
  84. package/lib/common/templates/ios/static.m.template.js +2 -2
  85. package/lib/common/templates/ios/strings.h.template.d.ts +1 -1
  86. package/lib/common/templates/ios/strings.h.template.js +1 -1
  87. package/lib/common/templates/ios/strings.m.template.d.ts +1 -1
  88. package/lib/common/templates/ios/strings.m.template.js +3 -3
  89. package/lib/common/templates/ios-swift/any.swift.template.d.ts +1 -1
  90. package/lib/common/templates/ios-swift/any.swift.template.js +1 -1
  91. package/lib/common/templates/scss/map-deep.template.d.ts +1 -1
  92. package/lib/common/templates/scss/map-deep.template.js +1 -1
  93. package/lib/common/templates/scss/map-flat.template.d.ts +1 -1
  94. package/lib/common/templates/scss/map-flat.template.js +2 -2
  95. package/lib/common/templates/static-style-guide/index.html.template.d.ts +1 -1
  96. package/lib/common/templates/static-style-guide/index.html.template.js +2 -2
  97. package/lib/common/transforms.d.ts +2 -1
  98. package/lib/common/transforms.js +125 -119
  99. package/lib/filterTokens.d.ts +4 -2
  100. package/lib/filterTokens.js +29 -10
  101. package/lib/fs.js +1 -0
  102. package/lib/performActions.d.ts +7 -5
  103. package/lib/performActions.js +12 -10
  104. package/lib/transform/object.d.ts +7 -4
  105. package/lib/transform/object.js +11 -7
  106. package/lib/transform/token.d.ts +6 -3
  107. package/lib/transform/token.js +16 -14
  108. package/lib/utils/combineJSON.d.ts +6 -2
  109. package/lib/utils/combineJSON.js +9 -3
  110. package/lib/utils/createFormatArgs.d.ts +5 -1
  111. package/lib/utils/createFormatArgs.js +9 -4
  112. package/lib/utils/detectDtcgSyntax.d.ts +8 -0
  113. package/lib/utils/detectDtcgSyntax.js +26 -0
  114. package/lib/utils/flattenTokens.d.ts +2 -7
  115. package/lib/utils/flattenTokens.js +21 -14
  116. package/lib/utils/index.d.ts +2 -2
  117. package/lib/utils/index.js +2 -2
  118. package/lib/utils/preprocess.d.ts +3 -1
  119. package/lib/utils/preprocess.js +17 -15
  120. package/lib/utils/references/getReferences.d.ts +7 -9
  121. package/lib/utils/references/getReferences.js +6 -5
  122. package/lib/utils/references/resolveReferences.d.ts +6 -6
  123. package/lib/utils/references/resolveReferences.js +10 -11
  124. package/package.json +1 -1
  125. package/types/Action.d.ts +3 -3
  126. package/types/Config.d.ts +9 -2
  127. package/types/File.d.ts +1 -1
  128. package/types/Filter.d.ts +1 -1
  129. package/types/Format.d.ts +5 -3
  130. package/types/Parser.d.ts +1 -1
  131. package/types/Transform.d.ts +6 -2
  132. package/types/FormatHelpers.d.ts +0 -0
@@ -9,6 +9,6 @@
9
9
  * @param {File} file
10
10
  * @param {PlatformConfig} [platform]
11
11
  */
12
- export default function cleanFile(file: File, platform?: import("../types/Config.d.ts").PlatformConfig | undefined): void;
12
+ export default function cleanFile(file: File, platform?: import("../types/Config.d.ts").PlatformConfig | undefined): Promise<void>;
13
13
  export type File = import('../types/File.d.ts').File;
14
14
  export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
package/lib/cleanFile.js CHANGED
@@ -26,7 +26,7 @@ import { fs } from 'style-dictionary/fs';
26
26
  * @param {File} file
27
27
  * @param {PlatformConfig} [platform]
28
28
  */
29
- export default function cleanFile(file, platform = {}) {
29
+ export default async function cleanFile(file, platform = {}) {
30
30
  let { destination } = file;
31
31
 
32
32
  if (typeof destination !== 'string') throw new Error('Please enter a valid destination');
@@ -9,5 +9,5 @@
9
9
  * @memberOf StyleDictionary
10
10
  * @param {PlatformConfig} platform
11
11
  */
12
- export default function cleanFiles(platform: PlatformConfig): void;
12
+ export default function cleanFiles(platform: PlatformConfig): Promise<void[] | undefined>;
13
13
  export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
package/lib/cleanFiles.js CHANGED
@@ -25,17 +25,20 @@ import cleanFile from './cleanFile.js';
25
25
  * @memberOf StyleDictionary
26
26
  * @param {PlatformConfig} platform
27
27
  */
28
- export default function cleanFiles(platform) {
28
+ export default async function cleanFiles(platform) {
29
29
  if (platform.buildPath && platform.buildPath.slice(-1) !== '/') {
30
30
  throw new Error('Build path must end in a trailing slash or you will get weird file names.');
31
31
  }
32
32
 
33
- // while neither the format or dictionary are used by clean file I'm passing them in for symmetry to buildFile
34
- platform.files?.forEach((file) => {
35
- if (file.format) {
36
- cleanFile(file, platform);
37
- } else {
38
- throw new Error('Please supply a template or formatter');
39
- }
40
- });
33
+ if (platform.files) {
34
+ return Promise.all(
35
+ platform.files.map((file) => {
36
+ if (file.format) {
37
+ return cleanFile(file, platform);
38
+ } else {
39
+ throw new Error('Please supply a template or formatter');
40
+ }
41
+ }),
42
+ );
43
+ }
41
44
  }
@@ -31,34 +31,39 @@ export default {
31
31
  * @memberof Actions
32
32
  */
33
33
  'android/copyImages': {
34
- do: function (dictionary, config) {
34
+ do: async function (dictionary, config, options) {
35
35
  const imagesDir = `${config.buildPath}android/main/res/drawable-`;
36
36
  /**
37
37
  * @param {Token} token
38
38
  */
39
- dictionary.allTokens.forEach((token) => {
40
- if (token.attributes?.category === 'asset' && token.attributes.type === 'image') {
41
- const name = token.path.slice(2, 4).join('_');
42
- const dir = `${imagesDir}${token.attributes.state}`;
43
- const path = `${dir}/${name}.png`;
44
- fs.mkdirSync(dir, { recursive: true });
45
- fs.copyFileSync(token.$value ?? token.value, path);
46
- }
47
- });
39
+ await Promise.all(
40
+ dictionary.allTokens.map((token) => {
41
+ if (token.attributes?.category === 'asset' && token.attributes.type === 'image') {
42
+ const name = token.path.slice(2, 4).join('_');
43
+ const dir = `${imagesDir}${token.attributes.state}`;
44
+ const path = `${dir}/${name}.png`;
45
+ return fs.promises.mkdir(dir, { recursive: true }).then(() => {
46
+ return fs.promises.copyFile(options.usesDtcg ? token.$value : token.value, path);
47
+ });
48
+ }
49
+ }),
50
+ );
48
51
  },
49
- undo: function (dictionary, config) {
52
+ undo: async function (dictionary, config) {
50
53
  const imagesDir = `${config.buildPath}android/main/res/drawable-`;
51
54
  /**
52
55
  * @param {Token} token
53
56
  */
54
- dictionary.allTokens.forEach((token) => {
55
- if (token.attributes?.category === 'asset' && token.attributes.type === 'image') {
56
- const name = token.path.slice(2, 4).join('_');
57
- const dir = `${imagesDir}${token.attributes.state}`;
58
- const path = `${dir}/${name}.png`;
59
- fs.unlinkSync(path);
60
- }
61
- });
57
+ await Promise.all(
58
+ dictionary.allTokens.map((token) => {
59
+ if (token.attributes?.category === 'asset' && token.attributes.type === 'image') {
60
+ const name = token.path.slice(2, 4).join('_');
61
+ const dir = `${imagesDir}${token.attributes.state}`;
62
+ const path = `${dir}/${name}.png`;
63
+ return fs.promises.unlink(path);
64
+ }
65
+ }),
66
+ );
62
67
  },
63
68
  },
64
69
 
@@ -68,15 +73,15 @@ export default {
68
73
  * @memberof Actions
69
74
  */
70
75
  copy_assets: {
71
- do: function (dictionary, config) {
76
+ do: async function (_, config) {
72
77
  // eslint-disable-next-line no-console
73
78
  console.log('Copying assets directory to ' + config.buildPath + 'assets');
74
- fs.copyFileSync('assets', config.buildPath + 'assets');
79
+ return fs.promises.copyFile('assets', config.buildPath + 'assets');
75
80
  },
76
- undo: function (dictionary, config) {
81
+ undo: async function (_, config) {
77
82
  // eslint-disable-next-line no-console
78
83
  console.log('Removing assets directory from ' + config.buildPath + 'assets');
79
- fs.unlinkSync(config.buildPath + 'assets');
84
+ return fs.promises.unlink(config.buildPath + 'assets');
80
85
  },
81
86
  },
82
87
  };
@@ -27,15 +27,17 @@
27
27
  * @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
28
28
  * @param {Formatting} [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}${token.name}${separator} ${token.value}${suffix}`
29
29
  * @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
30
+ * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
30
31
  * @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
31
32
  */
32
- export default function createPropertyFormatter({ outputReferences, outputReferenceFallbacks, dictionary, format, formatting, themeable, }: {
33
+ export default function createPropertyFormatter({ outputReferences, outputReferenceFallbacks, dictionary, format, formatting, themeable, usesDtcg, }: {
33
34
  outputReferences?: boolean | undefined;
34
35
  outputReferenceFallbacks?: boolean | undefined;
35
36
  dictionary: Dictionary;
36
37
  format?: string | undefined;
37
38
  formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
38
39
  themeable?: boolean | undefined;
40
+ usesDtcg?: boolean | undefined;
39
41
  }): (token: import('../../../types/DesignToken.d.ts').TransformedToken) => string;
40
42
  export type Dictionary = import('../../../types/DesignToken.d.ts').Dictionary;
41
43
  export type Formatting = import('../../../types/File.d.ts').FormattingOptions;
@@ -10,7 +10,7 @@
10
10
  * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
11
  * and limitations under the License.
12
12
  */
13
- import getReferences from '../../utils/references/getReferences.js';
13
+ import { _getReferences } from '../../utils/references/getReferences.js';
14
14
  import usesReferences from '../../utils/references/usesReferences.js';
15
15
 
16
16
  /**
@@ -113,6 +113,7 @@ function addComment(to_ret_token, comment, options) {
113
113
  * @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
114
114
  * @param {Formatting} [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}${token.name}${separator} ${token.value}${suffix}`
115
115
  * @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
116
+ * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
116
117
  * @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
117
118
  */
118
119
  export default function createPropertyFormatter({
@@ -122,6 +123,7 @@ export default function createPropertyFormatter({
122
123
  format,
123
124
  formatting = {},
124
125
  themeable = false,
126
+ usesDtcg = false,
125
127
  }) {
126
128
  /** @type {Formatting} */
127
129
  const formatDefaults = {};
@@ -159,7 +161,7 @@ export default function createPropertyFormatter({
159
161
  const { tokens, unfilteredTokens } = dictionary;
160
162
  return function (token) {
161
163
  let to_ret_token = `${indentation}${prefix}${token.name}${separator} `;
162
- let value = token.$value ?? token.value;
164
+ let value = usesDtcg ? token.$value : token.value;
163
165
 
164
166
  /**
165
167
  * A single value can have multiple references either by interpolation:
@@ -176,7 +178,7 @@ export default function createPropertyFormatter({
176
178
  if (outputReferences && usesReferences(token.original.value)) {
177
179
  // Formats that use this function expect `value` to be a string
178
180
  // or else you will get '[object Object]' in the output
179
- const refs = getReferences(token.original.value, tokens, { unfilteredTokens }, []);
181
+ const refs = _getReferences(token.original.value, tokens, { unfilteredTokens }, []);
180
182
 
181
183
  // original can either be an object value, which requires transitive value transformation in web CSS formats
182
184
  // or a different (primitive) type, meaning it can be stringified.
@@ -198,11 +200,8 @@ export default function createPropertyFormatter({
198
200
  // because Style Dictionary resolved this in the resolution step.
199
201
  // Here we are undoing that by replacing the value with
200
202
  // the reference's name
201
- if (
202
- (Object.hasOwn(ref, 'value') || Object.hasOwn(ref, '$value')) &&
203
- Object.hasOwn(ref, 'name')
204
- ) {
205
- const refVal = ref.$value ?? ref.value;
203
+ if (Object.hasOwn(ref, `${usesDtcg ? '$' : ''}value`) && Object.hasOwn(ref, 'name')) {
204
+ const refVal = usesDtcg ? ref.$value : ref.value;
206
205
  const replaceFunc = function () {
207
206
  if (format === 'css') {
208
207
  if (outputReferenceFallbacks) {
@@ -9,7 +9,7 @@
9
9
  * @param {File} [options.file] - The file object that is passed to the formatter.
10
10
  * @param {'short' | 'xml' | 'long'} [options.commentStyle] - The only options are 'short', 'xml' and 'long', which will use the // or \<!-- --> or \/\* style comments respectively. Default fallback is 'long'.
11
11
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a comment in code. The configurable strings are: prefix, lineSeparator, header, and footer.
12
- * @returns {String}
12
+ * @returns {Promise<string>}
13
13
  * @example
14
14
  * ```js
15
15
  * StyleDictionary.registerFormat({
@@ -26,7 +26,7 @@ export default function fileHeader({ file, commentStyle, formatting }: {
26
26
  file?: import("../../../types/File.d.ts").File | undefined;
27
27
  commentStyle?: "long" | "short" | "xml" | undefined;
28
28
  formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
29
- }): string;
29
+ }): Promise<string>;
30
30
  export type File = import('../../../types/File.d.ts').File;
31
31
  export type FileHeader = import('../../../types/File.d.ts').FileHeader;
32
32
  export type Formatting = import('../../../types/File.d.ts').FormattingOptions;
@@ -37,7 +37,7 @@ const defaultFormatting = {
37
37
  * @param {File} [options.file] - The file object that is passed to the formatter.
38
38
  * @param {'short' | 'xml' | 'long'} [options.commentStyle] - The only options are 'short', 'xml' and 'long', which will use the // or \<!-- --> or \/\* style comments respectively. Default fallback is 'long'.
39
39
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a comment in code. The configurable strings are: prefix, lineSeparator, header, and footer.
40
- * @returns {String}
40
+ * @returns {Promise<string>}
41
41
  * @example
42
42
  * ```js
43
43
  * StyleDictionary.registerFormat({
@@ -50,7 +50,7 @@ const defaultFormatting = {
50
50
  * });
51
51
  * ```
52
52
  */
53
- export default function fileHeader({ file, commentStyle, formatting = {} }) {
53
+ export default async function fileHeader({ file, commentStyle, formatting = {} }) {
54
54
  // showFileHeader is true by default
55
55
  let showFileHeader = true;
56
56
  if (typeof file?.options?.showFileHeader !== 'undefined') {
@@ -83,7 +83,9 @@ export default function fileHeader({ file, commentStyle, formatting = {} }) {
83
83
  footer = `${lineSeparator}-->`;
84
84
  }
85
85
 
86
- return `${header}${fn(defaultHeader)
86
+ const headerContent = await fn(defaultHeader);
87
+
88
+ return `${header}${headerContent
87
89
  .map(/** @param {string} line */ (line) => `${prefix}${line}`)
88
90
  .join(lineSeparator)}${footer}`;
89
91
  }
@@ -9,6 +9,7 @@
9
9
  * @param {Boolean} [options.outputReferences] - Whether or not to output references
10
10
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. This will get passed to `formatHelpers.createPropertyFormatter` and used for the `lineSeparator` between lines of code.
11
11
  * @param {Boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
12
+ * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
12
13
  * @returns {String}
13
14
  * @example
14
15
  * ```js
@@ -24,12 +25,13 @@
24
25
  * });
25
26
  * ```
26
27
  */
27
- export default function formattedVariables({ format, dictionary, outputReferences, formatting, themeable, }: {
28
+ export default function formattedVariables({ format, dictionary, outputReferences, formatting, themeable, usesDtcg, }: {
28
29
  format: string;
29
30
  dictionary: Dictionary;
30
31
  outputReferences?: boolean | undefined;
31
32
  formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
32
33
  themeable?: boolean | undefined;
34
+ usesDtcg?: boolean | undefined;
33
35
  }): string;
34
36
  export type Token = import('../../../types/DesignToken.d.ts').TransformedToken;
35
37
  export type Tokens = import('../../../types/DesignToken.d.ts').TransformedTokens;
@@ -36,6 +36,7 @@ const defaultFormatting = {
36
36
  * @param {Boolean} [options.outputReferences] - Whether or not to output references
37
37
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. This will get passed to `formatHelpers.createPropertyFormatter` and used for the `lineSeparator` between lines of code.
38
38
  * @param {Boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
39
+ * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
39
40
  * @returns {String}
40
41
  * @example
41
42
  * ```js
@@ -57,6 +58,7 @@ export default function formattedVariables({
57
58
  outputReferences = false,
58
59
  formatting = {},
59
60
  themeable = false,
61
+ usesDtcg = false,
60
62
  }) {
61
63
  // typecast, we know that by know the tokens have been transformed
62
64
  let allTokens = /** @type {Token[]} */ (dictionary.allTokens);
@@ -87,6 +89,7 @@ export default function formattedVariables({
87
89
  format,
88
90
  formatting,
89
91
  themeable,
92
+ usesDtcg,
90
93
  }),
91
94
  )
92
95
  .filter(function (strVal) {
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
3
+ * @typedef {import('../../../types/Config.d.ts').Config} Config
3
4
  */
4
5
  /**
5
6
  * Given some value, returns a basic valid TypeScript type for that value.
@@ -22,11 +23,12 @@
22
23
  * });
23
24
  *```
24
25
  * @param {any} value A value to check the type of.
25
- * @param {Options & {outputStringLiterals?: boolean}} [options]
26
+ * @param {Options & Config & {outputStringLiterals?: boolean}} [options]
26
27
  * @return {String} A valid name for a TypeScript type.
27
28
  *
28
29
  */
29
- export default function getTypeScriptType(value: any, options?: (import("../../../types/Config.d.ts").LocalOptions & {
30
+ export default function getTypeScriptType(value: any, options?: (import("../../../types/Config.d.ts").LocalOptions & import("../../../types/Config.d.ts").Config & {
30
31
  outputStringLiterals?: boolean | undefined;
31
32
  }) | undefined): string;
32
33
  export type Options = import('../../../types/Config.d.ts').LocalOptions;
34
+ export type Config = import('../../../types/Config.d.ts').Config;
@@ -13,6 +13,7 @@
13
13
 
14
14
  /**
15
15
  * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
16
+ * @typedef {import('../../../types/Config.d.ts').Config} Config
16
17
  */
17
18
 
18
19
  /**
@@ -36,7 +37,7 @@
36
37
  * });
37
38
  *```
38
39
  * @param {any} value A value to check the type of.
39
- * @param {Options & {outputStringLiterals?: boolean}} [options]
40
+ * @param {Options & Config & {outputStringLiterals?: boolean}} [options]
40
41
  * @return {String} A valid name for a TypeScript type.
41
42
  *
42
43
  */
@@ -45,7 +46,7 @@ export default function getTypeScriptType(value, options = {}) {
45
46
 
46
47
  if (Array.isArray(value)) return getArrayType(value);
47
48
  if (typeof value === 'object') return getObjectType(value);
48
- if (outputStringLiterals && typeof value === 'string') return `"${value}"`;
49
+ if (outputStringLiterals && typeof value === 'string') return `"${value.replace(/"/g, '\\"')}"`;
49
50
  if (['string', 'number', 'boolean'].includes(typeof value)) return typeof value;
50
51
 
51
52
  return 'any';
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
3
3
  * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
4
+ * @typedef {import('../../../types/Config.d.ts').PlatformConfig} PlatformConfig
4
5
  */
5
6
  /**
6
7
  *
@@ -13,6 +14,7 @@
13
14
  * @param {String} prefix - Character to prefix variable names, like '$' for Sass
14
15
  * @param {Token[]} allTokens - allTokens array on the dictionary object passed to the formatter function.
15
16
  * @param {Options} options - options object passed to the formatter function.
17
+ * @param {PlatformConfig} platform - platform specific options
16
18
  * @returns {String}
17
19
  * @example
18
20
  * ```js
@@ -24,6 +26,7 @@
24
26
  * });
25
27
  * ```
26
28
  */
27
- export default function iconsWithPrefix(prefix: string, allTokens: Token[], options: Options): string;
29
+ export default function iconsWithPrefix(prefix: string, allTokens: Token[], options: Options, platform: PlatformConfig): string;
28
30
  export type Token = import('../../../types/DesignToken.d.ts').TransformedToken;
29
31
  export type Options = import('../../../types/Config.d.ts').LocalOptions;
32
+ export type PlatformConfig = import('../../../types/Config.d.ts').PlatformConfig;
@@ -14,6 +14,7 @@
14
14
  /**
15
15
  * @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
16
16
  * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
17
+ * @typedef {import('../../../types/Config.d.ts').PlatformConfig} PlatformConfig
17
18
  */
18
19
 
19
20
  /**
@@ -27,6 +28,7 @@
27
28
  * @param {String} prefix - Character to prefix variable names, like '$' for Sass
28
29
  * @param {Token[]} allTokens - allTokens array on the dictionary object passed to the formatter function.
29
30
  * @param {Options} options - options object passed to the formatter function.
31
+ * @param {PlatformConfig} platform - platform specific options
30
32
  * @returns {String}
31
33
  * @example
32
34
  * ```js
@@ -38,14 +40,15 @@
38
40
  * });
39
41
  * ```
40
42
  */
41
- export default function iconsWithPrefix(prefix, allTokens, options) {
43
+ export default function iconsWithPrefix(prefix, allTokens, options, platform) {
42
44
  return allTokens
43
45
  .filter(function (token) {
44
46
  return token.attributes?.category === 'content' && token.attributes.type === 'icon';
45
47
  })
46
48
  .map(function (token) {
47
- const varName = prefix + token.name + ': ' + (token.$value ?? token.value) + ';';
48
- const className = '.' + options.prefix + '-icon.' + token.attributes?.item + ':before ';
49
+ const varName =
50
+ prefix + token.name + ': ' + (options.usesDtcg ? token.$value : token.value) + ';';
51
+ const className = '.' + platform.prefix + '-icon.' + token.attributes?.item + ':before ';
49
52
  const declaration = '{ content: ' + prefix + token.name + '; }';
50
53
  return varName + '\n' + className + declaration;
51
54
  })
@@ -6,6 +6,7 @@
6
6
  * @memberof module:formatHelpers
7
7
  * @name minifyDictionary
8
8
  * @param {Tokens} obj - The object to minify. You will most likely pass `dictionary.tokens` to it.
9
+ * @param {boolean} [usesDtcg] - Whether or not tokens are using DTCG syntax.
9
10
  * @returns {Tokens}
10
11
  * @example
11
12
  * ```js
@@ -17,5 +18,5 @@
17
18
  * });
18
19
  * ```
19
20
  */
20
- export default function minifyDictionary(obj: Tokens): Tokens;
21
+ export default function minifyDictionary(obj: Tokens, usesDtcg?: boolean | undefined): Tokens;
21
22
  export type Tokens = import('../../../types/DesignToken.d.ts').TransformedTokens;
@@ -20,6 +20,7 @@
20
20
  * @memberof module:formatHelpers
21
21
  * @name minifyDictionary
22
22
  * @param {Tokens} obj - The object to minify. You will most likely pass `dictionary.tokens` to it.
23
+ * @param {boolean} [usesDtcg] - Whether or not tokens are using DTCG syntax.
23
24
  * @returns {Tokens}
24
25
  * @example
25
26
  * ```js
@@ -31,7 +32,7 @@
31
32
  * });
32
33
  * ```
33
34
  */
34
- export default function minifyDictionary(obj) {
35
+ export default function minifyDictionary(obj, usesDtcg = false) {
35
36
  if (typeof obj !== 'object' || Array.isArray(obj)) {
36
37
  return obj;
37
38
  }
@@ -39,12 +40,12 @@ export default function minifyDictionary(obj) {
39
40
  /** @type {Tokens} */
40
41
  const toRet = {};
41
42
 
42
- if (Object.hasOwn(obj, '$value') || Object.hasOwn(obj, 'value')) {
43
- return obj.$value ?? obj.value;
43
+ if (Object.hasOwn(obj, `${usesDtcg ? '$' : ''}value`)) {
44
+ return usesDtcg ? obj.$value : obj.value;
44
45
  } else {
45
46
  for (const name in obj) {
46
47
  if (Object.hasOwn(obj, name)) {
47
- toRet[name] = minifyDictionary(obj[name]);
48
+ toRet[name] = minifyDictionary(obj[name], usesDtcg);
48
49
  }
49
50
  }
50
51
  }
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  import usesReferences from '../../utils/references/usesReferences.js';
15
- import getReferences from '../../utils/references/getReferences.js';
15
+ import { _getReferences } from '../../utils/references/getReferences.js';
16
16
 
17
17
  /**
18
18
  * @typedef {import('../../../types/DesignToken.d.ts').TransformedTokens} Tokens
@@ -57,10 +57,10 @@ export default function sortByReference(tokens, opts) {
57
57
  if (a.original && usesReferences(a.original.value)) {
58
58
  // Both a and b have references, we need to see if they reference each other
59
59
  if (b.original && usesReferences(b.original.value)) {
60
- const aRefs = getReferences(a.original.value, tokens, {
60
+ const aRefs = _getReferences(a.original.value, tokens, {
61
61
  unfilteredTokens: opts?.unfilteredTokens,
62
62
  });
63
- const bRefs = getReferences(b.original.value, tokens, {
63
+ const bRefs = _getReferences(b.original.value, tokens, {
64
64
  unfilteredTokens: opts?.unfilteredTokens,
65
65
  });
66
66