mathiasbynens / punycode.js

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891.
https://mths.be/punycode
MIT License
1.59k stars 158 forks source link

Add UMD definitions #89

Open OSAGfar opened 5 years ago

OSAGfar commented 5 years ago

The code assumes that module is always available, which is not true (e.g. browser with requireJS). With the following UMD boilerplate it can be much friendlier to use in different environments.

The changes would be straightforward:

  1. Remove the module.exports = punycode; line at the very end

  2. Wrap remaining code like this:

    
    ;(function (root, factory) {
    
    if (typeof define === 'function' && define.amd) {
    define(factory);
    } else if (typeof exports === 'object') {
    module.exports = factory();
    } else {
    root.punycode = factory();
    }

}(this, function () {

return punycode; })); ```
FranklinYu commented 3 years ago

Any update? This would be very useful. I can make Pull Request to change scripts/prepublish.js with this template, if the maintainers are interested.

About what’s UMD, see the project homepage.