Skip to content

Commit

Permalink
fix: invalid characters in component name (#332)
Browse files Browse the repository at this point in the history
Fix #331
  • Loading branch information
christopher-gibson authored and gregberge committed Aug 6, 2019
1 parent 28f5285 commit 4b4bd2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/core/src/state.js
Original file line number Diff line number Diff line change
@@ -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}`
}

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
})
})
})

1 comment on commit 4b4bd2c

@vercel
Copy link

@vercel vercel bot commented on 4b4bd2c Aug 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully aliased the URL https://svgr-yfvdidavdi.now.sh to the following alias:

Please sign in to comment.