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

@strbjun/mpi-parser

v0.1.0

Published

This is a simple lisp like parser for a personally created MPI syntax in TypeScript based on an MPI parsing system from the 90s.

Downloads

4

Readme

MPI Parser

This is a simple lisp like parser for a personally created MPI syntax in TypeScript based on an MPI parsing system from the 90s

How to handle

Install with: npm i @strbjun/mpi-parser

Then import MPI from the module. Then, you are ready to go!

Syntax

Its simple. It works as: {if:{eq:1,1},yes,no} which would return "yes" as 1 is equal to 1. So the format is:

{functionName:parameter, parameter, parameter}

But unlike older interpreters from the 90s, this one will have type safety built in. If the wrong output is given it will error out.

How to create more interpreters

This can be useful in case you want more local functions, though the global functions, variables, etc. will work across all interpreters.

This will be easily done by importing the Interpreter class and just declare a new one.

How to create new functions

There's two types. Global and local. Global will exist across all interpreters and local will only exist on the individually declared one.

  1. Local declaration:
MPI.registerFunction(name: string, fn: FunctionDefinition, aliases: string[])
  • name: This defines the function name used to call the function
  • aliases: As a string array can set alternative function names. Not required.
  • fn: This is an object containing:
    • fn: This is the function declaration itself. It can either be just a straightforward function declaration where all arguments are parsed and checked, or you can get greater control of it with a return function.
      • Straightforward declaration: This is done via just putting in a standard function and result return such as: (arg1: string, arg2: string) => arg1 + arg2... and, viola, done! Each argument will be evaluated outside of it.
      • Greater controlled declaration: Here you can pass an object to return the above standard declaration so that you can get access to the evaluator. This has to be enabled for this to be used which will be mentioned below. But when used you get access to the following object values:
        • evaluator: This is a function where you pass a value to evaluate. It can be any of the arguments or all.
        • validator: Allow validation for any arguments or all. You have to pass the arguments in an array first, then an array of strings for the explicit types they should be, followed by the function name.
        • types: The types set in the function will be passed here in order
        • obj: The current interpreter object
    • argTypes: You have to pass the explicit argument types. More can be added, but what exists in code are: boolean, string, number, float, and any. Plus you can add [] to the end to show it is an array, but if an array is used then it will just grab the rest of the arguments and ignore the rest of the types following it. If it ends in a ? then the argument is optional.
    • useOverlap: A boolean value defaulting to false. If set to true then it will enable the greater controlled function declaration mentioned above.
  1. Global declaration:

Use the registerGlobalFunction using the same parameters as the local declaration and it will make it available in all interpreters instead. Scoping will work as first running the local declaration and THEN the global one.

How to create variables

You can have global and local variables which work similarly as the function declarations.

  1. Local declaration:
MPI.setVariable(name: string, value: AllowableTypes)
  • name: This is the declaration name for the variable.
  • value: Whatever you want to set it to as a value
  1. Global declaration

Use MPI.setGlobalVariable instead using the same parameters.

How to create new types

With this you can create new argument types for the functions either globally or locally scoped.

  1. Local declaration:
MPI.registerArgType(name: string, fn: ArgValidateFn)
  • name: The declaration name for the argument type
  • fn: The function to verify any argument with that argument type. It just takes the argument, then returns a variable of true if it is the valid type or false for if it is not.

To do

  • Make it faster
  • And document the global functions better