Skip to content

Commit abc3d3c

Browse files
authored
Merge pull request #58 from crswll/criswell/special-chars-in-names
2 parents 09dc4aa + bbe68a4 commit abc3d3c

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tailwindcss-theme-swapper",
3-
"version": "0.11.5",
3+
"version": "0.12.0",
44
"main": "src/index.js",
55
"license": "MIT",
66
"peerDependencies": {

src/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ function flatten (
4545
}
4646

4747
function getTailwindKeyName (keys) {
48-
return keys.filter(key => key.toLowerCase() !== 'default').map(kebabCase).join('-')
48+
return keys
49+
.filter(key => key.toLowerCase() !== 'default')
50+
.map(kebabCase)
51+
.map(key => key.replace(/[^a-z0-9\-]/gi, '_'))
52+
.join('-')
4953
}
5054

5155
function toCustomPropertyValue (keys, value) {

test/index.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const defaultTheme = {
1919
},
2020
spacing: {
2121
'fart': '69px',
22+
'5.5': '550px',
2223
},
2324
borderRadius: {
2425
default: '5px',
@@ -104,6 +105,7 @@ postcss(tailwindcss({
104105
--colors-primary: #f00;
105106
--colors-primary-darker: #400;
106107
--spacing-fart: 69px;
108+
--spacing-5_5: 550px;
107109
--border-radius: 5px;
108110
--font-family-sans: Font A, Font B, Font C;
109111
--font-size-sm: 12px;

test/utils.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ describe('getThemeAsCustomProps', () => {
8787
ringColor: { test: '#444' },
8888
fontSize: { base: '16px' },
8989
borderRadius: { default: '5px' },
90-
fontFamily: { foo: ['a', 'b', '"C 4"'] },
90+
spacing: {
91+
5: '500px',
92+
5.5: '550px',
93+
},
94+
fontFamily: {
95+
foo: ['a', 'b', '"C 4"'],
96+
},
9197
})
9298

9399
expect(result).toEqual({
@@ -100,6 +106,8 @@ describe('getThemeAsCustomProps', () => {
100106
'--ring-color-test': '#444',
101107
'--font-size-base': '16px',
102108
'--border-radius': '5px',
109+
'--spacing-5': '500px',
110+
'--spacing-5_5': '550px',
103111
'--font-family-foo': 'a, b, "C 4"',
104112
})
105113
})
@@ -117,6 +125,10 @@ describe('getThemeAsCustomProps', () => {
117125
fontSize: {
118126
base: '1rem',
119127
},
128+
spacing: {
129+
5: '500px',
130+
5.5: '550px',
131+
},
120132
})
121133

122134
expect(result).toEqual({
@@ -130,6 +142,10 @@ describe('getThemeAsCustomProps', () => {
130142
fontSize: {
131143
base: 'var(--font-size-base)',
132144
},
145+
spacing: {
146+
5: 'var(--spacing-5)',
147+
5.5: 'var(--spacing-5_5)',
148+
}
133149
})
134150
})
135151
})

0 commit comments

Comments
 (0)