npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ais-stream-decoder

v2.1.2

Published

AIS/NMEA decoder with native Node.js stream interface (TypeScript/JavaScript)

Downloads

195

Readme

AIS Stream Decoder

AIS/NMEA decoder with native stream interface for Node.js.

NPM Version CI Tests

Installation

This is a Node.js module available through the npm registry.

Installation is done using the npm install command:

$ npm install ais-stream-decoder

Features

  • Currently supports message types 1,2,3,4,5,18,24 (more to come) and partially supports message type 8 (inland static and voyage data)
  • Handles multi-part messages out of the box
  • Streaming API implemented as a Node.js transform stream
  • Returns nicely formatted JSON messages
  • Written in TypeScript

Usage

Decode a single line of data:

import AisDecoder from 'ais-stream-decoder';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const nmea = '!AIVDM,1,1,,B,133i;RPP1DPEbcDMV@1r:Ow:2>`<,0*41';
aisDecoder.write(nmea);

=>

{"type":1,"channel":"B","repeat":0,"mmsi":205278090,"navStatus":0,"rateOfTurn":null,"speedOverGround":8.4,"accuracy":true,"lon":4.73319,"lat":51.725665,"courseOverGround":260.1,"heading":null,"utcSecond":37,"specialManoeuvre":0,"raim":true,"radio":59916,"sentences":["!AIVDM,1,1,,B,133i;RPP1DPEbcDMV@1r:Ow:2>`<,0*41"]}

Handles multi-part messages like a pro:

import AisDecoder from 'ais-stream-decoder';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const part1 =
  '!AIVDM,2,1,7,A,57lof8`2F5HeT<eC:204e86373:222222222221@8HQC16Ch0:RA7kAD,0*28';
const part2 = '!AIVDM,2,2,7,A,PBp888888888880,2*79';

aisDecoder.write(part1);
aisDecoder.write(part2);

=>

{"type":5,"channel":"A","repeat":0,"mmsi":525200930,"aisVersion":2,"imo":9835915,"callsign":"YCKT2","name":"AKRA 102","typeAndCargo":80,"dimBow":67,"dimStern":33,"dimPort":19,"dimStarboard":1,"epfd":1,"etaMonth":9,"etaDay":7,"etaHour":16,"etaMinute":0,"draught":4.2,"destination":"ID_MERAK","dte":false,"sentences":["!AIVDM,2,1,7,A,57lof8`2F5HeT<eC:204e86373:222222222221@8HQC16Ch0:RA7kAD,0*28","!AIVDM,2,2,7,A,PBp888888888880,2*79"]}

Use it to read and decode NMEA line-by-line from a file:

import AisDecoder from 'ais-stream-decoder';
import {createReadStream} from 'fs';
import {resolve} from 'path';
import {createInterface} from 'readline';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const fileStream = createReadStream(
  resolve(__dirname, './examples/messages.txt')
);
const readLine = createInterface(fileStream);
readLine.on('line', line => aisDecoder.write(line));

We all love pipes! ❤

import AisDecoder from 'ais-stream-decoder';
import split from 'split';
import {createReadStream} from 'fs';
import {resolve} from 'path';

const fileStream = createReadStream(
  resolve(__dirname, './examples/messages.txt')
);
const aisDecoder = new AisDecoder({silent: true});

fileStream
  .pipe(split())
  .pipe(aisDecoder)
  .on('data', decodedMessage => {
    console.log(decodedMessage);
  });

License

MIT