Skip to content

Commit

Permalink
Added in AMD shim
Browse files Browse the repository at this point in the history
  • Loading branch information
beatgammit committed Jan 23, 2014
1 parent 8cc71e6 commit dade6d5
Show file tree
Hide file tree
Showing 20 changed files with 395 additions and 242 deletions.
14 changes: 11 additions & 3 deletions coordinator.js
@@ -1,5 +1,13 @@
(function () {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['./lib/convert'], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExports = factory();
}
}(this, function (convert) {
"use strict";

module.exports = require('./lib/convert');
}());
return convert;
}));
39 changes: 25 additions & 14 deletions lib/constants.js
@@ -1,4 +1,13 @@
(function () {
// if the module has no dependencies, the above pattern can be simplified to
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExports = factory();
}
}(this, function () {
"use strict";

var DEG_2_RAD = Math.PI / 180,
Expand Down Expand Up @@ -30,16 +39,18 @@

ECC_PRIME_SQUARED = ECC_SQUARED / (1 - ECC_SQUARED);

module.exports.DEG_2_RAD = DEG_2_RAD;
module.exports.RAD_2_DEG = RAD_2_DEG;
module.exports.EQUATORIAL_RADIUS = EQUATORIAL_RADIUS;
module.exports.ECC_SQUARED = ECC_SQUARED;
module.exports.ECC_PRIME_SQUARED = ECC_PRIME_SQUARED;
module.exports.EASTING_OFFSET = EASTING_OFFSET;
module.exports.NORTHING_OFFSET = NORTHING_OFFSET;
module.exports.GRIDSQUARE_SET_COL_SIZE = GRIDSQUARE_SET_COL_SIZE;
module.exports.GRIDSQUARE_SET_ROW_SIZE = GRIDSQUARE_SET_ROW_SIZE;
module.exports.BLOCK_SIZE = BLOCK_SIZE;
module.exports.E1 = E1;
module.exports.k0 = k0;
}());
return {
DEG_2_RAD: DEG_2_RAD,
RAD_2_DEG: RAD_2_DEG,
EQUATORIAL_RADIUS: EQUATORIAL_RADIUS,
ECC_SQUARED: ECC_SQUARED,
ECC_PRIME_SQUARED: ECC_PRIME_SQUARED,
EASTING_OFFSET: EASTING_OFFSET,
NORTHING_OFFSET: NORTHING_OFFSET,
GRIDSQUARE_SET_COL_SIZE: GRIDSQUARE_SET_COL_SIZE,
GRIDSQUARE_SET_ROW_SIZE: GRIDSQUARE_SET_ROW_SIZE,
BLOCK_SIZE: BLOCK_SIZE,
E1: E1,
k0: k0,
};
}));
24 changes: 16 additions & 8 deletions lib/convert.js
@@ -1,11 +1,19 @@
(function () {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['./latlong', './usng', './utm', './mgrs'], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExports = factory();
}
}(this, function (latlong, usng, utm, mgrs) {
"use strict";

var converters = {
'latlong': require('./latlong'),
'usng': require('./usng'),
'utm': require('./utm'),
'mgrs': require('./mgrs')
'latlong': latlong,
'usng': usng,
'utm': utm,
'mgrs': mgrs
};

function getConverter(inputType, outType) {
Expand All @@ -24,6 +32,6 @@
return converters[inputType].getConverter(outType);
}

module.exports = getConverter;
module.exports.converters = converters;
}());
getConverter.converters = converters;
return getConverter;
}));
39 changes: 23 additions & 16 deletions lib/latlong.js
@@ -1,12 +1,18 @@
(function () {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['./constants', './latlong/decimalToDegMinSec', './latlong/degMinSecToDecimal', './latlong/latlongToUtm', './latlong/translate', './utm'], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExports = factory();
}
}(this, function (CONSTANTS, decimalToDegMinSec, degMinSecToDecimal, latLongToUtm, translate, utm) {
"use strict";

var CONSTANTS = require('./constants'),
decimalToDegMinSec = require('./latlong/decimalToDegMinSec')(CONSTANTS),
degMinSecToDecimal = require('./latlong/degMinSecToDecimal')(CONSTANTS),
latLongToUtm = require('./latlong/latlongToUtm')(CONSTANTS),
translate = require('./latlong/translate')(CONSTANTS),
utm = require('./utm');
decimalToDegMinSec = decimalToDegMinSec(CONSTANTS);
degMinSecToDecimal = degMinSecToDecimal(CONSTANTS);
latLongToUtm = latLongToUtm(CONSTANTS);
translate = translate(CONSTANTS);

/*
* Convenience function that basically just:
Expand Down Expand Up @@ -85,12 +91,13 @@
return fn;
}

module.exports.toDecimal = degMinSecToDecimal;
module.exports.toDegMinSec = decimalToDegMinSec;
module.exports.toUsng = latLongToUsng;
module.exports.toUtm = latLongToUtm;
module.exports.toMgrs = latLongToMgrs;
module.exports.getConverter = getConverter;

module.exports.translate = translate;
}());
return {
toDecimal: degMinSecToDecimal,
toDegMinSec: decimalToDegMinSec,
toUsng: latLongToUsng,
toUtm: latLongToUtm,
toMgrs: latLongToMgrs,
getConverter: getConverter,
translate: translate,
};
}));
14 changes: 11 additions & 3 deletions lib/latlong/decimalToDegMinSec.js
@@ -1,4 +1,12 @@
(function () {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExports = factory();
}
}(this, function () {
"use strict";

/*
Expand Down Expand Up @@ -102,7 +110,7 @@
return ret;
}

module.exports = function () {
return function () {
return decimalToDegMinSec;
};
}());
}));
16 changes: 11 additions & 5 deletions lib/latlong/degMinSecToDecimal.js
@@ -1,8 +1,14 @@
(function () {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['./helpers'], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExports = factory();
}
}(this, function (helpers) {
"use strict";

var helpers = require('./helpers');

/*
* Converts degrees, minutes, seconds to decimal degrees.
*
Expand Down Expand Up @@ -53,9 +59,9 @@
return ret;
}

module.exports = function (constants) {
return function (constants) {
helpers = helpers(constants);

return degMinSecToDecimal;
};
}());
}));
120 changes: 64 additions & 56 deletions lib/latlong/helpers.js
@@ -1,5 +1,13 @@
/*jshint node:true */
(function () {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExports = factory();
}
}(this, function () {
"use strict";

var CONSTANTS = {};
Expand All @@ -20,33 +28,33 @@
zoneNum = zoneNum % 6;

switch (zoneNum) {
case 0:
tReturn = 6;
break;
case 0:
tReturn = 6;
break;

case 1:
tReturn = 1;
break;
case 1:
tReturn = 1;
break;

case 2:
tReturn = 2;
break;
case 2:
tReturn = 2;
break;

case 3:
tReturn = 3;
break;
case 3:
tReturn = 3;
break;

case 4:
tReturn = 4;
break;
case 4:
tReturn = 4;
break;

case 5:
tReturn = 5;
break;
case 5:
tReturn = 5;
break;

default:
tReturn = -1;
break;
default:
tReturn = -1;
break;
}

return tReturn;
Expand Down Expand Up @@ -79,38 +87,38 @@
}

switch (set) {
case 1:
l1 = "ABCDEFGH"; // column ids
l2 = "ABCDEFGHJKLMNPQRSTUV"; // row ids
break;

case 2:
l1 = "JKLMNPQR";
l2 = "FGHJKLMNPQRSTUVABCDE";
break;

case 3:
l1 = "STUVWXYZ";
l2 = "ABCDEFGHJKLMNPQRSTUV";
break;

case 4:
l1 = "ABCDEFGH";
l2 = "FGHJKLMNPQRSTUVABCDE";
break;

case 5:
l1 = "JKLMNPQR";
l2 = "ABCDEFGHJKLMNPQRSTUV";
break;

case 6:
l1 = "STUVWXYZ";
l2 = "FGHJKLMNPQRSTUVABCDE";
break;

default:
throw "Unrecognized set passed to lettersHelper";
case 1:
l1 = "ABCDEFGH"; // column ids
l2 = "ABCDEFGHJKLMNPQRSTUV"; // row ids
break;

case 2:
l1 = "JKLMNPQR";
l2 = "FGHJKLMNPQRSTUVABCDE";
break;

case 3:
l1 = "STUVWXYZ";
l2 = "ABCDEFGHJKLMNPQRSTUV";
break;

case 4:
l1 = "ABCDEFGH";
l2 = "FGHJKLMNPQRSTUVABCDE";
break;

case 5:
l1 = "JKLMNPQR";
l2 = "ABCDEFGHJKLMNPQRSTUV";
break;

case 6:
l1 = "STUVWXYZ";
l2 = "FGHJKLMNPQRSTUVABCDE";
break;

default:
throw "Unrecognized set passed to lettersHelper";
}

return l1.charAt(col) + l2.charAt(row);
Expand Down Expand Up @@ -328,7 +336,7 @@
return zoneNumber;
}

module.exports = function (constants) {
return function (constants) {
// set global functions
CONSTANTS = constants;

Expand All @@ -340,4 +348,4 @@
findGridLetters: findGridLetters
};
};
}());
}));
17 changes: 12 additions & 5 deletions lib/latlong/latlongToUtm.js
@@ -1,8 +1,15 @@
(function () {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['./helpers'], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExports = factory();
}
}(this, function (helpers) {
"use strict";

var CONSTANTS = {},
helpers = require('./helpers');
var CONSTANTS = {};

/*
* Converts latitude and longitude to UTM.
Expand Down Expand Up @@ -94,11 +101,11 @@
return utmcoords;
}

module.exports = function (constants) {
return function (constants) {
CONSTANTS = constants;

helpers = helpers(constants);

return latLongToUtm;
};
}());
}));

0 comments on commit dade6d5

Please sign in to comment.