-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kk/naming fix #293
Kk/naming fix #293
Conversation
The enforced camel casing breaks existing standard names like `ERC20.sol` and make the typings look like `Erc20.d.ts`, which adds complexity and confusion and requires unnecessary work to use typechain@2.0.
Don't enforce camel case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few propositions to choose from to simplify the transformations :D
const t2 = t1.replace(/^\d+/, '') // removes leading digits | ||
const result = upperFirst(camelCase(t2)) | ||
const transformations: ((s: string) => string)[] = [ | ||
(s) => s.split(' ').join('-'), // spaces to - so later we can automatically convert them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it prettier with a replace? 😃 also takes care of sequences of multiple and different whitespace chars
(s) => s.split(' ').join('-'), // spaces to - so later we can automatically convert them | |
(s) => s.replace(/\s+/g, '-'), // spaces to - so later we can automatically convert them |
(s) => s.split(' ').join('-'), // spaces to - so later we can automatically convert them | ||
(s) => s.replace(/^\d+/, ''), // removes leading digits | ||
(s) => deleteCharacterAndCaptializeNextCharacter(s, '-'), | ||
(s) => deleteCharacterAndCaptializeNextCharacter(s, '_'), | ||
(s) => deleteCharacterAndCaptializeNextCharacter(s, '.'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another idea: replace all non-word char sequences with a single '-' in one go, so you don't have to repeat the bottom lines:
(s) => s.split(' ').join('-'), // spaces to - so later we can automatically convert them | |
(s) => s.replace(/^\d+/, ''), // removes leading digits | |
(s) => deleteCharacterAndCaptializeNextCharacter(s, '-'), | |
(s) => deleteCharacterAndCaptializeNextCharacter(s, '_'), | |
(s) => deleteCharacterAndCaptializeNextCharacter(s, '.'), | |
(s) => s.replace(/\W+/g, '-'), // replace non-word character sequences with a single '-' | |
(s) => s.replace(/^\d+/, ''), // removes leading digits | |
(s) => deleteCharacterAndCaptializeNextCharacter(s, '-'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and yet another option without the need for a helper function :D
(s) => s.split(' ').join('-'), // spaces to - so later we can automatically convert them | |
(s) => s.replace(/^\d+/, ''), // removes leading digits | |
(s) => deleteCharacterAndCaptializeNextCharacter(s, '-'), | |
(s) => deleteCharacterAndCaptializeNextCharacter(s, '_'), | |
(s) => deleteCharacterAndCaptializeNextCharacter(s, '.'), | |
(s) => s.replace(/^\d+/, ''), // remove leading digits | |
(s) => s.replace(/\W+/g, '-'), // replace non-word character sequences with a single '-' | |
(s) => s.replace(/-[a-z]/g, match => match.substr(-1).toUpperCase()), // delete '-' and capitalize the letter after them | |
(s) => s.replace(/-/g, ''), // remove remaining minuses |
No description provided.