Skip to content

Commit

Permalink
Merge pull request #45 from DanielJDufour/ImprovedDecoding
Browse files Browse the repository at this point in the history
Improved decoding
  • Loading branch information
DanielJDufour authored May 6, 2019
2 parents ef2104f + e246a9f commit c30067f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mgrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function inverse(mgrs) {

export function toPoint(mgrs) {
if (mgrs === '') {
throw new TypeError(`toPoint received a blank string`);
throw new TypeError('toPoint received a blank string');
}
const bbox = UTMtoLL(decode(mgrs.toUpperCase()));
if (bbox.lat && bbox.lon) {
Expand Down Expand Up @@ -505,6 +505,9 @@ function decode(mgrsString) {
throw new TypeError('MGRSPoint coverting from nothing');
}

//remove any spaces in MGRS String
mgrsString = mgrsString.replace(/ /g, '');

const { length } = mgrsString;

let hunK = null;
Expand Down
10 changes: 9 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe ('third mgrs set', () => {
});

describe ('data validation', () => {
describe('forward function', () => {
describe('toPoint function', () => {
it('toPoint throws an error when a blank string is passed in', () => {
try {
mgrs.toPoint('');
Expand All @@ -56,6 +56,14 @@ describe ('data validation', () => {
error.message.should.equal('toPoint received a blank string');
}
});
it('toPoint should return the same result whether or not spaces are included in the MGRS String', () => {
const [ lon1, lat1 ] = mgrs.toPoint('4QFJ 12345 67890');
const [ lon2, lat2] = mgrs.toPoint('4QFJ1234567890');
lat1.should.equal(lat2);
lon1.should.equal(lon2);
});
});
describe('forward function', () => {
it('forward throws an error when array of strings passed in', () => {
try {
mgrs.forward(['40', '40']);
Expand Down

0 comments on commit c30067f

Please sign in to comment.