Actualmente estoy usando umdjs ( https://github.com/umdjs/umd ) para crear módulos nodejs.
Sabría si hay un patrón predefinido más específicamente para umd pollyfills. Esto se debe a que estoy escribiendo un polyfill para javascript usando el patrón umd.
(function (root, factory) { 'use strict'; if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define([], function () { return (root = factory()); }); } else if (typeof exports === 'object') { // Node. Does not work with strict CommonJS, but // only CommonJS-like enviroments that support module.exports, // like Node. module.exports = factory(); } else { // Browser globals return root.countByRadix = factory(); } }(this, function () { var that = this; // UMD Definition above, do not remove this line let hasOwnProperty = Object.prototype.hasOwnProperty; /** * American Standard for Communication * and Information Interchange * @param str * @returns */ function toAscii(str) { return [...str] .map(c => c.charCodeAt(0)) } function toRadixOf(str,base) { return toAscii(str).map(c => c.toString(base)); } if (!(hasOwnProperty.call(String.prototype, "countByRadix"))){ Object.defineProperty(String.prototype, "countByRadix", { value: function (radix) { return Number( toRadixOf(this, radix) .map(r => String(r).length) .reduce((a, b) => a + b)) } }) } return that }));