Skip to content

Instantly share code, notes, and snippets.

@wannyk
Created December 4, 2020 16:33
Show Gist options
  • Save wannyk/42c76bc3cf3431c21e41ff53706cace8 to your computer and use it in GitHub Desktop.
Save wannyk/42c76bc3cf3431c21e41ff53706cace8 to your computer and use it in GitHub Desktop.
encode utf8 string to euc-kr
const iconv = require('iconv-lite');
const assert = require('assert');
const urlencode = input => input.replace(/[^A-Za-z0-9-_.!~*'()]/g, c => c==' ' ? '+' : [...iconv.encode(c, "EUC-KR")].map(b => '%'+b.toString(16).toUpperCase()).join(''));
assert(urlencode('2013_16_방파제축조공사 추가절차 공사비 청구.pdf')=='2013_16_%B9%E6%C6%C4%C1%A6%C3%E0%C1%B6%B0%F8%BB%E7+%C3%DF%B0%A1%C0%FD%C2%F7+%B0%F8%BB%E7%BA%F1+%C3%BB%B1%B8.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment