File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1+ // CheckSnakeCase method checks the given string is in snake_case or not.
2+
3+ // Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)
4+
5+ /**
6+ * CheckSnakeCase method returns true if the string in snake_case, else return the false.
7+ * @param {String } varName the name of the variable to check.
8+ * @returns `Boolean` return true if the string is in snake_case, else return false.
9+ */
10+ const CheckSnakeCase = ( varName ) => {
11+ // firstly, check that input is a string or not.
12+ if ( typeof varName !== 'string' ) {
13+ return new TypeError ( 'Argument is not a string.' )
14+ }
15+
16+ const pat = / ( .* ?) _ ( [ a - z A - Z ] ) * /
17+ return pat . test ( varName )
18+ }
19+
20+ module . exports = CheckSnakeCase
You can’t perform that action at this time.
0 commit comments