From 8aa84ebf93dfd288112d0c674c47f5c3b4a9b63b Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Tue, 16 Aug 2016 14:52:15 -0400 Subject: [PATCH] Fix export so it works w/ `module.exports` & `window` Fixes Issue #13. This also fixes a similar issue where this library is used via browserify/webpack in the browser (or other environments where `window` is defined). Previously, `var S2 = require("s1-geometry").S2;`, would result in `window.S2` being defined but `S2` remaining undefined. This changes the behavior to prefer exporting via `module.exports`, if available, and falling back to `window` (or whatever `this` is in the module's imported scope -- which is usually `window`). Additionally, this keeps the library from polluting the global scope unnecessarily. --- src/s2geometry.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/s2geometry.js b/src/s2geometry.js index b13b09d..dee2264 100644 --- a/src/s2geometry.js +++ b/src/s2geometry.js @@ -22,10 +22,14 @@ // - i,j: they always use 30 bits, adjusting as needed. we use 0 to (1<