Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flight-plan-converter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flight-plan-converter - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

fixtures/fpl/sample.fpl

45

cli.js
'use strict';
// TODO: write cli
const fs = require( 'fs' )
const lib = require( './lib' )
const { formatSuffixes, formatTypes } = lib
if( process.argv.length < 4 ) {
console.error( `usage: ${process.argv[1]} [source] [dest]` )
process.exit()
}
const ifn = process.argv[ 2 ]
const isuffix = ifn.slice( ( ifn.lastIndexOf( '.' ) - 1 >>> 0 ) + 2 )
const ikey = Object.keys( formatSuffixes ).find( key => formatSuffixes[ key ] === isuffix )
const itype = formatTypes[ ikey ]
const ofn = process.argv[ 3 ]
const osuffix = ofn.slice( ( ofn.lastIndexOf( '.' ) - 1 >>> 0 ) + 2 )
const okey = Object.keys( formatSuffixes ).find( key => formatSuffixes[ key ] === osuffix )
const otype = formatTypes[ okey ]
if( !itype || !otype ) {
console.error( `unsupported type ${itype} ${otype}` )
process.exit()
}
const ifs = fs.readFileSync( ifn, 'utf8' )
fs.writeFileSync( ofn,
// converts parsed/normalized flight plan to specifique format
lib.convert(
// parsed/normalized flight plan
lib.parse(
// raw input flight plan
ifs,
// input format
itype // -> 'ms_fpl'
),
// output format
otype, // lib.formats.XPLANE_FMS // -> 'xplane_fms'
{ fmsVersion: '1100' }
) + '\n',
'utf8'
);

4

lib/convert/index.js

@@ -14,3 +14,3 @@ 'use strict';

*/
module.exports = function (flightPlan, format) {
module.exports = function (flightPlan, format, options) {
var converter = converters[format] || null;

@@ -22,3 +22,3 @@

return converter(flightPlan);
return converter(flightPlan, options);
};
'use strict';
var types = require('../types');
var typeMap = require('../typeMap');
var reverseTypeMap = Object.keys( typeMap ).reduce( ( r, k ) => ( { ...r, ...k && typeMap[ k ] && { [ typeMap[ k ] ]: k } } ), {} )
var typeMap = {
'airport': 1,
'ndb': 2,
'vor': 3,
'fix': 11,
'gps': 28
};
function getWaypointName( waypoint ) {
switch( waypoint.type ) {
case types.AIRPORT:
return waypoint.airport.icao
break;
case types.NDB:
case types.VOR:
return waypoint[waypoint.type].identifier
break;
case types.FIX:
return waypoint.fix.name
break;
case types.GPS:
default:
return waypoint.identifier || 'NONAME'
break
}
}
function lineFromWaypoint(waypoint) {
var line = [typeMap[waypoint.type] || typeMap[types.GPS]];
function lineFromWaypoint(waypoint, index, length, fmsVersion) {
var line = [reverseTypeMap[waypoint.type] || reverseTypeMap[types.GPS]];

@@ -27,4 +40,26 @@ switch(waypoint.type) {

break;
case types.GPS:
default:
// FMS takes all five entries per line, even for older v3 version, so should consider adding it even without v1100
// (leaving out to avoid intruding on anyone's compatbility)
// And most parsers allow the identifier here for locations (instead of weird +000_-000), including X-Plane
if( fmsVersion === '1100' ) {
line.push( waypoint.identifier || 'NONAME' )
}
break
}
if( fmsVersion === '1100' ) {
// v1100 needs VIA entry, using direct for enroute segments for now (except for departing and arriving airports)
let via
if( waypoint.type === types.AIRPORT && index === 0 ) {
via = 'ADEP'
} else if( waypoint.type === types.AIRPORT && index === length - 1 ) {
via = 'ADES'
} else {
via = 'DRCT'
}
line.push( via )
}
line.push(waypoint.elevation);

@@ -37,8 +72,3 @@ line.push(waypoint.lat);

/**
* Converts normalized flight plan to XPlanes fms format
* @param {Object} flightPlan normalized flight plan
* @return {String} FMS flight plan
*/
module.exports = function (flightPlan) {
function getV3Header( flightPlan ) {
return [

@@ -50,8 +80,38 @@ 'I',

]
}
function getDeX( suffix, waypoint ) {
const name = getWaypointName( waypoint )
const line = waypoint.type === types.AIRPORT ? `A${suffix} ${name}` : `${suffix} ${name}`
return line
}
function getV1100Header( flightPlan ) {
const dep = getDeX( 'DEP', flightPlan.waypoints[ 0 ] )
const des = getDeX( 'DES', flightPlan.waypoints[ flightPlan.waypoints.length - 1 ] )
return [
'I',
'1100 version',
'CYCLE 1708', // could get real AIRAC cycle, using this for now just to match X-Plane
dep,
des,
`NUMENR ${flightPlan.waypoints.length}`
]
}
/**
* Converts normalized flight plan to XPlanes fms format
* @param {Object} flightPlan normalized flight plan
* @return {String} FMS flight plan
*/
module.exports = function (flightPlan, options = {}) {
const { fmsVersion } = options
const header = fmsVersion === '1100' ? getV1100Header( flightPlan) : getV3Header( flightPlan )
return header
.concat(
flightPlan
.waypoints
.map(lineFromWaypoint)
.map( ( wp, i ) => lineFromWaypoint( wp, i, flightPlan.waypoints.length, fmsVersion ))
)
.join('\r\n');
};

@@ -50,2 +50,8 @@ 'use strict';

});
it('should convert complex.json into V1100', () => {
expect(converter(getFlightPlan('complex.json'), { fmsVersion: '1100' }))
.to
.eql(getFms('complex_cleaned_v1100.fms'));
});
});
'use strict';
// module file names for converters and parsers
const types = require( './formatTypes' )
const { FPL } = types
module.exports = {
XPLANE_FMS: 'xplane_fms',
KML: 'kml'
KML: 'kml',
[ FPL ]: 'fpl'
};

