diff --git a/__integration__/async.test.js b/__integration__/async.test.js index 327ba0dca..761da6bf0 100644 --- a/__integration__/async.test.js +++ b/__integration__/async.test.js @@ -17,11 +17,7 @@ import { fs } from 'style-dictionary/fs'; import { resolve } from '../lib/resolve.js'; import { buildPath } from './_constants.js'; import { clearOutput } from '../__tests__/__helpers.js'; -import { - transforms, - predefinedPropertyFormatNames, - transformTypes, -} from '../lib/enums/buildInEnums.js'; +import { transforms, propertyFormatNames, transformTypes } from '../lib/enums/buildInEnums.js'; const sleep = async (time) => { await new Promise((resolve) => setTimeout(resolve, time)); @@ -80,7 +76,7 @@ describe('integration', async function () { (await fileHeader({ file })) + ':root {\n' + formattedVariables({ - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, dictionary, outputReferences, }) + diff --git a/__tests__/common/formatHelpers/createPropertyFormatter.test.js b/__tests__/common/formatHelpers/createPropertyFormatter.test.js index e96b69a22..eceb97829 100644 --- a/__tests__/common/formatHelpers/createPropertyFormatter.test.js +++ b/__tests__/common/formatHelpers/createPropertyFormatter.test.js @@ -17,7 +17,7 @@ import { outputReferencesFilter } from '../../../lib/utils/references/outputRefe import { commentStyles, commentPositions, - predefinedPropertyFormatNames, + propertyFormatNames, } from '../../../lib/enums/buildInEnums.js'; const dictionary = { @@ -177,7 +177,7 @@ describe('common', () => { const propFormatter = createPropertyFormatter({ outputReferences: true, dictionary: { tokens: dictionary }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, }); expect(propFormatter(dictionary.foo)).to.equal(' --foo: 5px;'); expect(propFormatter(dictionary.ref)).to.equal(' --ref: var(--foo);'); @@ -187,7 +187,7 @@ describe('common', () => { const propFormatter = createPropertyFormatter({ outputReferences: true, dictionary: { tokens: transformedDictionary }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, }); expect(propFormatter(transformedDictionary.foo)).to.equal(' --foo: 5px;'); expect(propFormatter(transformedDictionary.ref)).to.equal(' --ref: var(--foo);'); @@ -197,7 +197,7 @@ describe('common', () => { const propFormatter = createPropertyFormatter({ outputReferences: true, dictionary: { tokens: numberDictionary }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, }); expect(propFormatter(numberDictionary.foo)).to.equal(' --foo: 10;'); expect(propFormatter(numberDictionary.ref)).to.equal(' --ref: var(--foo);'); @@ -207,7 +207,7 @@ describe('common', () => { const propFormatter = createPropertyFormatter({ outputReferences: true, dictionary: { tokens: numberDictionary }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, }); expect(propFormatter(numberDictionary.zero)).to.equal(' --zero: 0;'); expect(propFormatter(numberDictionary['ref-zero'])).to.equal( @@ -219,7 +219,7 @@ describe('common', () => { const propFormatter = createPropertyFormatter({ outputReferences: true, dictionary: { tokens: multiDictionary }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, }); expect(propFormatter(multiDictionary.foo)).to.equal(' --foo: 10px;'); expect(propFormatter(multiDictionary.bar)).to.equal(' --bar: 15px;'); @@ -269,7 +269,7 @@ describe('common', () => { unfilteredTokens, allTokens, }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, // outputReferences function that only outputs the refs if the token name is "bar" outputReferences: (token) => token.name === 'bar', }); @@ -329,7 +329,7 @@ describe('common', () => { unfilteredTokens, allTokens, }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, // outputReferences function that only outputs the refs if the referred tokens are not filtered out outputReferences: outputReferencesFilter, }); @@ -390,7 +390,7 @@ describe('common', () => { unfilteredTokens, allTokens, }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, usesDtcg: true, // outputReferences function that only outputs the refs if the referred tokens are not filtered out outputReferences: outputReferencesFilter, @@ -407,7 +407,7 @@ describe('common', () => { const propFormatter = createPropertyFormatter({ outputReferences: true, dictionary: { tokens: objectDictionary }, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, }); // expect(propFormatter(objectDictionary.tokens.foo)).to.equal(' --foo: 5px;'); @@ -453,12 +453,12 @@ describe('common', () => { it('should default to putting comment next to the output value', async () => { // long commentStyle const cssFormatter = createPropertyFormatter({ - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, dictionary: { tokens: commentDictionary }, }); // short commentStyle const sassFormatter = createPropertyFormatter({ - format: predefinedPropertyFormatNames.sass, + format: propertyFormatNames.sass, dictionary: { tokens: commentDictionary }, }); @@ -478,7 +478,7 @@ describe('common', () => { it('allows overriding formatting commentStyle', async () => { // long commentStyle const cssFormatter = createPropertyFormatter({ - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, dictionary: { tokens: commentDictionary }, formatting: { commentStyle: commentStyles.long, @@ -487,7 +487,7 @@ describe('common', () => { }); // short commentStyle const sassFormatter = createPropertyFormatter({ - format: predefinedPropertyFormatNames.sass, + format: propertyFormatNames.sass, dictionary: { tokens: commentDictionary }, formatting: { commentStyle: commentStyles.short, @@ -547,7 +547,7 @@ describe('common', () => { it('supports DTCG spec $description property for comments', async () => { // long commentStyle const cssFormatter = createPropertyFormatter({ - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, dictionary: { tokens: dtcgDictionary }, usesDtcg: true, }); @@ -564,7 +564,7 @@ describe('common', () => { it('supports DTCG spec $value for outputReferences', async () => { // long commentStyle const cssFormatter = createPropertyFormatter({ - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, outputReferences: true, dictionary: { tokens: dtcgDictionary }, usesDtcg: true, diff --git a/docs/src/content/docs/reference/Hooks/Formats/helpers.md b/docs/src/content/docs/reference/Hooks/Formats/helpers.md index 91d495b07..7bfd9e373 100644 --- a/docs/src/content/docs/reference/Hooks/Formats/helpers.md +++ b/docs/src/content/docs/reference/Hooks/Formats/helpers.md @@ -21,7 +21,7 @@ StyleDictionary.registerFormat({ header + ':root {\n' + formattedVariables({ - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, dictionary, outputReferences, }) + diff --git a/docs/src/content/docs/reference/Utils/format-helpers.md b/docs/src/content/docs/reference/Utils/format-helpers.md index a790529f7..1baf599ef 100644 --- a/docs/src/content/docs/reference/Utils/format-helpers.md +++ b/docs/src/content/docs/reference/Utils/format-helpers.md @@ -19,7 +19,7 @@ StyleDictionary.registerFormat({ header + ':root {\n' + formattedVariables({ - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, dictionary, outputReferences, }) + @@ -61,7 +61,7 @@ StyleDictionary.registerFormat({ const formatProperty = createPropertyFormatter({ outputReferences, dictionary, - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, }); return dictionary.allTokens.map(formatProperty).join('\n'); }, @@ -127,7 +127,7 @@ StyleDictionary.registerFormat({ name: 'myCustomFormat', format: function ({ dictionary, options }) { return formattedVariables({ - format: predefinedPropertyFormatNames.less, + format: propertyFormatNames.less, dictionary, outputReferences: options.outputReferences, }); diff --git a/docs/src/content/docs/version-4/migration.md b/docs/src/content/docs/version-4/migration.md index c7df96765..0355ad582 100644 --- a/docs/src/content/docs/version-4/migration.md +++ b/docs/src/content/docs/version-4/migration.md @@ -159,7 +159,7 @@ StyleDictionary.registerFormat({ // this helper is now async! because the user-passed file.fileHeader might be an async function (await fileHeader({ file })) + ':root {\n' + - formattedVariables({ format: predefinedPropertyFormatNames.css, dictionary, outputReferences }) + + formattedVariables({ format: propertyFormatNames.css, dictionary, outputReferences }) + '\n}\n' ); }, @@ -976,7 +976,7 @@ StyleDictionary.registerFormat({ // this helper is now async! because the user-passed file.fileHeader might be an async function (await fileHeader({ file })) + ':root {\n' + - formattedVariables({ format: predefinedPropertyFormatNames.css, dictionary, outputReferences }) + + formattedVariables({ format: propertyFormatNames.css, dictionary, outputReferences }) + '\n}\n' ); }, diff --git a/lib/common/formatHelpers/createPropertyFormatter.js b/lib/common/formatHelpers/createPropertyFormatter.js index 7735bbc17..d9750c0a0 100644 --- a/lib/common/formatHelpers/createPropertyFormatter.js +++ b/lib/common/formatHelpers/createPropertyFormatter.js @@ -12,11 +12,7 @@ */ import { getReferences } from '../../utils/references/getReferences.js'; import usesReferences from '../../utils/references/usesReferences.js'; -import { - commentStyles, - commentPositions, - predefinedPropertyFormatNames, -} from '../../enums/buildInEnums.js'; +import { commentStyles, commentPositions, propertyFormatNames } from '../../enums/buildInEnums.js'; /** * @typedef {import('../../../types/DesignToken.ts').TransformedToken} TransformedToken @@ -107,7 +103,7 @@ export function addComment(to_ret_token, comment, options) { * const formatProperty = createPropertyFormatter({ * outputReferences, * dictionary, - * format: predefinedPropertyFormatNames.css + * format: propertyFormatNames.css * }); * return dictionary.allTokens.map(formatProperty).join('\n'); * } @@ -135,24 +131,24 @@ export default function createPropertyFormatter({ /** @type {Formatting} */ const formatDefaults = {}; switch (format) { - case predefinedPropertyFormatNames.css: + case propertyFormatNames.css: formatDefaults.prefix = '--'; formatDefaults.indentation = ' '; formatDefaults.separator = ':'; break; - case predefinedPropertyFormatNames.sass: + case propertyFormatNames.sass: formatDefaults.prefix = '$'; formatDefaults.commentStyle = /** @type {'short' | 'long' | 'none'} */ (commentStyles.short); formatDefaults.indentation = ''; formatDefaults.separator = ':'; break; - case predefinedPropertyFormatNames.less: + case propertyFormatNames.less: formatDefaults.prefix = '@'; formatDefaults.commentStyle = /** @type {'short' | 'long' | 'none'} */ (commentStyles.short); formatDefaults.indentation = ''; formatDefaults.separator = ':'; break; - case predefinedPropertyFormatNames.stylus: + case propertyFormatNames.stylus: formatDefaults.prefix = '$'; formatDefaults.commentStyle = /** @type {'short' | 'long' | 'none'} */ (commentStyles.short); formatDefaults.indentation = ''; @@ -224,7 +220,7 @@ export default function createPropertyFormatter({ if (Object.hasOwn(ref, `${usesDtcg ? '$' : ''}value`) && Object.hasOwn(ref, 'name')) { const refVal = usesDtcg ? ref.$value : ref.value; const replaceFunc = function () { - if (format === predefinedPropertyFormatNames.css) { + if (format === propertyFormatNames.css) { if (outputReferenceFallbacks) { return `var(${prefix}${ref.name}, ${refVal})`; } else { @@ -247,7 +243,7 @@ export default function createPropertyFormatter({ to_ret_token += value; const themeable_token = typeof token.themeable === 'boolean' ? token.themeable : themeable; - if (format === predefinedPropertyFormatNames.sass && themeable_token) { + if (format === propertyFormatNames.sass && themeable_token) { to_ret_token += ' !default'; } diff --git a/lib/common/formatHelpers/formattedVariables.js b/lib/common/formatHelpers/formattedVariables.js index ba901a4c6..e66629fb7 100644 --- a/lib/common/formatHelpers/formattedVariables.js +++ b/lib/common/formatHelpers/formattedVariables.js @@ -46,7 +46,7 @@ const defaultFormatting = { * name: 'myCustomFormat', * format: function({ dictionary, options }) { * return formattedVariables({ - * format: predefinedPropertyFormatNames.less, + * format: propertyFormatNames.less, * dictionary, * outputReferences: options.outputReferences * }); diff --git a/lib/common/formats.js b/lib/common/formats.js index 091bc40d0..1c5ad3592 100644 --- a/lib/common/formats.js +++ b/lib/common/formats.js @@ -49,7 +49,7 @@ import { commentStyles, fileHeaderCommentStyles, fileFormats, - predefinedPropertyFormatNames, + propertyFormatNames, } from '../enums/buildInEnums.js'; /** @@ -107,7 +107,7 @@ const formats = { header + `${selector} {\n` + formattedVariables({ - format: predefinedPropertyFormatNames.css, + format: propertyFormatNames.css, dictionary, outputReferences, outputReferenceFallbacks, @@ -180,7 +180,7 @@ const formats = { '\n' + header + formattedVariables({ - format: predefinedPropertyFormatNames.sass, + format: propertyFormatNames.sass, dictionary, outputReferences, themeable, @@ -216,7 +216,7 @@ const formats = { return ( header + formattedVariables({ - format: predefinedPropertyFormatNames.sass, + format: propertyFormatNames.sass, dictionary, outputReferences, themeable, @@ -271,7 +271,7 @@ const formats = { return ( header + formattedVariables({ - format: predefinedPropertyFormatNames.less, + format: propertyFormatNames.less, dictionary, outputReferences, formatting, @@ -326,7 +326,7 @@ const formats = { return ( header + formattedVariables({ - format: predefinedPropertyFormatNames.stylus, + format: propertyFormatNames.stylus, dictionary, outputReferences, formatting, diff --git a/lib/enums/buildInEnums.js b/lib/enums/buildInEnums.js index 4daadcbca..4f1bb1d5b 100644 --- a/lib/enums/buildInEnums.js +++ b/lib/enums/buildInEnums.js @@ -160,7 +160,7 @@ export const transformTypes = { value: 'value', }; -export const predefinedPropertyFormatNames = { +export const propertyFormatNames = { css: 'css', sass: 'sass', less: 'less',