Skip to content

Commit

Permalink
Fix dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kazlauskis committed Jun 5, 2017
1 parent 670defe commit 1408c01
Show file tree
Hide file tree
Showing 17 changed files with 1,352 additions and 1,225 deletions.
2,357 changes: 1,227 additions & 1,130 deletions dist/BIGU.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/BIGU.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"circular-dependency-plugin": "^2.0.0",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.16.1",
"webpack-merge": "^0.14.1",
Expand Down
1 change: 1 addition & 0 deletions src/CILatLng.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import OSCIRef from 'OSCIRef';
import OSGB36LatLng from 'OSGB36LatLng';
import { deg2rad } from 'constants';

/**
* represents lat lng as INT24 (CI grid projection)
Expand Down
80 changes: 10 additions & 70 deletions src/GridRefParser/GridRefParser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import GridRefParserCI from './CI';
import GridRefParserGB from './GB';
import GridRefParserIE from './IE';

/**
* @constructor
*/
Expand Down Expand Up @@ -114,62 +112,18 @@ GridRefParser.prototype.quadrant = '';
GridRefParser.prototype.quadrantCode = '';

/**
* returns a GridRefParser (GB, IE or CI-specific parser) or false
* crudely tries to determine the country by trying each country in turn
*
* @param {string} rawGridRef
* @return GridRefParser|FALSE
* update tetrad using Easting/Northing values (metres)
* hectad should have been set prior to call
*/
GridRefParser.factory = function(rawGridRef) {
var parser;
var cleanRef = rawGridRef.replace(/\s+/g, '').toUpperCase();

if (!cleanRef) {
return false;
}
GridRefParser.prototype.set_tetrad = function() {
this.tetradLetter = GridRefParser.tetradLetters.substr(
((Math.floor((this.osRef.x % 10000) / 1000) >> 1) * 5) + (Math.floor((this.osRef.y % 10000) / 1000) >> 1)
, 1);

// if canonical ref form then be more efficient
if (/^[A-Z]{1,2}\d{2}(?:[A-Z]|[NS][EW]|(?:\d{2}){0,4})?$/.test(cleanRef)) {
// have simple well-formed grid ref

if (/^.\d/.test(cleanRef)) {
parser = new GridRefParserIE();
} else {
if (cleanRef.charAt(0) === 'W') {
parser = new GridRefParserCI();
} else {
parser = new GridRefParserGB();
}
}

parser.parse_well_formed(cleanRef);

return (parser.length && !parser.error) ? parser : false;
} else {
parser = new GridRefParserGB();
parser.parse(cleanRef);

if (parser.length && !parser.error) {
return parser;
}

if (cleanRef.charAt(0) === 'W') {
parser = new GridRefParserCI();
parser.parse(cleanRef);

if (parser.length && !parser.error) {
return parser;
}
} else {
parser = new GridRefParserIE();
parser.parse(cleanRef);

if (parser.length && !parser.error) {
return parser;
}
}
if (!this.tetradLetter) {
throw new Error("Failed to get tetrad letter when processing '" + this.preciseGridRef + "', easting=" + this.osRef.x + " northing=" + this.osRef.y);
}
return false;
this.tetrad = this.hectad + this.tetradLetter;
};

GridRefParser.get_normalized_precision = function(rawPrecision, minPrecision) {
Expand All @@ -185,19 +139,5 @@ GridRefParser.get_normalized_precision = function(rawPrecision, minPrecision) {
);
};

/**
* update tetrad using Easting/Northing values (metres)
* hectad should have been set prior to call
*/
GridRefParser.prototype.set_tetrad = function() {
this.tetradLetter = GridRefParser.tetradLetters.substr(
((Math.floor((this.osRef.x % 10000) / 1000) >> 1) * 5) + (Math.floor((this.osRef.y % 10000) / 1000) >> 1)
, 1);

if (!this.tetradLetter) {
throw new Error("Failed to get tetrad letter when processing '" + this.preciseGridRef + "', easting=" + this.osRef.x + " northing=" + this.osRef.y);
}
this.tetrad = this.hectad + this.tetradLetter;
};

export default GridRefParser;
65 changes: 65 additions & 0 deletions src/GridRefParser/factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import GridRefParser from './GridRefParser';
import GridRefParserCI from './CI';
import GridRefParserGB from './GB';
import GridRefParserIE from './IE';

/**
* returns a GridRefParser (GB, IE or CI-specific parser) or false
* crudely tries to determine the country by trying each country in turn
*
* @param {string} rawGridRef
* @return GridRefParser|FALSE
*/
GridRefParser.factory = function (rawGridRef) {
var parser;
var cleanRef = rawGridRef.replace(/\s+/g, '').toUpperCase();

if (!cleanRef) {
return false;
}

// if canonical ref form then be more efficient
if (/^[A-Z]{1,2}\d{2}(?:[A-Z]|[NS][EW]|(?:\d{2}){0,4})?$/.test(cleanRef)) {
// have simple well-formed grid ref

if (/^.\d/.test(cleanRef)) {
parser = new GridRefParserIE();
} else {
if (cleanRef.charAt(0) === 'W') {
parser = new GridRefParserCI();
} else {
parser = new GridRefParserGB();
}
}

parser.parse_well_formed(cleanRef);

return (parser.length && !parser.error) ? parser : false;
} else {
parser = new GridRefParserGB();
parser.parse(cleanRef);

if (parser.length && !parser.error) {
return parser;
}

if (cleanRef.charAt(0) === 'W') {
parser = new GridRefParserCI();
parser.parse(cleanRef);

if (parser.length && !parser.error) {
return parser;
}
} else {
parser = new GridRefParserIE();
parser.parse(cleanRef);

if (parser.length && !parser.error) {
return parser;
}
}
}
return false;
};

export default GridRefParser;
3 changes: 3 additions & 0 deletions src/IELatLng.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import OSGB36LatLng from 'OSGB36LatLng';
import WGS84LatLng from 'WGS84LatLng';
import OSIRef from 'OSIRef';
import LatLng from 'LatLng';
import { deg2rad, rad2deg } from 'constants';

/**
* represents lat lng as Modified Airy (Irish grid projection)
Expand Down
1 change: 1 addition & 0 deletions src/LatLng.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deg2rad } from 'constants';

/**
* represents lat lng
Expand Down
3 changes: 3 additions & 0 deletions src/OSCIRef.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import NationalGridCoords from 'NationalGridCoords';
import WGS84LatLng from 'WGS84LatLng';
import LatLng from 'LatLng';
import { deg2rad, rad2deg } from 'constants';

/**
*
Expand Down
1 change: 1 addition & 0 deletions src/OSGB36LatLng.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import WGS84LatLng from 'WGS84LatLng';
import OSRef from 'OSRef';
import { deg2rad, rad2deg } from 'constants';

/**
* represents lat lng as OSGB1936 (Ordnance Survey projection)
Expand Down
3 changes: 3 additions & 0 deletions src/OSIRef.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import NationalGridCoords from 'NationalGridCoords';
import MappingUtils from 'MappingUtils';
import IELatLng from 'IELatLng';
import { rad2deg } from 'constants';

/**
*
Expand Down
3 changes: 3 additions & 0 deletions src/OSRef.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import NationalGridCoords from 'NationalGridCoords';
import OSGB36LatLng from 'OSGB36LatLng';
import MappingUtils from 'MappingUtils';
import { rad2deg } from 'constants';

/**
*
Expand Down
5 changes: 5 additions & 0 deletions src/WGS84LatLng.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import CILatLng from 'CILatLng';
import IELatLng from 'IELatLng';
import LatLng from 'LatLng';
import OSGB36LatLng from 'OSGB36LatLng';
import { deg2rad, rad2deg } from 'constants';

/**
* represents lat lng as WGS84 (google map form)
*
Expand Down
4 changes: 4 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const deg2rad = Math.PI / 180;
const rad2deg = 180.0 / Math.PI;

export { deg2rad, rad2deg };
25 changes: 3 additions & 22 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import GridRefParser from 'GridRefParser/GridRefParser';
import GridRefParser from 'GridRefParser/factory';
import GridRefParserCI from 'GridRefParser/CI';
import GridRefParserGB from 'GridRefParser/GB';
import GridRefParserIR from 'GridRefParser/IE';
Expand All @@ -12,9 +12,11 @@ import OSGB36LatLng from 'OSGB36LatLng';
import OSIRef from 'OSIRef';
import OSRef from 'OSRef';
import WGS84LatLng from 'WGS84LatLng';
import './polyfill';


var BIGU = {
scriptVersions: {},
GridRefParser,
GridRefParserCI,
GridRefParserGB,
Expand All @@ -33,27 +35,6 @@ var BIGU = {

BIGU.scriptVersions.gridref = '001';

var deg2rad = Math.PI / 180;
var rad2deg = 180.0 / Math.PI;

/**
* polyfill for browsers other than firefox
*/
if (!('asinh' in Math)) {
Math.asinh = function (x) {
return Math.log(x + Math.sqrt(x * x + 1));
};
}

/**
* polyfill for browsers other than firefox and chrome
*/
if (!('trunc' in Math)) {
Math.trunc = function (x) {
return x < 0 ? Math.ceil(x) : Math.floor(x);
};
}

BIGU.scriptVersions.grParser = '002';

/**
Expand Down
17 changes: 17 additions & 0 deletions src/polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* polyfill for browsers other than firefox
*/
if (!('asinh' in Math)) {
Math.asinh = function (x) {
return Math.log(x + Math.sqrt(x * x + 1));
};
}

/**
* polyfill for browsers other than firefox and chrome
*/
if (!('trunc' in Math)) {
Math.trunc = function (x) {
return x < 0 ? Math.ceil(x) : Math.floor(x);
};
}
4 changes: 3 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const _ = require('underscore');
const webpack = require('webpack');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const pkg = require('./package.json');

var filename = 'BIGU.js';
Expand All @@ -20,7 +21,8 @@ const plugins = [
new webpack.DefinePlugin({
LIB_VERSION: JSON.stringify(pkg.version),
}),
new webpack.BannerPlugin(banner)
new webpack.BannerPlugin(banner),
new CircularDependencyPlugin(),
];

if (uglify) {
Expand Down

0 comments on commit 1408c01

Please sign in to comment.