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

bashscript

v2.0.26

Published

A small and minimalist REPL shell, and a very lightweight JavaScript library meant to convert Operating System commands to functions.

Downloads

54

Readme

bashscript

A small and minimalist REPL shell, and a very lightweight JavaScript library meant to convert Operating System commands to functions.

TLDR

import { cmd } from 'bashscript';
await cmd.echo("Grr Grr Meow!").exe; // Grr Grr Meow!

Installation

npm i bashscript

REPL Shell

npm i -g bashscript # install bashscript REPL shell
$ bashscript # enter shell
> process.title
node

> process.uptime()
22.950190303

> cmd.echo('Meow!').value()
Promise { <pending> }

> await cmd.echo('Meow!').value()
'Meow!'

Advanced REPL


> const command = cmd.echo('Foo');
undefined

> command
Shell {}

> await command.value();
'Foo'

> command.result
{
  command: 'echo Foo',
  exitCode: 0,
  stdout: 'Foo',
  stderr: '',
  all: undefined,
  failed: false,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Usage

import { cmd, exe } from 'bashscript';
const { echo } = cmd;
const result = await exe( echo("Meow!") );
assert.equal(result, "Meow!");
import { cmd } from 'bashscript';
const result = await cmd.echo("Meow!").value();
assert.equal(result, "Meow!");
import { cmd } from 'bashscript';
const result = await cmd.echo("Meow!").exe;
assert.equal(result, "Meow!");

Pipeline Example

import { cmd } from 'bashscript';
const { pipeline, cat, echo, tr, grep } = cmd;
const result = await pipeline(
  cat( echo('package.json') ),
  tr( '"[a-z]"', '"[A-Z]"'),
  grep('NAME')
).value();
assert.equal(result, '  "NAME": "BASHSCRIPT",')
import { cmd } from 'bashscript';
const { pipeline, cat, printf, dirname, readlink, which, grep, head } = cmd;
const result = await exe( pipeline(
  cat(
    printf(
      "%s",
      dirname(
        readlink(
          '-f',
          which('npm')
        )
      ),
      "/../package.json"
    )
  ),
  grep('name'),
  head('-n', 1)
) );
assert.equal(result, '  "name": "npm",')
import { cmd } from 'bashscript';
const { pipeline, cat, printf, dirname, readlink, which, grep, head } = cmd;
const result = await pipeline( cat( printf( "%s", dirname( readlink( '-f', which('npm') ) ), "/../package.json" ) ), grep('name'), head('-n', 1) ).value();
assert.equal(result, '  "name": "npm",')
import { cmd, pipeline } from 'bashscript'; // a pipeline helper can also be imported directly from the bashscript module.
const { cat, printf, dirname, readlink, which, grep, head } = cmd;
const result = await pipeline(cat( printf("%s", dirname(readlink('-f', which('npm'))),"/../package.json" )), grep('name'), head('-n', 1) ).value();
debug(result);
assert.equal(result, '  "name": "npm",')

Debugging Example

#!/usr/bin/env -S node --trace-uncaught
import { inspect } from 'util';
import { cmd } from '../index.js';
const { montage } = cmd;
const files = ['a.png', 'b.png', 'c.png'];
const tile = 2;
const filePath = '/tmp/test.jpg';
const command = montage(
  {'-background': '"#212529"'},
  ...files,
  {
    '-geometry': '320x230',
    '-tile':`${tile}x`
  },
  filePath
);

console.log(await command.string);
// await command.exe; // to execute;

prints

montage -background "#212529" a.png b.png c.png -geometry 320x230 -tile 2x /tmp/test.jpg

Namage

Not related to Bash the GNU Project's shell (the Bourne Again SHell), this is a JavaScript library that automagically converts system commands to JavaScript functions (Think "bash, verb: strike hard and violently");

History

Need for OS command integration arose from development of https://catpea.com, I was unable to locate small enough solutions that worked well for me. I came across proxy-www and ended up creating munchhausen and later bashscript.