Skip to content

Commit 8ec7c1a

Browse files
committed
Replace snake-case and camelcase with change-case
I noticed this PR still hanging gregberge#938, for this issue: gregberge#937 This should resolve the suggestions by replacing both these old packages with a new leaner one. Using version 4.x of change-case, as 5.x has done a rewrite to ESM-only. There is one behavior change in how pascalCase works (I haven't been able to find any alternative library that retains the behavior of the camelcase library wrt pascal-case after a leading number).
1 parent 180eb6d commit 8ec7c1a

File tree

6 files changed

+88
-38
lines changed

6 files changed

+88
-38
lines changed

packages/cli/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@
3535
"@svgr/plugin-jsx": "workspace:*",
3636
"@svgr/plugin-prettier": "workspace:*",
3737
"@svgr/plugin-svgo": "workspace:*",
38-
"camelcase": "^6.2.0",
3938
"chalk": "^4.1.2",
39+
"change-case": "^4.0.0",
4040
"commander": "^9.4.1",
4141
"dashify": "^2.0.0",
42-
"glob": "^8.0.3",
43-
"snake-case": "^3.0.4"
42+
"glob": "^8.0.3"
4443
},
4544
"devDependencies": {
4645
"@types/glob": "^8.1.0",

packages/cli/src/util.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('util', () => {
3939
expect(formatExportName('foo')).toBe('Foo')
4040
expect(formatExportName('foo-bar')).toBe('FooBar')
4141
expect(formatExportName('2foo')).toBe('Svg2foo')
42-
expect(formatExportName('2foo-bar')).toBe('Svg2FooBar')
42+
expect(formatExportName('2foo-bar')).toBe('Svg2fooBar')
4343
})
4444
})
4545
})

packages/cli/src/util.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import svgo from '@svgr/plugin-svgo'
66
import jsx from '@svgr/plugin-jsx'
77
import prettier from '@svgr/plugin-prettier'
88
// @ts-ignore
9-
import camelCase from 'camelcase'
10-
// @ts-ignore
119
import dashify from 'dashify'
12-
import { snakeCase } from 'snake-case'
10+
import { camelCase, pascalCase, snakeCase } from 'change-case'
1311

1412
export function transformFilename(
1513
filename: string,
@@ -21,7 +19,7 @@ export function transformFilename(
2119
case 'camel':
2220
return camelCase(filename)
2321
case 'pascal':
24-
return camelCase(filename, { pascalCase: true })
22+
return pascalCase(filename)
2523
case 'snake':
2624
return snakeCase(filename)
2725
default:
@@ -64,12 +62,12 @@ export const politeWrite = (data: string, silent?: boolean): void => {
6462

6563
export const formatExportName = (name: string): string => {
6664
if (/[-]/g.test(name) && /^\d/.test(name)) {
67-
return `Svg${camelCase(name, { pascalCase: true })}`
65+
return `Svg${pascalCase(name)}`
6866
}
6967

7068
if (/^\d/.test(name)) {
7169
return `Svg${name}`
7270
}
7371

74-
return camelCase(name, { pascalCase: true })
72+
return pascalCase(name)
7573
}

packages/core/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@
4040
"dependencies": {
4141
"@babel/core": "^7.21.3",
4242
"@svgr/babel-preset": "workspace:*",
43-
"camelcase": "^6.2.0",
44-
"cosmiconfig": "^8.3.6",
45-
"snake-case": "^3.0.4"
43+
"change-case": "^4.0.0",
44+
"cosmiconfig": "^8.3.6"
4645
},
4746
"devDependencies": {
4847
"svgo": "^3.0.2"

packages/core/src/state.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { parse as parsePath } from 'path'
2-
// @ts-ignore
3-
import camelCase from 'camelcase'
2+
import { pascalCase } from 'change-case'
43
import type { ConfigPlugin } from './plugins'
54

65
export interface State {
@@ -17,11 +16,8 @@ const VALID_CHAR_REGEX = /[^a-zA-Z0-9 _-]/g
1716

1817
const getComponentName = (filePath?: string): string => {
1918
if (!filePath) return 'SvgComponent'
20-
const pascalCaseFileName = camelCase(
19+
const pascalCaseFileName = pascalCase(
2120
parsePath(filePath).name.replace(VALID_CHAR_REGEX, ''),
22-
{
23-
pascalCase: true,
24-
},
2521
)
2622
return `Svg${pascalCaseFileName}`
2723
}

pnpm-lock.yaml

Lines changed: 77 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)