Skip to content

Commit

Permalink
refactor: rename enum predefinedPropertyFormatNames to propertyFormat…
Browse files Browse the repository at this point in the history
…Names
  • Loading branch information
Dario Soller committed Oct 28, 2024
1 parent d71466d commit 7926485
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 48 deletions.
8 changes: 2 additions & 6 deletions __integration__/async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -80,7 +76,7 @@ describe('integration', async function () {
(await fileHeader({ file })) +
':root {\n' +
formattedVariables({
format: predefinedPropertyFormatNames.css,
format: propertyFormatNames.css,
dictionary,
outputReferences,
}) +
Expand Down
32 changes: 16 additions & 16 deletions __tests__/common/formatHelpers/createPropertyFormatter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { outputReferencesFilter } from '../../../lib/utils/references/outputRefe
import {
commentStyles,
commentPositions,
predefinedPropertyFormatNames,
propertyFormatNames,
} from '../../../lib/enums/buildInEnums.js';

const dictionary = {
Expand Down Expand Up @@ -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);');
Expand All @@ -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);');
Expand All @@ -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);');
Expand All @@ -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(
Expand All @@ -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;');
Expand Down Expand Up @@ -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',
});
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
Expand All @@ -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;');

Expand Down Expand Up @@ -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 },
});

Expand All @@ -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,
Expand All @@ -487,7 +487,7 @@ describe('common', () => {
});
// short commentStyle
const sassFormatter = createPropertyFormatter({
format: predefinedPropertyFormatNames.sass,
format: propertyFormatNames.sass,
dictionary: { tokens: commentDictionary },
formatting: {
commentStyle: commentStyles.short,
Expand Down Expand Up @@ -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,
});
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/reference/Hooks/Formats/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ StyleDictionary.registerFormat({
header +
':root {\n' +
formattedVariables({
format: predefinedPropertyFormatNames.css,
format: propertyFormatNames.css,
dictionary,
outputReferences,
}) +
Expand Down
6 changes: 3 additions & 3 deletions docs/src/content/docs/reference/Utils/format-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ StyleDictionary.registerFormat({
header +
':root {\n' +
formattedVariables({
format: predefinedPropertyFormatNames.css,
format: propertyFormatNames.css,
dictionary,
outputReferences,
}) +
Expand Down Expand Up @@ -61,7 +61,7 @@ StyleDictionary.registerFormat({
const formatProperty = createPropertyFormatter({
outputReferences,
dictionary,
format: predefinedPropertyFormatNames.css,
format: propertyFormatNames.css,
});
return dictionary.allTokens.map(formatProperty).join('\n');
},
Expand Down Expand Up @@ -127,7 +127,7 @@ StyleDictionary.registerFormat({
name: 'myCustomFormat',
format: function ({ dictionary, options }) {
return formattedVariables({
format: predefinedPropertyFormatNames.less,
format: propertyFormatNames.less,
dictionary,
outputReferences: options.outputReferences,
});
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/version-4/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
},
Expand Down Expand Up @@ -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'
);
},
Expand Down
20 changes: 8 additions & 12 deletions lib/common/formatHelpers/createPropertyFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
* }
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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 {
Expand All @@ -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';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/common/formatHelpers/formattedVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const defaultFormatting = {
* name: 'myCustomFormat',
* format: function({ dictionary, options }) {
* return formattedVariables({
* format: predefinedPropertyFormatNames.less,
* format: propertyFormatNames.less,
* dictionary,
* outputReferences: options.outputReferences
* });
Expand Down
12 changes: 6 additions & 6 deletions lib/common/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
commentStyles,
fileHeaderCommentStyles,
fileFormats,
predefinedPropertyFormatNames,
propertyFormatNames,
} from '../enums/buildInEnums.js';

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ const formats = {
header +
`${selector} {\n` +
formattedVariables({
format: predefinedPropertyFormatNames.css,
format: propertyFormatNames.css,
dictionary,
outputReferences,
outputReferenceFallbacks,
Expand Down Expand Up @@ -180,7 +180,7 @@ const formats = {
'\n' +
header +
formattedVariables({
format: predefinedPropertyFormatNames.sass,
format: propertyFormatNames.sass,
dictionary,
outputReferences,
themeable,
Expand Down Expand Up @@ -216,7 +216,7 @@ const formats = {
return (
header +
formattedVariables({
format: predefinedPropertyFormatNames.sass,
format: propertyFormatNames.sass,
dictionary,
outputReferences,
themeable,
Expand Down Expand Up @@ -271,7 +271,7 @@ const formats = {
return (
header +
formattedVariables({
format: predefinedPropertyFormatNames.less,
format: propertyFormatNames.less,
dictionary,
outputReferences,
formatting,
Expand Down Expand Up @@ -326,7 +326,7 @@ const formats = {
return (
header +
formattedVariables({
format: predefinedPropertyFormatNames.stylus,
format: propertyFormatNames.stylus,
dictionary,
outputReferences,
formatting,
Expand Down
2 changes: 1 addition & 1 deletion lib/enums/buildInEnums.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const transformTypes = {
value: 'value',
};

export const predefinedPropertyFormatNames = {
export const propertyFormatNames = {
css: 'css',
sass: 'sass',
less: 'less',
Expand Down

0 comments on commit 7926485

Please sign in to comment.