Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
/ arg-analyser Public archive

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

License

Notifications You must be signed in to change notification settings

tguichaoua/arg-analyser

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published