| 1 | # umd |
| 2 | <img src="http://i.imgur.com/ypw29XY.png" align="right"/> |
| 3 | |
| 4 | Universal Module Definition for use in automated build systems |
| 5 | |
| 6 | - simple synchronous wrapping of a string |
| 7 | - `return` style module support |
| 8 | - CommonJS support |
| 9 | - prevents internal UMDs from conflicting |
| 10 | |
| 11 | [](https://travis-ci.org/ForbesLindesay/umd) |
| 12 | [](https://david-dm.org/ForbesLindesay/umd) |
| 13 | [](https://www.npmjs.com/package/umd) |
| 14 | |
| 15 | ## Source Format |
| 16 | |
| 17 | In order for the UMD wrapper to work the source code for your module should `return` the export, e.g. |
| 18 | |
| 19 | ```javascript |
| 20 | function method() { |
| 21 | //code |
| 22 | } |
| 23 | method.helper = function () { |
| 24 | //code |
| 25 | } |
| 26 | return method; |
| 27 | ``` |
| 28 | |
| 29 | For examples, see the examples directory. The CommonJS module format is also supported by passing true as the second argument to methods. |
| 30 | |
| 31 | ## API |
| 32 | |
| 33 | options: |
| 34 | |
| 35 | - `commonJS` (default: `false`) - If commonJS is `true` then it will accept CommonJS source instead of source code which `return`s the module. |
| 36 | |
| 37 | ### umd(name, source, [options]) |
| 38 | |
| 39 | The `name` should the the name of the module. Use a string like name, all lower case with hyphens instead of spaces. |
| 40 | |
| 41 | If `source` should be a string, that is wrapped in umd and returned as a string. |
| 42 | |
| 43 | ### umd.prelude(module, [options]) |
| 44 | |
| 45 | return the text which will be inserted before a module. |
| 46 | |
| 47 | ### umd.postlude(module, [options]) |
| 48 | |
| 49 | return the text which will be inserted after a module. |
| 50 | |
| 51 | ## Command Line |
| 52 | |
| 53 | ``` |
| 54 | Usage: umd <name> <source> <destination> [options] |
| 55 | |
| 56 | Pipe Usage: umd <name> [options] < source > destination |
| 57 | |
| 58 | Options: |
| 59 | |
| 60 | -h --help Display usage information |
| 61 | -c --commonJS Use CommonJS module format |
| 62 | ``` |
| 63 | |
| 64 | You can easilly pipe unix commands together like: |
| 65 | |
| 66 | ```js |
| 67 | cat my-module.js | umd my-module | uglify-js > my-module.umd.min.js |
| 68 | ``` |
| 69 | |
| 70 | ## Name Casing and Characters |
| 71 | |
| 72 | The `name` passed to `umd` will be converted to camel case (`my-library` becomes `myLibrary`) and may only contain: |
| 73 | |
| 74 | * alphanumeric characters |
| 75 | * $ |
| 76 | * _ |
| 77 | |
| 78 | The name may not begin with a number. Invalid characters will be stripped. |
| 79 | |
| 80 | ## License |
| 81 | |
| 82 | MIT |