String.prototype.modifyStr = function(UpDown = 'Up', invertFirstLetter = false) {
let workingLine = String(this)
if (UpDown) {
workingLine = String(this).replace( /[a-zA-Z]|[а-яА-Я]/g, match => {
if (match == match.match(/[a-z]|[а-я]/)) {
return String.fromCharCode(match.charCodeAt(0) - ((match == 'ё') ? 80 : 32) )
}
else return match
})
} else if (!UpDown){
workingLine = String(this).replace( /[a-zA-Z]|[а-яА-Я]/g, match => {
if (match == match.match(/[A-Z]|[А-Я]/)) {
return String.fromCharCode(match.charCodeAt(0) + ((match == 'ё') ? 80 : 32) )
}
else return match
})
}
if (invertFirstLetter) {
let firstLetter = workingLine[0],
newLetter
if ( firstLetter == firstLetter.match( /[a-z]|[а-я]/g ) ) {
newLetter = String.fromCharCode(firstLetter.charCodeAt(0) - ((firstLetter == 'ё') ? 80 : 32) )
} else if ( firstLetter == firstLetter.match( /[A-Z]|[А-Я]/g ) ) {
newLetter = String.fromCharCode(firstLetter.charCodeAt(0) + ((firstLetter == 'ё') ? 80 : 32) )
}
return workingLine.replace(firstLetter, newLetter)
} else return workingLine
}
var obj = {
а: 'А',
б: 'Б',
в: 'В',
г: 'Г',
д: 'Д'
}
var letter = 'в';
console.log(obj[letter]);