Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
What is the pattern common used for umdjs polyfills?

I am currently using umdjs(https://github.com/umdjs/umd) to create a nodejs modules.

I would know if their is a predefined pattern more specificly for umd pollyfills.This is because I am writting a polyfill for javascript using the umd pattern.


(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
}));
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!