style-dictionary 5.1.3 → 5.2.0

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 (33) hide show
  1. package/examples/advanced/assets-base64-embed/package.json +1 -1
  2. package/examples/advanced/create-react-app/package.json +1 -1
  3. package/examples/advanced/create-react-native-app/package.json +1 -1
  4. package/examples/advanced/custom-parser/package.json +1 -1
  5. package/examples/advanced/custom-transforms/package.json +1 -1
  6. package/examples/advanced/font-face-rules/package.json +1 -1
  7. package/examples/advanced/format-helpers/package.json +1 -1
  8. package/examples/advanced/matching-build-files/package.json +1 -1
  9. package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
  10. package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
  11. package/examples/advanced/npm-module/package.json +1 -1
  12. package/examples/advanced/referencing_aliasing/package.json +1 -1
  13. package/examples/advanced/s3/package.json +1 -1
  14. package/examples/advanced/tailwind-preset/package.json +1 -1
  15. package/examples/advanced/tokens-deprecation/package.json +1 -1
  16. package/examples/advanced/transitive-transforms/package.json +1 -1
  17. package/examples/advanced/variables-in-outputs/package.json +1 -1
  18. package/examples/advanced/yaml-tokens/package.json +1 -1
  19. package/lib/StyleDictionary.js +1 -1
  20. package/lib/common/formatHelpers/fileHeader.js +11 -7
  21. package/lib/common/formatHelpers/formattedVariables.d.ts +5 -1
  22. package/lib/common/formatHelpers/formattedVariables.js +59 -10
  23. package/lib/common/formats.js +10 -5
  24. package/lib/common/transforms.js +3 -1
  25. package/lib/enums/index.d.ts +6 -5
  26. package/lib/enums/index.js +6 -5
  27. package/lib/enums/sorts.d.ts +3 -0
  28. package/lib/enums/sorts.js +3 -0
  29. package/lib/transform/token.js +17 -13
  30. package/package.json +1 -1
  31. package/types/Config.d.ts +2 -0
  32. package/types/Sort.d.ts +17 -0
  33. package/types/index.d.ts +1 -0
@@ -12,6 +12,6 @@
12
12
  "author": "",
13
13
  "license": "Apache-2.0",
14
14
  "devDependencies": {
15
- "style-dictionary": "^5.1.3"
15
+ "style-dictionary": "^5.2.0"
16
16
  }
17
17
  }
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "devDependencies": {
14
14
  "eslint-config-react-app": "^7.0.1",
15
- "style-dictionary": "^5.1.3"
15
+ "style-dictionary": "^5.2.0"
16
16
  },
17
17
  "resolutions": {
18
18
  "immer": "8.0.1",
@@ -29,7 +29,7 @@
29
29
  "eslint-config-react-app": "^7.0.1",
30
30
  "jest": "~25.2.6",
31
31
  "react-test-renderer": "~16.13.1",
32
- "style-dictionary": "^5.1.3"
32
+ "style-dictionary": "^5.2.0"
33
33
  },
34
34
  "jest": {
35
35
  "preset": "react-native"
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "Apache-2.0",
12
12
  "devDependencies": {
13
- "style-dictionary": "^5.1.3"
13
+ "style-dictionary": "^5.2.0"
14
14
  }
15
15
  }
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "^5.1.3"
19
+ "style-dictionary": "^5.2.0"
20
20
  }
21
21
  }
@@ -9,6 +9,6 @@
9
9
  },
10
10
  "license": "Apache-2.0",
11
11
  "devDependencies": {
12
- "style-dictionary": "^5.1.3"
12
+ "style-dictionary": "^5.2.0"
13
13
  }
14
14
  }
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "Apache-2.0",
12
12
  "devDependencies": {
13
- "style-dictionary": "^5.1.3"
13
+ "style-dictionary": "^5.2.0"
14
14
  }
15
15
  }
@@ -17,6 +17,6 @@
17
17
  "author": "Kelly Harrop <kn.harrop@gmail.com>",
18
18
  "license": "Apache-2.0",
19
19
  "devDependencies": {
20
- "style-dictionary": "^5.1.3"
20
+ "style-dictionary": "^5.2.0"
21
21
  }
22
22
  }
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "^5.1.3"
19
+ "style-dictionary": "^5.2.0"
20
20
  }
