fluent-string-lexer

1.0.0 • Public • Published

fluent-string-lexer

Node CI

A fluent-style lexer (a very simple one) that walks a string and outputs values. It was built to handle a data format that had mostly fixed fields with some optionals, some length-prefixed repeated elements, and other simple mechanisms. Hopefully it's useful to you.

See the tests for some examples, but here are some simple ones:

const tcpParser = new FluentStringLexer()
  .fixed(3, 'deviceType');

const parser = new FluentStringLexer()
  .fixed(3, 'messageGroup')
  .fixed(2, 'messageToken')
  .fixed(1, 'completionCode')
  .fixed(1, 'commandCode')
  .branchByValue('messageGroup', {
    TCP: tcpParser,
  });

This will parse the following message:

TCP00 BNXG

Into the following object:

  {
    messageGroup: 'TCP',
    messageToken: '00',
    commandCode: 'B',
    completionCode: ' ',
    deviceType: 'NXG',
  }

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    7
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    7

Package Sidebar

Install

npm i fluent-string-lexer

Weekly Downloads

7

Version

1.0.0

License

MIT

Unpacked Size

42 kB

Total Files

21

Last publish

Collaborators

  • djmax