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

esc-get-cmd-stdout-array-promise

v0.1.7

Published

Runs the provided command and returns a promise that resolves with array of lines of stdout. onError can be 'empty' to receive an empty array regardless of error, 'exit' (process) else reject the promise.

Downloads

72

Readme

esc-get-cmd-stdout-array-promise

Runs the provided command and returns a promise that resolves with array of lines of stdout.

Install

npm install esc-get-cmd-stdout-array-promise

Use

I ran these commands in a terminal

/$ mkdir /tmp/foo
/$ cd /tmp/foo
/tmp/foo$ touch file1.txt file2.zip file3.mp3
/tmp/foo$ mkdir dir1 dir2
import getCmdStdoutAP from 'esc-get-cmd-stdout-array-promise';
import colors from 'esc-colors'; // optional

( async () => {
  const linesA = await getCmdStdoutAP('ls', { cwd:'/tmp/foo' }, colors);
  console.log('linesA', linesA);
})();

image

  const linesA = await getCmdStdoutAP('ls -la', { cwd:'/tmp/foo' }, colors);
  console.log('linesA', linesA);

image

Obviously ls isn't the best use for this module, but it's an example that anyone would be familiar with.

onError options

When the command that you run fails

  • (default) - Promise rejects
  • onError:'exit' - Exit the process
  • onError:'empty' - You receive []
  • onError:[] - You receive []
  • onError:['some','failsafe','output'] - You receive ['some','failsafe','output']
/tmp/foo$ printf 'APPLE\nORANGE\n' > fruit-selection.txt
  const linesA = await getCmdStdoutAP('cat fruit-selection.txt', { cwd:'/tmp/foo', onError:['GRAPE'] }, colors);
  console.log('linesA', linesA);

image

/tmp/foo$ rm fruit-selection.txt

image

Inspiration

Initially I liked zx but found it a nightmare to debug scripts run with it when something went wrong.

So I started using zx as a dependency and running my scripts with Node.JS.

Then I realized the only thing I like about zx is how you can run stuff, and I was even wrapping zx to turn stdout into an array, etc. So I just made something better (for me).

This is a 1.2KiB alternative to the zx's 831KiB. I sleep better at night.

Project goals

  • No dependencies
  • No nonsense
  • Reliable, no radical changes will ever happen.
  • Small, simple, easy to audit, yourself

If I have ideas for something different, I'll make a new package rather than make breaking changes.

Notes

Have fun!

Say thanks

Star the repo https://github.com/softwarecreations/esc-get-cmd-stdout-array-promise

PR's or issues

Welcome

License

MIT