Skip to content

Commit e686888

Browse files
committed
AMD and CommonJs support - Universal Module Definition pattern
1 parent 7371332 commit e686888

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

naturalSort.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
* Natural Sort algorithm for Javascript - Version 0.8.1 - Released under MIT license
33
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
44
*/
5+
;(function (name, global, undefined) {
6+
var UNDEFINED = undefined + ''
7+
, FUNCTION = 'function'
8+
;
9+
(
10+
typeof define !== FUNCTION || !define.amd ? typeof module != UNDEFINED && module.exports
11+
// CommonJS
12+
? function (deps, factory) { module.exports = factory(); }
13+
// Browser
14+
: function (deps, factory) { global[name] = factory(); }
15+
// AMD
16+
: define
17+
)
18+
/*define*/([], function factory() {
19+
520
function naturalSort (a, b) {
621
var re = /(^([+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|^0x[\da-fA-F]+$|\d+)/g,
722
sre = /^\s+|\s+$/g, // trim pre-post whitespace
@@ -48,3 +63,8 @@ function naturalSort (a, b) {
4863
else if (oFxNcL > oFyNcL) { return 1; }
4964
}
5065
}
66+
67+
return naturalSort;
68+
});
69+
}
70+
('naturalSort', typeof self == 'undefined' ? typeof global == 'undefined' ? this : global : self));

0 commit comments

Comments
 (0)