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 🙏

© 2026 – Pkg Stats / Ryan Hefner

alchemist-cli

v1.1.0

Published

A NodeJS expression CLI wrapper

Downloads

6

Readme

alchemist

A simple command line wrapper for Javascript expressions and more

npm version

[!NOTE] This tool is still in its development stage. Feel free to contribute.

Prerequisites

This project requires NodeJS and NPM.

Installation

A. Stable version

Install as a global module from npm registry

npm install -g alchemist-cli

B. Latest features from git

Clone this repository

git clone https://github.com/vaexey/alchemist.git
cd alchemist

Install as a global module from source

npm install -g

Usage

Full command line syntax:

alc|alchemist <javascript expression> [// arg1 [arg2 ...]]

Quick start:

$ echo GHI | alc "'Hello world! ' + args[0] + CRLF + stdin" // ABC DEF
Hello world! ABC
GHI

Examples

  1. Replace newlines in stdin with ; and print to stdout
    Notice: Expression starting with a dot refer to a "stdin" string by default
cat file | alc ".split('\n').join(';')"
  1. Extract JSON value from file passed in command line arguments
// file.json
{
    "key1": {
        "key2": [
            1,
            2
        ]
    }
}
alc "file(args[0]).json().key1.key2[1].toFile(args[1])" // file.json output.txt
// output.txt
2
  1. Create variables and conditionals
alc "content = file(tstdin); content ? content.length : log('-1')"
  1. Handle errors
alc "(file(tstdin) ?? error(\`Could not read file \${tstdin}\`)).length"

alc "content = file(tstdin); assert(content != null, \`Could not read file \${tstdin}\`, content).length"
  1. Calculate documented arithmetic operations
alc "address = args[0]; opcode = args[1]; address_width = 5; (opcode << address_width) + address + CRLF" // 85 4
  1. Use return keyword in a function expression
    Notice: Prepending an expression with an @ wraps it into a function body that is immediately called which allows using this keyword
alc "@if(args[0] > args[1]) return 'left\n'; return 'right\n';" // 1 2
  1. Remove second to last character in string if it matches
alc "str = args[0].ss; if(str[-2] === '.') str[-2] = ''; str" // abc
  1. Return an exit code
alc "exitCode(args[0]);EMPTY" // -1
  1. Any valid NodeJS expression you can come up with
alc "require('crypto').createHash('sha256').update(args.join(' ')).digest('base64') + CRLF" // some text to be hashed

Important notes

  1. Javascript code usually must be surrounded by quotes
    This is caused by bash treating certain special characters as bash syntax (eg. brackets)
    Example:
// Bad - throws a bash error
alc log(args[0]) // abc
// Good
alc "log(args[0])" // abc
  1. Certain characters must be escaped with \ regardless of being inside quotes.
    This is caused by bash treating backticks and dollar sign variables as bash syntax.
    Example:
// Bad - unexpected behaviour
alc "`abc`"
alc "`${args.length} ${456}`"
// Good
alc "\`abc\`"
alc "\`\${args.length} \${456}\`"
  1. It is usually a good practice to end data written to stdout with a new line.
    Alchemist provides a bunch of constants that can solve this issue as no new line symbols are placed by default. Example:
// Bad - does not end with a newline and may cause cerain terminal emulators to display a malformed prompt
alc "args[0]" // abc
// Good - ends in (a) newline character(s)
alc "args[0] + LF" // abc
alc "args[0] + CRLF" // abc
  1. Usually, the stdin constant contains stray whitespace characters, such as new line at the end.
    To prevent these from malforming the input, use the tstdin variable to reference the result of .trim() function on the stdin value.
// Bad - stray new line character makes the path invalid
echo file.json | alc "file(stdin)"
// Good
echo file.json | alc "file(tstdin)"

Javascript extensions

Alchemist provides a couple of extensions to the NodeJS environment - mainly to shorten the expressions.
Note: You can peek at the extensions by opening the file fills.js

Constants:

const CR = "\r";
const LF = "\n";
const CRLF = CR + LF;
const EMPTY = "";

Runtime variables:

// Contains all data read to stdin (if any)
// type: string
const stdin;

// stdin.trim() result
// type: string
const tstdin;

// Contains command line arguments provided after // symbols (if any)
// type: string[]
const args;

Functions:

function log(...args); // console.log wrapper
function error(...args); // console.error wrapper that throws exception on call
function file(path, options?); // fs.readFileSync wrapper
function assert(expected, message?, chain?); // throws exception when 'expected' is not === true

Prototype extensions:

Object.prototype.json(reviver?) // JSON.parse wrapper for 'this' casted to string
Object.prototype.toJson(pretty?) // JSON.stringify wrapper with pretty print switch for 'this' object
Object.prototype.toFile(path, options?) // fs.writeFileSync wrapper with 'this' casted to string as the file contents
Object.prototype.ss // returns a 'ss' string wrapper (TODO: docs)

Why?

Someone may ask Why would one use alchemist when there are already tools like sed and awk?
As far as I am concerned, these tools are widely used and loved by the community, but they pose certain entry barriers for newbies. Alchemist provides ease of use for those who already had written some code in Javascript and do not want to spend time reading manuals.

TLDR: Manuals bad, Javascript good

License

The software is licensed under 3-Clause BSD NON-AI License.