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

@kodeko/akita-core

v0.1.1

Published

A powerfull string interpreter

Downloads

30

Readme

@kodeko/akita-core

@kodeko/akita-core is a free-to-use string-based interpreter that allows people to develop packages with a simple syntax. The syntax is based on a keyword that represents a function, characters to indicate function opening and closing, and a character to separate arguments. A good analogy to use would be the way function calls are made, for example: myFunction(1, 2, 3), where "myFunction" is the keyword, "(" is the opening symbol, ")" is the closing symbol, and "," is the argument separator.

Installation

You can install @kodeko/akita-core using the following npm command:

npm install @kodeko/akita-core

Example

Once installed, you can use the akita interpreter in your project as follows:

import {
	akita_functions_mod,
	Interpreter,
	withPrefix,
} from "@kodeko/akita-core";

void (async function main() {
	// Load the defult functions and adds as prefix $
	await Interpreter.load_functions(akita_functions_mod, withPrefix("$"));
	// Creates a new Interpreter
	const itr = new Interpreter();
	// Sets the input to execute
	itr.lexer.set_input("$log[$get[great]]");
	// Executes the input
	await itr.solve({
		extra: {
			variables: {
				great: "Hello world!",
			},
		},
	});
})();
// result
Hello world!

In the above example, we import the interpreter and helpers and then execute a script represented by the string "$log[$get[great]]". The execute method of the akita interpreter will parse and execute the script, returning the result. In this case, the result will be logged to the console.

How Works?

The akita interpreter works through a lexer based on regular expressions, which detects keywords and their arguments. It then stores this information in objects and replaces their values with SYSTEM_FUNCTION(<unique id>). For example:

// Input
$log[$get[great]]
// Output
SYSTEM_RESULT(0)
// Object Data
[
  {
    id: 'SYSTEM_FUNCTION(0)',
    prototype: undefined,
    total: '$log[SYSTEM_FUNCTION(1)]',
    name: '$log',
    pos: 0,
    _id: 0,
    inside: 'SYSTEM_FUNCTION(1)',
    fields: [
      {
        value: 'SYSTEM_FUNCTION(1)',
        overloads: [
          {
            id: 'SYSTEM_FUNCTION(1)',
            prototype: undefined,
          }
        ]
      }
    ]
  }
]

In this case, SYSTEM_FUNCTION(1) represents the keyword $log, and inside $log is SYSTEM_FUNCTION(0), which is $object.

After this process, an array is traversed that executes the functions from top to bottom and from left to right. The value of each function is returned as SYSTEM_RESULT(<unique id>), allowing for handling of objects, numbers, classes, etc. First, it tries to execute $log, but since it contains within its arguments another function ($get), that one will be executed first. That is, that "always" the functions inside will be executed, and once that is executed, $log is executed.

// Final interpreter object data
{
  results: { 'SYSTEM_RESULT(1)': 'Hello world!', 'SYSTEM_RESULT(0)': '' },
  extra: { variables: { great: 'Hello world!' } },
  input: 'SYSTEM_RESULT(1)',
  parents: [],
  epd: null,
}

Additional Considerations


Enjoy using the package in your project! If you have any further questions or need more information, feel free to ask on my Discord DM or our Discord Server.