* A simple `Array#map`-like wrapper to work with domain name strings or email * addresses. * @private * @param {String} domain The domain name or email address. * @param {Function} callback The function that gets called for every * character. * @returns {String} A new string of characters retu
(domain, callback)
| 82 | * function. |
| 83 | */ |
| 84 | function mapDomain(domain, callback) { |
| 85 | const parts = domain.split('@'); |
| 86 | let result = ''; |
| 87 | if (parts.length > 1) { |
| 88 | // In email addresses, only the domain name should be punycoded. Leave |
| 89 | // the local part (i.e. everything up to `@`) intact. |
| 90 | result = parts[0] + '@'; |
| 91 | domain = parts[1]; |
| 92 | } |
| 93 | // Avoid `split(regex)` for IE8 compatibility. See #17. |
| 94 | domain = domain.replace(regexSeparators, '\x2E'); |
| 95 | const labels = domain.split('.'); |
| 96 | const encoded = map(labels, callback).join('.'); |
| 97 | return result + encoded; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Creates an array containing the numeric code points of each Unicode |