21
21
  }
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "homepage": "https://github.com/dbanksdesign/style-dictionary-node#readme",
22
22
  "devDependencies": {
23
- "style-dictionary": "^5.1.3",
23
+ "style-dictionary": "^5.2.0",
24
24
  "tinycolor2": "^1.4.1"
25
25
  }
26
26
  }
@@ -17,6 +17,6 @@
17
17
  "author": "",
18
18
  "license": "Apache-2.0",
19
19
  "devDependencies": {
20
- "style-dictionary": "^5.1.3"
20
+ "style-dictionary": "^5.2.0"
21
21
  }
22
22
  }
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "^5.1.3"
19
+ "style-dictionary": "^5.2.0"
20
20
  }
21
21
  }
@@ -16,6 +16,6 @@
16
16
  "devDependencies": {
17
17
  "aws-sdk": "^2.7.21",
18
18
  "fs-extra": "^1.0.0",
19
- "style-dictionary": "^5.1.3"
19
+ "style-dictionary": "^5.2.0"
20
20
  }
21
21
  }
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "license": "Apache-2.0",
12
12
  "devDependencies": {
13
- "style-dictionary": "^5.1.3",
13
+ "style-dictionary": "^5.2.0",
14
14
  "tailwindcss": "^3.4.15",
15
15
  "mocha": "^10.2.0",
16
16
  "chai": "^5.1.1"
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "^5.1.3"
19
+ "style-dictionary": "^5.2.0"
20
20
  }
21
21
  }
@@ -12,6 +12,6 @@
12
12
  "license": "ISC",
13
13
  "devDependencies": {
14
14
  "colorjs.io": "^0.5.2",
15
- "style-dictionary": "^5.1.3"
15
+ "style-dictionary": "^5.2.0"
16
16
  }
17
17
  }
@@ -11,6 +11,6 @@
11
11
  "author": "",
12
12
  "license": "MIT",
13
13
  "devDependencies": {
14
- "style-dictionary": "^5.1.3"
14
+ "style-dictionary": "^5.2.0"
15
15
  }
16
16
  }
@@ -10,7 +10,7 @@
10
10
  "author": "",
11
11
  "license": "Apache-2.0",
12
12
  "devDependencies": {
13
- "style-dictionary": "^5.1.3",
13
+ "style-dictionary": "^5.2.0",
14
14
  "yaml": "^1.10.0"
15
15
  }
16
16
  }
