Skip to content

Commit

Permalink
Fix error in parse data. Fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Aug 26, 2015
1 parent 0f5cf4a commit 177a3fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-nmea",
"version": "0.2.1",
"version": "0.2.2",
"description": "Parser for NMEA sentences.",
"main": "lib",
"scripts": {
Expand Down
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const params = {
track: /\d{1,3}[.]\d{1,3}/,
date: /\d{6}/,
magneticVariation: /(\d{1,3}[.]\d{1,3})?\,([WE])?/,
faa: /[ADENS]/,
faa: /([ADENS])?/,
gprmcCheckSum: /\w{2}/
}

Expand All @@ -63,7 +63,8 @@ const gprmc = XRegExp.build(`(?x)^
({{speed}}) \\,
({{track}}) \\,
({{date}}) \\,
({{magneticVariation}}) \\,
({{magneticVariation}})
(\\,)?
({{faa}}) \\*
({{gprmcCheckSum}})$`, params)

Expand Down Expand Up @@ -197,7 +198,7 @@ function parse(raw) {
speed: knotsToKmh(r.speed),
track: r.track,
magneticVariation: r.magneticVariation,
mode: faaModes[r.faa]
mode: r.faa ? faaModes[r.faa] : null
}
}

Expand Down Expand Up @@ -258,7 +259,9 @@ function randomData(opts = {}) {
magneticVariation = opts.magneticVariation || chance.pick([mv, ","])
}

if (params.faa.test(opts.faa)) {
if (opts.faa === undefined) {
faa = "A"
} else if (params.faa.test(opts.faa)) {
faa = opts.faa
} else {
faa = "A"
Expand Down

0 comments on commit 177a3fe

Please sign in to comment.