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

nrpl

v0.1.0

Published

Navlost's Reverse Polish Language

Downloads

7

Readme

Introduction to NRPL

Description

NRPL is a stack-based language heavily inspired by Hewlett-Packard's RPL (from which it derives its name) and Forth. It was developed to give users the ability to do complex processing on their data server-side in a concise and secure manner.

Typical uses of NRPL are for querying, filtering, and transforming data. The language is general purpose, making it suitable for a variety of uses. This module was developed to fulfil the need for an interpreted that could be embedded in JavaScript applications to run untrusted, user-supplied code. For a full description of the language and its various options and commands, please refer to its complete specification.

How it works

NRPL programs are sequences of commands, literals, and variables, which take arguments from, and return results to, a stack[PDF]. Being based on Hewlett-Packard's RPN, it uses a postfix notation.

An example

Assume you would like to add the numbers 3 and 5 together:

Input

3 5 +

Output

   1:   8

Where 1: refers to the bottommost stack level and 8 is the result of the operation.

Another example (step by step)

Let us take a slightly more involved example, and calculate the volume of a sphere of radius 7.5, using the formula 4/3 π r3:

Input

4 3 / PI * 7.5 3 ^ *

Output

   1:   1767.1458676442585

The calculation happens as follows, step by step:

Description | Input | Stack ------------|-------|------- Enter the first number | 4 | 1: 4 Enter the second number | 3 | 2: 4 1: 3 Divide | / | 1: 1.3333333333333333 Enter the symbolic constant π | PI | 2: 1.3333333333333333 1: 3.141592653589793 Multiply | | 1: 4.1887902047863905 Enter the radius | 7.5 | 2: 4.1887902047863905 1: 7.5 Enter the exponent | 3 | 3: 4.1887902047863905 2: 7.5 1: 3 Exponentiate | ^ | 2: 4.1887902047863905 1: 421.875 Multiply | | 1: 1767.1458676442585

A feature of postfix notation is that parentheses are never required. As long as enough stack levels are available (NRPL has a conceptually infinite stack) calculations can be of any arbitrary complexity.

Installation

npm install nrpl

Calling


const NRPL = require('nrpl');

async function runInterpreter (script) {

	const nrpl = new NRPL(/*<Global Variable Getter>,*/ /*<Global Variable Setter>,*/ /*<Allow locals?>*/);
	
	return await nrpl.exec(script);
};


runInterpreter("3 2 +").then( (stack) => console.log("Three plus two equals", stack) );
// Three plus two equals [5]

Getting data in and out

Data is entered into the program via two mechanisms:

  1. Direct input into the stack, as we have seen above.
  2. Via variables, as we will see in a moment.

Retrieved may be retrieved from the stack or via assignment to global variables.

Variables

There are two types of variables: “global” and “local”, both of which may be enabled or disabled independently.

Global variables

These variables may be used to pass data into and out of the interpreter. For example, to persist data between calls. Globals may be read only, write only, read/write, or disabled altogether.

Local variables

These variables are used within a single execution call, their values being lost once the script returns.

Example instantiation with arguments


let variables = {
	UID: process.getuid(),
	GID: process.getgid(),
	PID: process.pid
}

function getVariable(name) {
	return variables.hasOwnProperty(name)
		? variables[name]
		: undefined;
}

function setVariable(name, value) {
	// For illustration, do not allow to change PID variable
	if (name && name != "PID") {
		variables[name] = value;
	}
}

// Preload the stack with some data
let stack = [
	process.cwd(),
	"Hello"
];

const script = '" user " $UID ++ SWAP !CURRENTDIR';

const nrpl = new NRPL(getVariable, setVariable, true);

nrpl.exec(script, stack).then(console.log);

console.log("VARIABLES", variables);

// When execution completes, the stack will contain a
// greeting similar to "Hello user 12345" and variables.CURRENTDIR
// will have been set to the processes' current working directory.

More information

For a full description of NRPL, please refer to the specification.