Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fluent-string-lexer

gas-buddy15MIT1.0.0

A fluent-style lexer (a very simple one) that walks a string and outputs values

lexer, lex, string parsing, fixed formats, legacy data formats, gasbuddy

readme

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',
  }

changelog

1.0.0

  • Everything changes.