Skip to content

Commit

Permalink
Added a sentence validation to the utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
fabdrol committed Nov 13, 2016
1 parent 42d645a commit 096a278
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,46 @@

utils.RATIOS = {
// DISTANCE
NM_IN_KM: 1.852000000000000000000000000000000000000000000000000000000000000000000000000,
KM_IN_NM: 0.539956803000000000000000000000000000000000000000000000000000000000000000000000000,
NM_IN_KM: 1.852,
KM_IN_NM: 0.539956803,
// SPEED
// Knots
KNOTS_IN_MS: 0.514444000000000000000000000000000000000000000000000000000000000000000000000000,
KNOTS_IN_MPH: 1.150779000000000000000000000000000000000000000000000000000000000000000000000000,
KNOTS_IN_KPH: 1.852000000000000000000000000000000000000000000000000000000000000000000000000,
KNOTS_IN_MS: 0.514444,
KNOTS_IN_MPH: 1.150779,
KNOTS_IN_KPH: 1.852,
// MPH
MPH_IN_MS: 0.44704000000000000000000000000000000000000000000000000000000000000000000000000,
MPH_IN_KPH: 1.609344000000000000000000000000000000000000000000000000000000000000000000000000,
MPH_IN_KNOTS: 0.868976000000000000000000000000000000000000000000000000000000000000000000000000,
MPH_IN_MS: 0.44704,
MPH_IN_KPH: 1.609344,
MPH_IN_KNOTS: 0.868976,
// KPH
KPH_IN_MS: 0.277778000000000000000000000000000000000000000000000000000000000000000000000000,
KPH_IN_MPH: 0.621371000000000000000000000000000000000000000000000000000000000000000000000000,
KPH_IN_KNOTS: 0.539957000000000000000000000000000000000000000000000000000000000000000000000000,
KPH_IN_MS: 0.277778,
KPH_IN_MPH: 0.621371,
KPH_IN_KNOTS: 0.539957,
// MS
MS_IN_KPH: 3.6000000000000000000000000000000000000000000000000000000000000000000000000,
MS_IN_MPH: 2.236936000000000000000000000000000000000000000000000000000000000000000000000000,
MS_IN_KNOTS: 1.943844000000000000000000000000000000000000000000000000000000000000000000000000,
MS_IN_KPH: 3.6,
MS_IN_MPH: 2.236936,
MS_IN_KNOTS: 1.943844,
};

exports.valid = function(sentence) {
sentence = String(sentence).trim();

if (sentence === "") {
return false;
}

if ((sentence.charAt(0) == '$' || sentence.charAt(0) == '!') && sentence.charAt(sentence.length - 3) == '*') {
var check = 0;
var split = sentence.split('*');

for (var i = 1; i < split[0].length; i++) {
check = check ^ split[0].charCodeAt(i);
};

return (parseInt(split[1], 16) == check);
}

return false;
};

exports.source = function(sentence) {
Expand Down

0 comments on commit 096a278

Please sign in to comment.