npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generic-stdout-parser

v1.0.1

Published

Parse any type of command line/cmd/shell stdout into Javascrpt Object, JSON or XML

Downloads

1,479

Readme

Generic StdOut parser

Version Downloads/week License

Description

Unable to find a parser for results of command 'v4l2-ctl --list-ctrls', I had to create it myself. Soooo fed up of manually creating parsers for cmd/sh/bash command line output logs , I created this NPM package to centralize all my homemade parsers at the same place, and possibly avoid to have to specify the input format

When there are useless lines added to a stdout json or xml shell output, the parser manages to detect and ignore them.

To avoid duplication with linux tables parsing of package node-shell-parser, it is possible to use 'node-shell-parser' as inputFormat

Available input formats are

  • json
  • xml
  • raw_structure_datatype_props
  • shell

Available output formats are

  • javascript object
  • JSON
  • XML

Installation

npm install generic-stdout-parser

Usage

    const StdOutParser = require('generic-stdout-parser')
    const stdoutlog = [' some useless output line','   <lelama>NUL</lelama>    ',' another useless output line']
    const parseRes = new StdOutParser(stdoutlog).parse()
    console.log(parseRes.result.lelama === "NUL")

Examples

Json to JS Object

        const StdOutParser = require('generic-stdout-parser')
        const stdoutlog = ['{ "lelama": "NUL" }']
        const parseRes = new StdOutParser(stdoutlog).parse()
        assert(parseRes.result.lelama === "NUL",'lelama property not found in '+JSON.stringify(parseRes))

JSON to JS Object with crappy extra lines:

        const StdOutParser = require('generic-stdout-parser')
        const stdoutlog = ['blablablabla','   { "lelama": "NUL" }']
        const parseRes = new StdOutParser(stdoutlog).parse()
        assert(parseRes.result.lelama === "NUL",'lelama property not found in '+JSON.stringify(parseRes))

XML to JS Object

        const StdOutParser = require('generic-stdout-parser')
        const stdoutlog = '<lelama>NUL</lelama>'
        const parseRes = new StdOutParser(stdoutlog).parse()
        assert(parseRes.result.lelama === "NUL",'lelama property not found in '+JSON.stringify(parseRes))

JSON to XML:

        const StdOutParser = require('generic-stdout-parser')
        const stdoutlog = ['{ "lelama": "NUL" }']
        const parseRes = new StdOutParser(stdoutlog,{'resultFormat': 'xml'}).parse()
        console.log(parseRes)

raw_structure_datatype_props (v4l2-ctl --list-ctrls) to JS Object:

        const StdOutParser = require('generic-stdout-parser')
        const stdoutlog = `User Controls

        brightness (int)    : min=0 max=100 step=1 default=50 value=50 flags=slider
          contrast (int)    : min=-100 max=100 step=1 default=0 value=-10 flags=slider
        saturation (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
       red_balance (int)    : min=1 max=7999 step=1 default=1000 value=1000 flags=slider
      blue_balance (int)    : min=1 max=7999 step=1 default=1000 value=1000 flags=slider
   horizontal_flip (bool)   : default=0 value=0

Codec Controls

video_bitrate_mode (menu)   : min=0 max=1 default=0 value=0 flags=update
     video_bitrate (int)    : min=25000 max=25000000 step=25000 default=10000000 value=10000000
repeat_sequence_header (bool)   : default=0 value=0
h264_i_frame_period (int)    : min=0 max=2147483647 step=1 default=60 value=60
        h264_level (menu)   : min=0 max=11 default=11 value=11
      h264_profile (menu)   : min=0 max=4 default=4 value=4` ;
      
        const parseRes = new StdOutParser(stdoutlog,{inputFormat: 'raw_structure_datatype_props'}).parse()
        assert(parseRes.result.find(x => x.name === 'User Controls').properties
                                    .find(x => x.name === 'brightness').properties
                                    .find(x => x.name === 'value')
                                    .value === '50',
                                    'Unable to find Camera Controls auto_exposure.max with value 3 in '+JSON.stringify(parseRes))

linux shell output to JS Object:

        const StdOutParser = require('generic-stdout-parser')
const stdoutlog = `  PID TTY          TIME CMD
        23856 pts/1    00:00:00 ps
        31475 pts/1    00:00:00 bash
        ` ;
        const parseRes = new StdOutParser(stdoutlog,{'inputFormat': 'shell'}).parse()
        assert(parseRes.result[0]['TTY'] === '23856 pts/1','Unable to find TTY = N23856 pts/1 in '+parseRes)

Don't hesitate to contribute with GitHub pull requests !