Skip to content

Commit

Permalink
Merge e400033 into 9376210
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed May 31, 2015
2 parents 9376210 + e400033 commit 849850a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc
@@ -1,5 +1,6 @@
{
"env": {
"amd": true,
"browser": true,
"node": true
},
Expand Down
43 changes: 24 additions & 19 deletions src/simple_statistics.js
@@ -1,25 +1,29 @@
'use strict';
// # simple-statistics
//
// A simple, literate statistics system. The code below uses the
// [Javascript module pattern](http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth),
// eventually assigning `simple-statistics` to `ss` in browsers or the
// `exports` object for node.js
(function() {
var ss = {};

/* istanbul ignore else */
if (typeof module !== 'undefined') {
// Assign the `ss` object to exports, so that you can require
// it in [node.js](http://nodejs.org/)
module.exports = ss;
(function(f) {
if (typeof exports === 'object' && typeof module !== 'undefined'){
module.exports = f();
} else if (typeof define === 'function' && define.amd) {
define([], f);
} else {
// Otherwise, in a browser, we assign `ss` to the window object,
// so you can simply refer to it as `ss`.
// Coverage testing will always skip this line, so we exclude
// it from istanbul's vision.
this.ss = ss;
var g;
if (typeof window !== 'undefined') {
g = window;
} else if (typeof global !== 'undefined') {
g = global;
} else if (typeof self !== 'undefined'){
g = self;
} else {
g = this;
}
g.ss = f();
}
}(function() {
// # simple-statistics
//
// A simple, literate statistics system.

var ss = {};

// # [Linear Regression](http://en.wikipedia.org/wiki/Linear_regression)
//
Expand Down Expand Up @@ -1571,4 +1575,5 @@
ss.rms = root_mean_square;
ss.erf = error_function;

})(this);
return ss;
}));
21 changes: 21 additions & 0 deletions test/amd.test.js
@@ -0,0 +1,21 @@
'use strict';

var test = require('tape'),
vm = require('vm'),
fs = require('fs');

var src = fs.readFileSync('./src/simple_statistics.js', 'utf8');

test('uses window', function(t) {
var glob = {};
vm.runInNewContext(src, {window: glob});
t.ok(glob.ss);
t.end();
});

test('supports node', function(t) {
var module = { exports: {} };
vm.runInNewContext(src, { module: module, exports: module.exports });
t.ok(module.exports);
t.end();
});

0 comments on commit 849850a

Please sign in to comment.