Skip to content

Commit b839bf6

Browse files
authored
chore: Merge pull request TheAlgorithms#661 from suryapratapsinghsuryavanshi/master
Added CheckFlatCase, CheckSnakeCase, CheckKebabCase methods.
2 parents 6d1733a + 6e2506b commit b839bf6

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

String/CheckFlatCase.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// CheckFlatCase method checks the given string is in flatcase or not.
2+
3+
// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)
4+
5+
/**
6+
* CheckFlatCase method returns true if the string in flatcase, 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 flatcase, else return false.
9+
*/
10+
const CheckFlatCase = (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]*$/
17+
return pat.test(varname)
18+
}
19+
20+
module.exports = CheckFlatCase

String/CheckKebabCase.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// CheckKebabCase method checks the given string is in kebab-case or not.
2+
3+
// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)
4+
5+
/**
6+
* CheckKebabCase method returns true if the string in kebab-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 kebab-case, else return false.
9+
*/
10+
const CheckKebabCase = (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 = /(\w+)-(\w)([\w-]*)/
17+
return pat.test(varName) && !varName.includes('_')
18+
}
19+
20+
module.exports = CheckKebabCase

String/CheckSnakeCase.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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-zA-Z])*/
17+
return pat.test(varName)
18+
}
19+
20+
module.exports = CheckSnakeCase

0 commit comments

Comments
 (0)