@@ -6,4 +6,6 @@ 'use strict';

parse: require('./parse'),
formatTypes: require('./formatTypes'),
formats: require('./formats'),
formatSuffixes: require('./formatSuffixes'),
types: require('./types')
};
'use strict';
const formatTypes = require( '../formatTypes' )
const { FPL } = formatTypes
var parsers = {
xplane_fms: require('./xplane_fms')
xplane_fms: require('./xplane_fms'),
[ FPL ]: require( './fpl' )
};

@@ -6,0 +10,0 @@

@@ -7,12 +7,4 @@ 'use strict';

var normalizeLineBreaks = require('../utils/normalizeLineBreaks');
var typeMap = require('../typeMap');
var typeMap = {
1: types.AIRPORT,
2: types.NDB,
3: types.VOR,
11: types.FIX,
28: types.GPS,
9999: types.ERROR
};
var fmsVersion = 3;

@@ -19,0 +11,0 @@

{
"name": "flight-plan-converter",
"version": "0.0.5",
"version": "0.0.6",
"description": "Converts Flight Plans from and to various file formats.",
"bin": "cli.js",
"bin": "flight-plan-converter",
"main": "index.js",
"scripts": {
"convert": "node cli.js @$",
"convert": "node cli.js",
"test": "node node_modules/.bin/mocha lib/*.test.js lib/**/*.test.js"

@@ -31,3 +31,6 @@ },

"mocha": "^2.5.3"
},
"dependencies": {
"libxmljs": "^0.19.5"
}
}

@@ -12,2 +12,3 @@ # Flight-Plan converter

- [X-Planes](http://www.x-plane.com) `.fms` V1100
- [ForeFlight](https://plan.foreflight.com) `.fpl` (import only)
- KML (export only)

@@ -25,2 +26,9 @@

or bypassing npm to use directly:
```bash
$ npm install
$ flight-plan-converter [source] [dest]
```
or programatically:

@@ -27,0 +35,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc