diff --git a/packages/core/src/state.js b/packages/core/src/state.js index 0db86354..ac1dbffe 100644 --- a/packages/core/src/state.js +++ b/packages/core/src/state.js @@ -1,11 +1,16 @@ import path from 'path' import camelcase from 'camelcase' +const validCharacters = /[^a-zA-Z0-9_-]/g + function getComponentName(state) { if (!state.filePath) return 'SvgComponent' - const pascalCaseFileName = camelcase(path.parse(state.filePath).name, { - pascalCase: true, - }) + const pascalCaseFileName = camelcase( + path.parse(state.filePath).name.replace(validCharacters, ''), + { + pascalCase: true, + }, + ) return `Svg${pascalCaseFileName}` } diff --git a/packages/core/src/state.test.js b/packages/core/src/state.test.js index 4ced7d3d..26a304c3 100644 --- a/packages/core/src/state.test.js +++ b/packages/core/src/state.test.js @@ -20,6 +20,10 @@ describe('state', () => { filePath: '1_big_svg.svg', componentName: 'Svg1BigSvg', }) + expect(expandState({ filePath: 'a&b~c-d_e.svg' })).toEqual({ + filePath: 'a&b~c-d_e.svg', + componentName: 'SvgAbcDE', + }) }) }) })