umdname

adapt umd module types to alternative formats

Usage no npm install needed!

<script type="module">
  import umdname from 'https://cdn.skypack.dev/umdname';
</script>

README

umdname

(c)Bumblehead, 2016 MIT-license

overview

umdname changes the global name a umd module will define. For example, this umd boilerplate is found in mustache.js:

(function (root, factory) {
  if (typeof exports === "object" && exports) {
    factory(exports); // CommonJS
  } else {
    var mustache = {};
    factory(mustache);
    if (typeof define === "function" && define.amd) {
      define(mustache); // AMD
    } else {
      root.Mustache = mustache; // <script>
    }
  }
}(this, function (mustache) {
  /* ... mustache.js ... */
}));

umdname can return this content with Mustache changed to speedracer using umdname(mustachecontent, 'speedracer')

(function (root, factory) {
  if (typeof exports === 'object' && exports) {
    factory(exports);
  } else {
    var mustache = {};
    factory(mustache);
    if (typeof define === 'function' && define.amd) {
      define(mustache);
    } else {
      root.speedracer = mustache;
    }
  }
}(this, function (mustache) {
  /* ... mustache.js ... */
}));

The adaptation is useful for browser build tools that must define the name of a module to a predefined name referenced by other files.

It is assumed that content passed to umdname consists of a single valid umd-wrapped expression following the official umd boilerplate template. Currently no error-check is performed.


license

scrounge

(The MIT License)

Copyright (c) 2016 Bumblehead chris@bumblehead.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.