This method decodes string that was encoded by PHP's urlencode
method using windows-1251
encoding (i.e.
php -r "echo urlencode(iconv('utf8', 'windows-1251', 'Что-то с чем-то'));"
)
Created
July 22, 2019 12:26
-
-
Save GendelfLugansk/da5636ac6ec3527ec5698c7df70e5ced to your computer and use it in GitHub Desktop.
JavaScript: decodeURIComponentWin1251
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
const decodeURIComponentWin1251 = encoded => { | |
const win1251toutf8 = { | |
'%E9': '%D0%B9', | |
'%e9': '%D0%B9', | |
'%C9': '%D0%99', | |
'%c9': '%D0%99', | |
'%F6': '%D1%86', | |
'%f6': '%D1%86', | |
'%D6': '%D0%A6', | |
'%d6': '%D0%A6', | |
'%F3': '%D1%83', | |
'%f3': '%D1%83', | |
'%D3': '%D0%A3', | |
'%d3': '%D0%A3', | |
'%EA': '%D0%BA', | |
'%ea': '%D0%BA', | |
'%CA': '%D0%9A', | |
'%ca': '%D0%9A', | |
'%E5': '%D0%B5', | |
'%e5': '%D0%B5', | |
'%C5': '%D0%95', | |
'%c5': '%D0%95', | |
'%ED': '%D0%BD', | |
'%ed': '%D0%BD', | |
'%CD': '%D0%9D', | |
'%cd': '%D0%9D', | |
'%E3': '%D0%B3', | |
'%e3': '%D0%B3', | |
'%C3': '%D0%93', | |
'%c3': '%D0%93', | |
'%F8': '%D1%88', | |
'%f8': '%D1%88', | |
'%D8': '%D0%A8', | |
'%d8': '%D0%A8', | |
'%F9': '%D1%89', | |
'%f9': '%D1%89', | |
'%D9': '%D0%A9', | |
'%d9': '%D0%A9', | |
'%E7': '%D0%B7', | |
'%e7': '%D0%B7', | |
'%C7': '%D0%97', | |
'%c7': '%D0%97', | |
'%F5': '%D1%85', | |
'%f5': '%D1%85', | |
'%D5': '%D0%A5', | |
'%d5': '%D0%A5', | |
'%FA': '%D1%8A', | |
'%fa': '%D1%8A', | |
'%DA': '%D0%AA', | |
'%da': '%D0%AA', | |
'%F4': '%D1%84', | |
'%f4': '%D1%84', | |
'%D4': '%D0%A4', | |
'%d4': '%D0%A4', | |
'%FB': '%D1%8B', | |
'%fb': '%D1%8B', | |
'%DB': '%D0%AB', | |
'%db': '%D0%AB', | |
'%E2': '%D0%B2', | |
'%e2': '%D0%B2', | |
'%C2': '%D0%92', | |
'%c2': '%D0%92', | |
'%E0': '%D0%B0', | |
'%e0': '%D0%B0', | |
'%C0': '%D0%90', | |
'%c0': '%D0%90', | |
'%EF': '%D0%BF', | |
'%ef': '%D0%BF', | |
'%CF': '%D0%9F', | |
'%cf': '%D0%9F', | |
'%F0': '%D1%80', | |
'%f0': '%D1%80', | |
'%D0': '%D0%A0', | |
'%d0': '%D0%A0', | |
'%EE': '%D0%BE', | |
'%ee': '%D0%BE', | |
'%CE': '%D0%9E', | |
'%ce': '%D0%9E', | |
'%EB': '%D0%BB', | |
'%eb': '%D0%BB', | |
'%CB': '%D0%9B', | |
'%cb': '%D0%9B', | |
'%E4': '%D0%B4', | |
'%e4': '%D0%B4', | |
'%C4': '%D0%94', | |
'%c4': '%D0%94', | |
'%E6': '%D0%B6', | |
'%e6': '%D0%B6', | |
'%C6': '%D0%96', | |
'%c6': '%D0%96', | |
'%FD': '%D1%8D', | |
'%fd': '%D1%8D', | |
'%DD': '%D0%AD', | |
'%dd': '%D0%AD', | |
'%FF': '%D1%8F', | |
'%ff': '%D1%8F', | |
'%DF': '%D0%AF', | |
'%df': '%D0%AF', | |
'%F7': '%D1%87', | |
'%f7': '%D1%87', | |
'%D7': '%D0%A7', | |
'%d7': '%D0%A7', | |
'%F1': '%D1%81', | |
'%f1': '%D1%81', | |
'%D1': '%D0%A1', | |
'%d1': '%D0%A1', | |
'%EC': '%D0%BC', | |
'%ec': '%D0%BC', | |
'%CC': '%D0%9C', | |
'%cc': '%D0%9C', | |
'%E8': '%D0%B8', | |
'%e8': '%D0%B8', | |
'%C8': '%D0%98', | |
'%c8': '%D0%98', | |
'%F2': '%D1%82', | |
'%f2': '%D1%82', | |
'%D2': '%D0%A2', | |
'%d2': '%D0%A2', | |
'%FC': '%D1%8C', | |
'%fc': '%D1%8C', | |
'%DC': '%D0%AC', | |
'%dc': '%D0%AC', | |
'%E1': '%D0%B1', | |
'%e1': '%D0%B1', | |
'%C1': '%D0%91', | |
'%c1': '%D0%91', | |
'%FE': '%D1%8E', | |
'%fe': '%D1%8E', | |
'%DE': '%D0%AE', | |
'%de': '%D0%AE', | |
'%B8': '%D1%91', | |
'%b8': '%D1%91', | |
'%A8': '%D0%81', | |
'%a8': '%D0%81', | |
'%B3': '%D1%96', | |
'%b3': '%D1%96', | |
'%B2': '%D0%86', | |
'%b2': '%D0%86', | |
'%BF': '%D1%97', | |
'%bf': '%D1%97', | |
'%AF': '%D0%87', | |
'%af': '%D0%87', | |
'%B4': '%D2%91', | |
'%b4': '%D2%91', | |
'%A5': '%D2%90', | |
'%a5': '%D2%90', | |
}; | |
return decodeURIComponent( | |
encoded.replace(/\+/g, '%20').replace(/%[\da-zA-Z]{2}/g, match => win1251toutf8[match] || match) | |
); | |
}; | |
export default decodeURIComponentWin1251; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment