Skip to content

Commit 4b4bd2c

Browse files
christopher-gibsongregberge
authored andcommitted
fix: invalid characters in component name (#332)
Fix #331
1 parent 28f5285 commit 4b4bd2c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/core/src/state.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import path from 'path'
22
import camelcase from 'camelcase'
33

4+
const validCharacters = /[^a-zA-Z0-9_-]/g
5+
46
function getComponentName(state) {
57
if (!state.filePath) return 'SvgComponent'
6-
const pascalCaseFileName = camelcase(path.parse(state.filePath).name, {
7-
pascalCase: true,
8-
})
8+
const pascalCaseFileName = camelcase(
9+
path.parse(state.filePath).name.replace(validCharacters, ''),
10+
{
11+
pascalCase: true,
12+
},
13+
)
914
return `Svg${pascalCaseFileName}`
1015
}
1116

packages/core/src/state.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ describe('state', () => {
2020
filePath: '1_big_svg.svg',
2121
componentName: 'Svg1BigSvg',
2222
})
23+
expect(expandState({ filePath: 'a&b~c-d_e.svg' })).toEqual({
24+
filePath: 'a&b~c-d_e.svg',
25+
componentName: 'SvgAbcDE',
26+
})
2327
})
2428
})
2529
})

0 commit comments

Comments
 (0)