@@ -67,7 +67,7 @@ export default class StyleDictionary extends Register {
67
67
  // Placeholder is transformed on prepublish -> see scripts/inject-version.js
68
68
  // Another option might be import pkg from './package.json' with { "type": "json" } which would work in both browser and node, but support is not there yet.
69
69
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
70
- static VERSION = '5.1.3';
70
+ static VERSION = '5.2.0';
71
71
 
72
72
  /** @returns {Config} */
73
73
  get options() {
@@ -61,11 +61,15 @@ export default async function fileHeader({ file, commentStyle, formatting = {},
61
61
  fn = file.options.fileHeader;
62
62
  }
63
63
 
64
- let { prefix, lineSeparator, header, footer, fileHeaderTimestamp } = Object.assign(
65
- {},
66
- defaultFormatting,
67
- formatting,
68
- );
64
+ let {
65
+ prefix,
66
+ lineSeparator,
67
+ header,
68
+ commentStyle: _commentStyle,
69
+ footer,
70
+ fileHeaderTimestamp,
71
+ } = Object.assign({}, defaultFormatting, formatting);
72
+ const commentStyleMerged = commentStyle ?? _commentStyle;
69
73
 
70
74
  // default header
71
75
  const defaultHeader = [
@@ -73,11 +77,11 @@ export default async function fileHeader({ file, commentStyle, formatting = {},
73
77
  ...(fileHeaderTimestamp ? [`Generated on ${new Date().toUTCString()}`] : []),
74
78
  ];
75
79
 
76
- if (commentStyle === commentStyles.short) {
80
+ if (commentStyleMerged === commentStyles.short) {
77
81
  prefix = `// `;
78
82
  header = `${lineSeparator}`;
79
83
  footer = `${lineSeparator}${lineSeparator}`;
80
- } else if (commentStyle === 'xml') {
84
+ } else if (commentStyleMerged === 'xml') {
81
85
  prefix = ` `;
82
86
  header = `<!--${lineSeparator}`;
83
87
  footer = `${lineSeparator}-->`;
@@ -11,6 +11,7 @@
11
11
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. This will get passed to `formatHelpers` -> `createPropertyformat` and used for the `lineSeparator` between lines of code.
12
12
  * @param {Boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
13
13
  * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
14
+ * @param {SortOption} [options.sort] - Optional sorting strategy.
14
15
  * @returns {String}
15
16
  * @example
16
17
  * ```js
@@ -28,7 +29,7 @@
28
29
  * });
29
30
  * ```
30
31
  */
31
- export default function formattedVariables({ format, dictionary, outputReferences, outputReferenceFallbacks, formatting, themeable, usesDtcg, }: {
32
+ export default function formattedVariables({ format, dictionary, outputReferences, outputReferenceFallbacks, formatting, themeable, usesDtcg, sort, }: {
32
33
  format: string;
33
34
  dictionary: Dictionary;
34
35
  outputReferences?: import("../../../types/Format.d.ts").OutputReferences | undefined;
@@ -36,9 +37,12 @@ export default function formattedVariables({ format, dictionary, outputReference
36
37
  formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
37
38
  themeable?: boolean | undefined;
38
39
  usesDtcg?: boolean | undefined;
40
+ sort?: import("../../../types/Sort.d.ts").SortOption | undefined;
39
41
  }): string;
40
42
  export type Token = import("../../../types/DesignToken.d.ts").TransformedToken;
41
43
  export type Tokens = import("../../../types/DesignToken.d.ts").TransformedTokens;
42
44
  export type Formatting = import("../../../types/File.d.ts").FormattingOptions;
43
45
  export type OutputReferences = import("../../../types/Format.d.ts").OutputReferences;
46
+ export type SortFn = import("../../../types/Sort.d.ts").SortFn;
47
+ export type SortOption = import("../../../types/Sort.d.ts").SortOption;
44
48
  export type Dictionary = import("../../../types/DesignToken.d.ts").Dictionary;
@@ -1,11 +1,14 @@
1
1
  import createPropertyFormatter from './createPropertyFormatter.js';
2
2
  import sortByReference from './sortByReference.js';
3
+ import sortByName from './sortByName.js';
3
4
 
4
5
  /**
5
6
  * @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
6
7
  * @typedef {import('../../../types/DesignToken.d.ts').TransformedTokens} Tokens
7
8
  * @typedef {import('../../../types/File.d.ts').FormattingOptions} Formatting
8
9
  * @typedef {import('../../../types/Format.d.ts').OutputReferences} OutputReferences
10
+ * @typedef {import('../../../types/Sort.d.ts').SortFn} SortFn
11
+ * @typedef {import('../../../types/Sort.d.ts').SortOption} SortOption
9
12
  * @typedef {import('../../../types/DesignToken.d.ts').Dictionary} Dictionary
10
13
  */
11
14
 
@@ -26,6 +29,7 @@ const defaultFormatting = {
26
29
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. This will get passed to `formatHelpers` -> `createPropertyformat` and used for the `lineSeparator` between lines of code.
27
30
  * @param {Boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
28
31
  * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
32
+ * @param {SortOption} [options.sort] - Optional sorting strategy.
29
33
  * @returns {String}
30
34
  * @example
31
35
  * ```js
@@ -51,6 +55,7 @@ export default function formattedVariables({
51
55
  formatting = {},
52
56
  themeable = false,
53
57
  usesDtcg = false,
58
+ sort,
54
59
  }) {
55
60
  // typecast, we know that by know the tokens have been transformed
56
61
  let allTokens = /** @type {Token[]} */ (dictionary.allTokens);
@@ -59,18 +64,62 @@ export default function formattedVariables({
59
64
 
60
65
  let { lineSeparator } = Object.assign({}, defaultFormatting, formatting);
61
66
 
62
- // Some languages are imperative, meaning a variable has to be defined
63
- // before it is used. If `outputReferences` is true, check if the token
64
- // has a reference, and if it does send it to the end of the array.
65
- // We also need to account for nested references, a -> b -> c. They
66
- // need to be defined in reverse order: c, b, a so that the reference always
67
- // comes after the definition
68
- if (outputReferences) {
67
+ const sortInputs = sort ? (Array.isArray(sort) ? sort : [sort]) : [];
68
+
69
+ // reference-safety sorter is an internal concern:
70
+ // we only compute it when outputReferences=true
71
+ const byReference = outputReferences
72
+ ? sortByReference(tokens, { unfilteredTokens: dictionary.unfilteredTokens, usesDtcg })
73
+ : null;
74
+
75
+ /**
76
+ * @param {SortFn} keyOrFn
77
+ * @returns {((a: Token, b: Token) => number) | null}
78
+ */
79
+ const normalize = (keyOrFn) => {
80
+ if (typeof keyOrFn === 'function') return keyOrFn;
81
+
82
+ if (keyOrFn === 'name') return sortByName;
83
+
84
+ // Fail loudly for invalid values (esp. typos)
85
+ if (typeof keyOrFn === 'string') {
86
+ throw new Error(
87
+ `Invalid "sort" option: "${keyOrFn}". ` +
88
+ `Use "name", a comparator function, or an array of those.`,
89
+ );
90
+ }
91
+
92
+ // Non-string non-function values are also invalid
93
+ throw new Error(
94
+ `Invalid "sort" option type: ${typeof keyOrFn}. ` +
95
+ `Use "name", a comparator function, or an array of those.`,
96
+ );
97
+ };
98
+
99
+ /**
100
+ * @param {((a: Token, b: Token) => number) | null} s
101
+ * @returns {s is ((a: Token, b: Token) => number)}
102
+ */
103
+ const isComparator = (s) => s !== null;
104
+
105
+ const requestedSorters = sortInputs.map(normalize).filter(isComparator);
106
+
107
+ // If outputReferences=true, enforce reference-safe ordering first (define-before-use safety).
108
+ // The user-provided sort acts as a tie-breaker on top.
109
+ const comparators = outputReferences
110
+ ? [byReference, ...requestedSorters].filter(isComparator)
111
+ : requestedSorters.filter(isComparator);
112
+
113
+ if (comparators.length > 0) {
69
114
  // note: using the spread operator here so we get a new array rather than
70
115
  // mutating the original
71
- allTokens = [...allTokens].sort(
72
- sortByReference(tokens, { unfilteredTokens: dictionary.unfilteredTokens, usesDtcg }),
73
- );
116
+ allTokens = [...allTokens].sort((a, b) => {
117
+ for (const cmp of comparators) {
118
+ const r = cmp(a, b);
119
+ if (r !== 0) return r;
120
+ }
121
+ return 0;
122
+ });
74
123
  }
75
124
 
76
125
  return allTokens
@@ -193,7 +193,7 @@ const formats = {
193
193
  : options.selector
194
194
  ? [options.selector]
195
195
  : [`:root`];
196
- const { outputReferences, outputReferenceFallbacks, usesDtcg, formatting } = options;
196
+ const { outputReferences, outputReferenceFallbacks, usesDtcg, formatting, sort } = options;
197
197
  const header = await fileHeader({
198
198
  file,
199
199
  formatting: getFormattingCloneWithoutPrefix(formatting),
@@ -219,6 +219,7 @@ const formats = {
219
219
  indentation: indentation.repeat(selector.length),
220
220
  },
221
221
  usesDtcg,
222
+ sort,
222
223
  });
223
224
 
224
225
  return (
@@ -289,7 +290,7 @@ const formats = {
289
290
  */
290
291
  [scssMapDeep]: async function ({ dictionary, options, file }) {
291
292
  // Default the "themeable" option to true for backward compatibility.
292
- const { outputReferences, themeable = true, formatting, usesDtcg } = options;
293
+ const { outputReferences, themeable = true, formatting, usesDtcg, sort } = options;
293
294
  const header = await fileHeader({
294
295
  file,
295
296
  commentStyle: long,
@@ -306,6 +307,7 @@ const formats = {
306
307
  themeable,
307
308
  formatting,
308
309
  usesDtcg,
310
+ sort,
309
311
  }) +
310
312
  '\n' +
311
313
  scssMapDeepTemplate({ dictionary, options })
@@ -326,7 +328,7 @@ const formats = {
326
328
  * ```
327
329
  */
328
330
  [scssVariables]: async function ({ dictionary, options, file }) {
329
- const { outputReferences, themeable = false, formatting, usesDtcg } = options;
331
+ const { outputReferences, themeable = false, formatting, usesDtcg, sort } = options;
330
332
  const header = await fileHeader({
331
333
  file,
332
334
  commentStyle: short,
@@ -342,6 +344,7 @@ const formats = {
342
344
  themeable,
343
345
  formatting,
344
346
  usesDtcg,
347
+ sort,
345
348
  }) +
346
349
  '\n'
347
350
  );
@@ -381,7 +384,7 @@ const formats = {
381
384
  * ```
382
385
  */
383
386
  [lessVariables]: async function ({ dictionary, options, file }) {
384
- const { outputReferences, formatting, usesDtcg } = options;
387
+ const { outputReferences, formatting, usesDtcg, sort } = options;
385
388
  const header = await fileHeader({
386
389
  file,
387
390
  commentStyle: short,
@@ -396,6 +399,7 @@ const formats = {
396
399
  outputReferences,
397
400
  formatting,
398
401
  usesDtcg,
402
+ sort,
399
403
  }) +
400
404
  '\n'
401
405
  );
@@ -435,7 +439,7 @@ const formats = {
435
439
  * ```
436
440
  */
437
441
  [stylusVariables]: async function ({ dictionary, options, file, platform }) {
438
- const { formatting, usesDtcg } = options;
442
+ const { formatting, usesDtcg, sort } = options;
439
443
  const outputReferences = !!platform.options?.outputReferences;
440
444
  const header = await fileHeader({
441
445
  file,
@@ -451,6 +455,7 @@ const formats = {
451
455
  outputReferences,
452
456
  formatting,
453
457
  usesDtcg,
458
+ sort,
454
459
  }) +
455
460
  '\n'
456
461
  );
@@ -105,7 +105,9 @@ function wrapValueWithDoubleQuote(token, options) {
105
105
  * @returns {string}
106
106
  */
107
107
  function throwSizeError(name, value, unitType) {
108
- throw `Invalid Number: '${name}: ${value}' is not a valid number, cannot transform to '${unitType}' \n`;
108
+ throw new Error(
109
+ `Invalid Number: '${name}: ${value}' is not a valid number, cannot transform to '${unitType}' \n`,
110
+ );
109
111
  }
110
112
 
111
113
  /**
@@ -1,12 +1,13 @@
1
1
  export { actions } from "./actions.js";
2
- export { logWarningLevels } from "./logWarningLevels.js";
3
- export { logVerbosityLevels } from "./logVerbosityLevels.js";
4
- export { logBrokenReferenceLevels } from "./logBrokenReferenceLevels.js";
5
- export { commentStyles } from "./commentStyles.js";
6
2
  export { commentPositions } from "./commentPositions.js";
3
+ export { commentStyles } from "./commentStyles.js";
7
4
  export { fileHeaderCommentStyles } from "./fileHeaderCommentStyles.js";
8
5
  export { formats } from "./formats.js";
6
+ export { logBrokenReferenceLevels } from "./logBrokenReferenceLevels.js";
7
+ export { logVerbosityLevels } from "./logVerbosityLevels.js";
8
+ export { logWarningLevels } from "./logWarningLevels.js";
9
+ export { propertyFormatNames } from "./propertyFormatNames.js";
10
+ export { builtInSorts } from "./sorts.js";
9
11
  export { transformGroups } from "./transformGroups.js";
10
12
  export { transforms } from "./transforms.js";
11
13
  export { transformTypes } from "./transformTypes.js";
12
- export { propertyFormatNames } from "./propertyFormatNames.js";
@@ -1,12 +1,13 @@
1
1
  export { actions } from './actions.js';
2
- export { logWarningLevels } from './logWarningLevels.js';
3
- export { logVerbosityLevels } from './logVerbosityLevels.js';
4
- export { logBrokenReferenceLevels } from './logBrokenReferenceLevels.js';
5
- export { commentStyles } from './commentStyles.js';
6
2
  export { commentPositions } from './commentPositions.js';
3
+ export { commentStyles } from './commentStyles.js';
7
4
  export { fileHeaderCommentStyles } from './fileHeaderCommentStyles.js';
8
5
  export { formats } from './formats.js';
6
+ export { logBrokenReferenceLevels } from './logBrokenReferenceLevels.js';
7
+ export { logVerbosityLevels } from './logVerbosityLevels.js';
8
+ export { logWarningLevels } from './logWarningLevels.js';
9
+ export { propertyFormatNames } from './propertyFormatNames.js';
10
+ export { builtInSorts } from './sorts.js';
9
11
  export { transformGroups } from './transformGroups.js';
10
12
  export { transforms } from './transforms.js';
11
13
  export { transformTypes } from './transformTypes.js';
12
- export { propertyFormatNames } from './propertyFormatNames.js';
@@ -0,0 +1,3 @@
1
+ export namespace builtInSorts {
2
+ let name: "name";
3
+ }
@@ -0,0 +1,3 @@
1
+ export const builtInSorts = {
2
+ name: /** @type {'name'} */ ('name'),
3
+ };
@@ -46,20 +46,24 @@ async function _transformTokenWrapper(transform, token, config, options, vol) {
46
46
  try {
47
47
  to_ret = await transform.transform(token, config, options, vol);
48
48
  } catch (e) {
49
- if (e instanceof Error) {
50
- const transformError = createErrorMessage(token, e, transform.name, !!options?.usesDtcg);
51
- // collect the errors so we can warn the user at the end of the run
52
- GroupMessages.add(TRANSFORM_ERRORS, transformError);
49
+ const message = e instanceof Error ? e.message : String(e);
50
+ const transformError = createErrorMessage(
51
+ token,
52
+ e instanceof Error ? e : new Error(message),
53
+ transform.name,
54
+ !!options?.usesDtcg,
55
+ );
56
+ // collect the errors so we can warn the user at the end of the run
57
+ GroupMessages.add(TRANSFORM_ERRORS, transformError);
53
58
 
54
- // Return a sensible fallback value
55
- switch (transform.type) {
56
- case 'attribute':
57
- return token.attributes;
58
- case 'name':
59
- return token.name;
60
- case 'value':
61
- return options.usesDtcg ? token.$value : token.value;
62
- }
59
+ // Return a sensible fallback value
60
+ switch (transform.type) {
61
+ case 'attribute':
62
+ return token.attributes;
63
+ case 'name':
64
+ return token.name;
65
+ case 'value':
66
+ return options.usesDtcg ? token.$value : token.value;
63
67
  }
64
68
  }
65
69
  return to_ret;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "style-dictionary",
3
- "version": "5.1.3",
3
+ "version": "5.2.0",
4
4
  "description": "Style once, use everywhere. A build system for creating cross-platform styles.",
5
5
  "keywords": [
6
6
  "style dictionary",
package/types/Config.d.ts CHANGED
@@ -5,6 +5,7 @@ import type { Parser } from './Parser.js';
5
5
  import type { Preprocessor } from './Preprocessor.js';
6
6
  import type { Transform } from './Transform.js';
7
7
  import type { Format, OutputReferences } from './Format.js';
8
+ import type { SortOption } from './Sort.js';
8
9
  import type { Action } from './Action.js';
9
10
  import { logBrokenReferenceLevels, logWarningLevels, logVerbosityLevels } from '../lib/enums/index.js';
10
11
  type logWarningLevels = typeof logWarningLevels;
@@ -26,6 +27,7 @@ export interface LocalOptions {
26
27
  outputReferences?: OutputReferences;
27
28
  outputReferenceFallbacks?: boolean;
28
29
  formatting?: FormattingOverrides;
30
+ sort?: SortOption;
29
31
  [key: string]: any;
30
32
  }
31
33
  export interface GetReferencesOptions {
@@ -0,0 +1,17 @@
1
+ import type { TransformedToken } from './DesignToken.js';
2
+ import { builtInSorts } from '../lib/enums/sorts.js';
3
+ export type BuiltInSorts = typeof builtInSorts;
4
+ export interface Sort {
5
+ name: string;
6
+ sort: SortFn;
7
+ }
8
+ /**
9
+ * A single sort function - either a built-in sort referenced by name string or a custom comparator function
10
+ * for inline usage
11
+ */
12
+ export type SortFn = string | ((a: TransformedToken, b: TransformedToken) => number);
13
+ /**
14
+ * Sort option for formattedVariables - can be a single sort item or an array of sort items
15
+ * (for chaining multiple sorts as tie-breakers)
16
+ */
17
+ export type SortOption = SortFn | SortFn[];
package/types/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export type { DesignToken, DesignTokens, PreprocessedTokens, TransformedToken, T
4
4
  export type { FileHeader, File, FormattingOptions } from './File.js';
5
5
  export type { Filter } from './Filter.js';
6
6
  export type { Format, FormatFnArguments, FormatFn, OutputReferences } from './Format.js';
7
+ export type { SortOption, SortFn, BuiltInSorts } from './Sort.js';
7
8
  export type { Parser, ParserOptions } from './Parser.js';
8
9
  export type { Preprocessor } from './Preprocessor.js';
9
10
  export type { Transform, NameTransform, AttributeTransform, ValueTransform } from './Transform.js';