Skip to content

Commit

Permalink
AMD and CommonJs support - Universal Module Definition pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
duzun committed Oct 22, 2015
1 parent 71044f7 commit 4bd01a5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions naturalSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
* Natural Sort algorithm for Javascript - Version 0.8 - Released under MIT license
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
*/
;(function (name, global, undefined) {
var UNDEFINED = undefined + ''
, FUNCTION = 'function'
;
(
typeof define !== FUNCTION || !define.amd ? typeof module != UNDEFINED && module.exports
// CommonJS
? function (deps, factory) { module.exports = factory(); }
// Browser
: function (deps, factory) { global[name] = factory(); }
// AMD
: define
)
/*define*/([], function factory() {

function naturalSort (a, b) {
var re = /(^([+\-]?(?:\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[\da-fA-F]+$|\d+)/g,
sre = /^\s+|\s+$/g, // trim pre-post whitespace
Expand Down Expand Up @@ -47,3 +62,8 @@ function naturalSort (a, b) {
}
return 0;
}

return naturalSort;
});
}
('naturalSort', typeof self == 'undefined' ? typeof global == 'undefined' ? this : global : self));

0 comments on commit 4bd01a5

Please sign in to comment.