From 5645f2b23f091cc555be98ee91f37ef020c21f5b Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Sat, 19 Aug 2023 14:46:32 +0200 Subject: [PATCH 1/2] move separator to config --- src/lib/default-config.ts | 1 + src/lib/modifier-utils.ts | 2 +- src/lib/types.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index 6b2858f6..e8b357ff 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -92,6 +92,7 @@ export function getDefaultConfig() { return { cacheSize: 500, + separator: ':', theme: { colors: [isAny], spacing: [isLength], diff --git a/src/lib/modifier-utils.ts b/src/lib/modifier-utils.ts index dc7f62b6..2a807972 100644 --- a/src/lib/modifier-utils.ts +++ b/src/lib/modifier-utils.ts @@ -3,7 +3,7 @@ import { Config } from './types' export const IMPORTANT_MODIFIER = '!' export function createSplitModifiers(config: Config) { - const separator = config.separator || ':' + const separator = config.separator const isSeparatorSingleCharacter = separator.length === 1 const firstSeparatorCharacter = separator[0] const separatorLength = separator.length diff --git a/src/lib/types.ts b/src/lib/types.ts index 7b3d4e72..23cf4d5c 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -14,7 +14,7 @@ export interface Config { * Custom separator for modifiers in Tailwind classes * @see https://tailwindcss.com/docs/configuration#separator */ - separator?: string + separator: string /** * Theme scales used in classGroups. * The keys are the same as in the Tailwind config but the values are sometimes defined more broadly. From 1c41660ae3c313cfb3062fb3d6bf5f118174bfb0 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Sat, 19 Aug 2023 14:46:38 +0200 Subject: [PATCH 2/2] adjust tests --- tests/create-tailwind-merge.test.ts | 2 ++ tests/merge-configs.test.ts | 2 ++ tests/modifiers.test.ts | 1 + tests/public-api.test.ts | 3 +++ 4 files changed, 8 insertions(+) diff --git a/tests/create-tailwind-merge.test.ts b/tests/create-tailwind-merge.test.ts index 3007de07..594ec061 100644 --- a/tests/create-tailwind-merge.test.ts +++ b/tests/create-tailwind-merge.test.ts @@ -3,6 +3,7 @@ import { createTailwindMerge } from '../src' test('createTailwindMerge works with single config function', () => { const tailwindMerge = createTailwindMerge(() => ({ cacheSize: 20, + separator: ':', theme: {}, classGroups: { fooKey: [{ fooKey: ['bar', 'baz'] }], @@ -42,6 +43,7 @@ test('createTailwindMerge works with multiple config functions', () => { const tailwindMerge = createTailwindMerge( () => ({ cacheSize: 20, + separator: ':', theme: {}, classGroups: { fooKey: [{ fooKey: ['bar', 'baz'] }], diff --git a/tests/merge-configs.test.ts b/tests/merge-configs.test.ts index 36c02074..b544a7b2 100644 --- a/tests/merge-configs.test.ts +++ b/tests/merge-configs.test.ts @@ -5,6 +5,7 @@ test('mergeConfigs has correct behavior', () => { mergeConfigs( { cacheSize: 50, + separator: ':', theme: { hi: ['ho'], }, @@ -28,6 +29,7 @@ test('mergeConfigs has correct behavior', () => { ), ).toEqual({ cacheSize: 50, + separator: ':', theme: { hi: ['ho'], }, diff --git a/tests/modifiers.test.ts b/tests/modifiers.test.ts index 6088f2c5..18152566 100644 --- a/tests/modifiers.test.ts +++ b/tests/modifiers.test.ts @@ -17,6 +17,7 @@ test('conflicts across postfix modifiers', () => { const customTwMerge = createTailwindMerge(() => ({ cacheSize: 10, + separator: ':', theme: {}, classGroups: { foo: ['foo-1/2', 'foo-2/3'], diff --git a/tests/public-api.test.ts b/tests/public-api.test.ts index 61d2b689..49253129 100644 --- a/tests/public-api.test.ts +++ b/tests/public-api.test.ts @@ -84,6 +84,7 @@ test('createTailwindMerge() has correct inputs and outputs', () => { expect( createTailwindMerge(() => ({ cacheSize: 0, + separator: ':', theme: {}, classGroups: {}, conflictingClassGroups: {}, @@ -92,6 +93,7 @@ test('createTailwindMerge() has correct inputs and outputs', () => { const tailwindMerge = createTailwindMerge(() => ({ cacheSize: 20, + separator: ':', theme: {}, classGroups: { fooKey: [{ fooKey: ['bar', 'baz'] }], @@ -156,6 +158,7 @@ test('mergeConfigs has correct inputs and outputs', () => { mergeConfigs( { cacheSize: 50, + separator: ':', theme: {}, classGroups: { fooKey: [{ fooKey: ['one', 'two'] }],