I want to encode a string as per RFC 1738 in NodeJs app. This is required in Twitter API documentation . I found no package to achieve this. Has someone done this already? I wanted too register my webhook url to twitter app.
You can use the native javascript method encodeURIComponent .
To be compliant with the RFC you would need to handle these additional characters:
function rawurlencode (str) {
return encodeURIComponent(str)
.replace(/!/g, '%21')
.replace(/'/g, '%27')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
.replace(/\*/g, '%2A')
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.