-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rakesh-paulraj
committed
Jan 16, 2024
1 parent
ac2681c
commit 813e566
Showing
2 changed files
with
117 additions
and
79 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,38 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"overrides": [ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"files": [ | ||
".eslintrc.{js,cjs}" | ||
], | ||
"parserOptions": { | ||
"sourceType": "script" | ||
} | ||
} | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"indent": ["error", 4], | ||
"linebreak-style": ["error", "windows"], | ||
"quotes": ["error", "double"], | ||
"semi": ["error", "always"] | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,79 +1,79 @@ | ||
export const isIdentical = (strOne: string, strTwo: string) => { | ||
strOne = strOne.trim(); | ||
strTwo = strTwo.trim(); | ||
if (strOne.toLowerCase() === strTwo.toLowerCase()) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export const isAlpha = (str: string) => { | ||
if (/^[a-zA-Z]+$/.test(str)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export const isEmpty = (value: string) => { | ||
value = value.trim(); | ||
return value.length == 0; | ||
}; | ||
|
||
export const isAlphaNumeric = (str: string) => { | ||
if (/^[a-zA-Z0-9]+$/.test(str)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export const isValidEmail = (email: string) => { | ||
// regular expression to match valid email addresses | ||
var pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
// match the pattern against the email string | ||
return pattern.test(email); | ||
}; | ||
|
||
export const countWords = (str: string) => { | ||
// split the string into an array of words | ||
var words = str.split(" "); | ||
// return the length of the array | ||
return words.length; | ||
}; | ||
|
||
export const isAvailable = (str: string, word: string) => { | ||
if (str.indexOf(word) !== -1) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export const countOccurrences = (str: string, word: string) => { | ||
// split the string into an array of words | ||
var words = str.split(" "); | ||
// initialize a counter variable | ||
var count = 0; | ||
// loop through the array of words | ||
for (var i = 0; i < words.length; i++) { | ||
// if the current word matches the target word, increment the counter | ||
if (words[i] === word) { | ||
count++; | ||
} | ||
} | ||
// return the count | ||
return count; | ||
}; | ||
|
||
export const isPasswordStrong = (password: string) => { | ||
// define a regular expression that matches a strong password | ||
var strongRegex = | ||
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/; | ||
// test the password against the regular expression | ||
return strongRegex.test(password); | ||
}; | ||
|
||
export const isURL = (str: string) => { | ||
// define a regular expression that matches a URL format | ||
var urlRegex = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/; | ||
// test the string against the regular expression | ||
return urlRegex.test(str); | ||
}; | ||
export const isIdentical = (strOne: string, strTwo: string) => { | ||
strOne = strOne.trim(); | ||
strTwo = strTwo.trim(); | ||
if (strOne.toLowerCase() === strTwo.toLowerCase()) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export const isAlpha = (str: string) => { | ||
if (/^[a-zA-Z]+$/.test(str)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export const isEmpty = (value: string) => { | ||
value = value.trim(); | ||
return value.length == 0; | ||
}; | ||
|
||
export const isAlphaNumeric = (str: string) => { | ||
if (/^[a-zA-Z0-9]+$/.test(str)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export const isValidEmail = (email: string) => { | ||
// regular expression to match valid email addresses | ||
const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
// match the pattern against the email string | ||
return pattern.test(email); | ||
}; | ||
|
||
export const countWords = (str: string) => { | ||
// split the string into an array of words | ||
const words = str.split(" "); | ||
// return the length of the array | ||
return words.length; | ||
}; | ||
|
||
export const isAvailable = (str: string, word: string) => { | ||
if (str.indexOf(word) !== -1) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export const countOccurrences = (str: string, word: string) => { | ||
// split the string into an array of words | ||
const words = str.split(" "); | ||
// initialize a counter variable | ||
let count = 0; | ||
// loop through the array of words | ||
for (let i = 0; i < words.length; i++) { | ||
// if the current word matches the target word, increment the counter | ||
if (words[i] === word) { | ||
count++; | ||
} | ||
} | ||
// return the count | ||
return count; | ||
}; | ||
|
||
export const isPasswordStrong = (password: string) => { | ||
// define a regular expression that matches a strong password | ||
const strongRegex = | ||
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/; | ||
// test the password against the regular expression | ||
return strongRegex.test(password); | ||
}; | ||
|
||
export const isURL = (str: string) => { | ||
// define a regular expression that matches a URL format | ||
const urlRegex = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/; | ||
// test the string against the regular expression | ||
return urlRegex.test(str); | ||
}; |