-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap quotes around reserved keywords e.g. "user"
- Loading branch information
1 parent
62a613c
commit 6366dc0
Showing
14 changed files
with
290 additions
and
56 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
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
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,16 @@ | ||
import { reservedKeywords } from './reserved-keywords'; | ||
|
||
export const wrapQuotes = (string: string) => { | ||
const isCamelCase = string.match(/[A-Z]/); | ||
const isReserved = reservedKeywords.has(string); | ||
const shouldWrap = isReserved || isCamelCase; | ||
|
||
return shouldWrap ? `"${string}"` : string; | ||
}; | ||
|
||
export const toSnakeCase = (string: string) => | ||
string | ||
.replace(/\W+/g, ' ') | ||
.split(/ |\B(?=[A-Z])/) | ||
.map((word) => word.toLowerCase()) | ||
.join('_'); |
Oops, something went wrong.