Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getAltLayout = (string: string): string => {
- if (getAltLayoutCache[string]) {
- return getAltLayoutCache[string];
- }
- const eng = ' `qwertyuiop[]asdfghjkl;\'zxcvbnm,./~QWERTYUIOP{}ASDFGHJKLZXCVBNM<>?'.split('');
- const rus = ' ёйцукенгшщзхъфывапролджэячсмитьбю.ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЯЧСМИТЬБЮ,'.split('');
- const map: AnyObject = {};
- let result = '';
- if (/[a-zA-Z]+/.test(string)) {
- eng.map((engChar, index) => {
- map[engChar] = rus[index];
- });
- }
- else {
- rus.map((rusChar, index) => {
- map[rusChar] = eng[index];
- });
- }
- for (let i = 0, max = string.length; i < max; i++) {
- result += map[string[i]];
- }
- if (result) {
- getAltLayoutCache[string] = result;
- }
- return result;
- };
Add Comment
Please, Sign In to add comment