arg-analyser
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Arg Analyser

Version Maintenance License: MIT

A simple configurable string analyser to get elements from command like string.

  • Split the string by space
  • Don't split string between quotes
  • Recursive group

How to use it

import { Analyser } from "arg-analyser";

const sample = `Lorem ipsum "dolor sit amet, consectetur" adipiscing (elit. [In id {fermentum mi.}] Curabitur) viverra, 'justo \\'nec viver"ra' mollis, lec"tus massa."`;

// Perform a one shot analyse
const args = Analyser.analyse(sample, {
    delimiters: [
        ["(", ")"],
        ["[", "]"],
        ["{", "}"],
    ],
});

// Instantiate a Analyse object to re-use it
const analyser = new Analyser({
    delimiters: [
        ["(", ")"],
        ["[", "]"],
        ["{", "}"],
    ],
});

const args1 = analyser.analyse("hello world !");
const args2 = analyser.analyse(sample);

Example

To run the example script :

  1. Clone this repository git clone https://github.com/tguichaoua/arg-analyser.git
  2. Enter in the directory cd arg-analyser
  3. Install dependencies npm install
  4. Run the example script npm run example
========================================
hello world !
----------------------------------------
├ ∅  hello
├ ∅  world
├ ∅  !
========================================
"hello world" !
----------------------------------------
├ "  hello world
├ ∅  !
========================================
[deep (in {the (rabbit [hole])})]
----------------------------------------
├ [ ]
│  ├ ∅  deep
│  ├ ( )
│  │  ├ ∅  in
│  │  ├ { }
│  │  │  ├ ∅  the
│  │  │  ├ ( )
│  │  │  │  ├ ∅  rabbit
│  │  │  │  ├ [ ]
│  │  │  │  │  ├ ∅  hole
========================================

📝 License

Copyright © 2021 Tristan Guichaoua.
This project is MIT licensed.

Readme

Keywords

Package Sidebar

Install

npm i arg-analyser

Weekly Downloads

2

Version

0.1.1

License

MIT

Unpacked Size

14.5 kB

Total Files

9

Last publish

Collaborators

  • tguichaoua