Guest User

Untitled

a guest
Jun 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. const getAltLayout = (string: string): string => {
  2. if (getAltLayoutCache[string]) {
  3. return getAltLayoutCache[string];
  4. }
  5.  
  6. const eng = ' `qwertyuiop[]asdfghjkl;\'zxcvbnm,./~QWERTYUIOP{}ASDFGHJKLZXCVBNM<>?'.split('');
  7. const rus = ' ёйцукенгшщзхъфывапролджэячсмитьбю.ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЯЧСМИТЬБЮ,'.split('');
  8. const map: AnyObject = {};
  9. let result = '';
  10.  
  11. if (/[a-zA-Z]+/.test(string)) {
  12. eng.map((engChar, index) => {
  13. map[engChar] = rus[index];
  14. });
  15. }
  16. else {
  17. rus.map((rusChar, index) => {
  18. map[rusChar] = eng[index];
  19. });
  20. }
  21.  
  22. for (let i = 0, max = string.length; i < max; i++) {
  23. result += map[string[i]];
  24. }
  25.  
  26. if (result) {
  27. getAltLayoutCache[string] = result;
  28. }
  29.  
  30. return result;
  31. };
Add Comment
Please, Sign In to add comment