(sourceUrl)
| 1 | const { base64Encode } = require('./base64Encode') |
| 2 | |
| 3 | function base64EncodeURL(sourceUrl) { |
| 4 | try { |
| 5 | sourceUrl = decodeURI(sourceUrl); |
| 6 | } catch (error) { |
| 7 | // ignore errors |
| 8 | } |
| 9 | sourceUrl = encodeURI(sourceUrl); |
| 10 | return base64Encode(sourceUrl) |
| 11 | .replace(/\+/g, '-') // Convert '+' to '-' |
| 12 | .replace(/\//g, '_') // Convert '/' to '_' |
| 13 | .replace(/=+$/, ''); // Remove ending '='; |
| 14 | } |
| 15 | |
| 16 | |
| 17 | module.exports.base64EncodeURL = base64EncodeURL; |
no test coverage detected