@canboat/canboatjs 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/analyzerjs CHANGED
@@ -1,9 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const argv = require('minimist')(process.argv.slice(2))
3
+ const argv = require('minimist')(process.argv.slice(2), {
4
+ alias: { h: 'help' },
5
+ boolean: ['n']
6
+ })
7
+
8
+ if ( argv['help'] ) {
9
+ console.error(`Usage: ${process.argv[1]} [options]
10
+
11
+ Options:
12
+ -c don't check for invalid values
13
+ -n output null values
14
+ -h, --help output usage information`)
15
+ process.exit(1)
16
+ }
4
17
 
5
18
  const Parser = require('../index').FromPgn
6
- var parser = new Parser()
19
+ var parser = new Parser( {
20
+ returnNulls: argv['n'] === true,
21
+ checkForInvalidFields: argv['n']
22
+ })
7
23
 
8
24
  parser.on('error', (pgn, error) => {
9
25
  console.error(`Error parsing ${pgn.pgn} ${error}`)
package/lib/fromPgn.js CHANGED
@@ -60,6 +60,10 @@ class Parser extends EventEmitter {
60
60
  super()
61
61
  this.options = _.isUndefined(opts) ? {} : opts
62
62
 
63
+ if ( this.options.returnNulls === undefined ) {
64
+ this.options.returnNulls = false
65
+ }
66
+
63
67
  this.name = pkg.name
64
68
  this.version = pkg.version
65
69
  this.author = pkg.author
@@ -235,7 +239,8 @@ class Parser extends EventEmitter {
235
239
  }
236
240
  }
237
241
 
238
- if ( !_.isUndefined(value) && value != null ) {
242
+ if ( !_.isUndefined(value) && (value != null ||
243
+ this.options.returnNulls) ) {
239
244
  pgn.fields[field.Name] = value
240
245
  }
241
246
  }
@@ -570,7 +575,18 @@ function readField(options, runPostProcessor, pgn, field, bs) {
570
575
  if ( field.Offset ) {
571
576
  value += field.Offset
572
577
  }
573
- if ( field.Resolution && typeof value === 'number' ) {
578
+ let max
579
+ if ( typeof field.RangeMax !== 'undefined'
580
+ && field.Resolution ) {
581
+ max = field.RangeMax / field.Resolution
582
+ }
583
+ if ( options.checkForInvalidFields !== false && max !== 'undefined' &&
584
+ field.FieldType !== 'LOOKUP' &&
585
+ field.BitLength > 1 &&
586
+ max - value <= 0 ) {
587
+ //console.log(`Bad field ${field.Name} ${max - value}`)
588
+ value = null
589
+ } if ( field.Resolution && typeof value === 'number' ) {
574
590
  var resolution = field.Resolution
575
591
 
576
592
  if ( _.isString(resolution) ) {
@@ -586,13 +602,6 @@ function readField(options, runPostProcessor, pgn, field, bs) {
586
602
  }
587
603
 
588
604
  value = Number.parseFloat(value.toFixed(precision))
589
-
590
- if ( typeof field.RangeMin !== 'undefined' && value < field.RangeMin ) {
591
- value = null
592
- }
593
- if ( typeof field.RangeMax !== 'undefined' && value > field.RangeMax ) {
594
- value = null
595
- }
596
605
  }
597
606
 
598
607
  if (field.FieldType === 'LOOKUP' &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {