-
-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for html attribute casing & add autofix
- Loading branch information
Showing
4 changed files
with
123 additions
and
99 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
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,42 @@ | ||
const assert = require('assert') | ||
|
||
function kebabCase (str) { | ||
return str | ||
.replace(/([a-z])([A-Z])/g, match => match[0] + '-' + match[1]) | ||
.replace(/[^a-zA-Z:]+/g, '-') | ||
.toLowerCase() | ||
} | ||
|
||
function camelCase (str) { | ||
return str | ||
.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => ( | ||
index === 0 ? letter.toLowerCase() : letter.toUpperCase()) | ||
) | ||
.replace(/[^a-zA-Z:]+/g, '') | ||
} | ||
|
||
function pascalCase (str) { | ||
return str | ||
.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => letter.toUpperCase()) | ||
.replace(/[^a-zA-Z:]+/g, '') | ||
} | ||
|
||
const convertersMap = { | ||
'kebab-case': kebabCase, | ||
'camelCase': camelCase, | ||
'PascalCase': pascalCase | ||
} | ||
|
||
module.exports = { | ||
allowedCaseOptions: [ | ||
'camelCase', | ||
'kebab-case', | ||
'PascalCase' | ||
], | ||
|
||
getConverter (name) { | ||
assert(typeof name === 'string') | ||
|
||
return convertersMap[name] || pascalCase | ||
} | ||
} |
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