-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Azat Serikov <[email protected]>
- Loading branch information
Showing
4 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'typechain': patch | ||
--- | ||
|
||
Escape dirs starting with digits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { camelCase } from 'lodash' | ||
|
||
/** | ||
* Converts valid directory name to valid variable name. Example: 0directory-name becomes _0DirectoryName | ||
*/ | ||
export function normalizeDirName(rawName: string): string { | ||
const transformations: ((s: string) => string)[] = [ | ||
(s) => camelCase(s), // convert to camelCase | ||
(s) => s.replace(/^\d/g, (match) => '_' + match), // prepend '_' if contains a leading number | ||
] | ||
|
||
return transformations.reduce((s, t) => t(s), rawName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { expect } from 'earljs' | ||
|
||
import { normalizeDirName } from '../../src/codegen/normalizeDirName' | ||
|
||
describe('dir name normalizer', () => { | ||
it('should work', () => { | ||
expect(normalizeDirName('dirname')).toEqual('dirname') | ||
expect(normalizeDirName('dir_name')).toEqual('dirName') | ||
expect(normalizeDirName('0.4.24')).toEqual('_0424') | ||
expect(normalizeDirName('0-4-24')).toEqual('_0424') | ||
expect(normalizeDirName('0424')).toEqual('_0424') | ||
expect(normalizeDirName('0dir-name.1')).toEqual('_0DirName1') | ||
}) | ||
}) |