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

lexure

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lexure

Lexer and parser for semi-structured user input.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
200
increased by104.08%
Maintainers
1
Weekly downloads
 
Created
Source

lexure

npm i lexure

Lexer and parser for structured non-technical user input.

Features

  • Parses quoted input with multiple quote types.
  • Parses flags and options with customizable parsing implementation.
  • Keeps trailing whitespace.
  • Always parses input by allowing some mis-inputs.

Example

import { Lexer, Parser, Tokens, Unordered } from 'lexure';

const input = 'hello world "cool stuff" --foo --bar=baz';

const lexer = new Lexer(input)
    .setQuotes([['"', '"'], ['“', '”']]);

const tokens = lexer.lex();
>>> [
    Word { value: 'hello', trailing: ' ' },
    Word { value: 'world', trailing: ' ' },
    Quoted { value: '"cool stuff"', innerValue: 'cool stuff', trailing: ' ' },
    Word { value: '--foo', trailing: ' ' },
    Word { value: '--bar=baz', trailing: '' },
]

const parser = new Parser(tokens)
    .setUnorderedStrategy(Unordered.longStrategy());

const res = parser.parse();
>>> {
    ordered: [
        Word { value: 'hello', trailing: ' ' },
        Word { value: 'world', trailing: ' ' },
        Quoted { value: '"cool stuff"', innerValue: 'cool stuff', trailing: ' ' }
    ],
    flags: Set { 'foo' },
    options: Map { 'bar' => 'baz' }
}

const text = Tokens.joinTokens(res.ordered);
>>> 'hello world "cool stuff"'

See code for more usages and documentation.

Keywords

FAQs

Package last updated on 10 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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