2021-12-06 21:26:14 +05:30
|
|
|
/**
|
|
|
|
|
* @function upper
|
|
|
|
|
* @description Will convert the entire string to uppercase letters.
|
2022-03-05 15:10:39 +06:00
|
|
|
* @param {String} str - The input string
|
2021-12-06 21:26:14 +05:30
|
|
|
* @return {String} Uppercase string
|
|
|
|
|
* @example upper("hello") => HELLO
|
|
|
|
|
* @example upper("He_llo") => HE_LLO
|
|
|
|
|
*/
|
|
|
|
|
const upper = (str) => {
|
|
|
|
|
if (typeof str !== 'string') {
|
2022-03-05 15:10:39 +06:00
|
|
|
throw new TypeError('Argument should be string')
|
2021-12-06 21:26:14 +05:30
|
|
|
}
|
|
|
|
|
|
2023-10-03 23:08:19 +02:00
|
|
|
return str.replace(/[a-z]/g, (char) =>
|
|
|
|
|
String.fromCharCode(char.charCodeAt() - 32)
|
2022-03-05 15:10:39 +06:00
|
|
|
)
|
2021-12-06 21:26:14 +05:30
|
|
|
}
|
|
|
|
|
|
2022-03-28 15:29:21 +06:00
|
|
|
export default upper
|