Skip to content
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

Merged
merged 7 commits into from
Nov 1, 2020
Merged

Kk/naming fix #293

merged 7 commits into from
Nov 1, 2020

Conversation

krzkaczor
Copy link
Member

No description provided.

PhABC and others added 4 commits October 28, 2020 18:28
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
Copy link
Contributor

@quezak quezak left a 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
Copy link
Contributor

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

Suggested change
(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

Comment on lines 8 to 12
(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, '.'),
Copy link
Contributor

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:

Suggested change
(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, '-'),

Copy link
Contributor

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

Suggested change
(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

@krzkaczor krzkaczor merged commit 922f684 into master Nov 1, 2020
@krzkaczor krzkaczor deleted the kk/naming-fix branch November 1, 2020 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants