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

turingjs

v1.1.3

Published

Turing.js is an Event-Driven-Language-Design-API based on the definition of a [turing machine](https://en.wikipedia.org/wiki/Turing_machine).

Downloads

29

Readme

CircleCI Npm dependancies

Turing.js logo

Turing.js

Turing.js is an Event-Driven-Language-Design-API based on the definition of a turing machine.

A Turing machine is an abstract machine that manipulates symbols on a strip of tape according to a table of rules. The machine operates on an infinite memory tape divided into discrete cells. The machine positions its head over a cell and "reads" the symbol there. Then, as per the symbol and its present place in a finite table of user-specified instructions, the machine (i) writes a symbol (e.g. a digit or a letter from a finite alphabet) in the cell, then (ii) either moves the tape one cell left or right, then (iii) (as determined by the observed symbol and the machine's place in the table) either proceeds to a subsequent instruction or halts the computation.

Typescript & Typings

Turing.js is written in and is designed to be used in Typescript, this means that Turing.js will always include its own typings. Because Turing.js comes with its own typings it lends it self very well to editors such as vs code that utilizes typings in both typescript and javascript to improve intellisense.

Links & Install

Install: npm i --save turingjs

Playground: https://runkit.com/olian04/turing-js-demo

Docs: https://olian04.github.io/Turing.js/

Demo

/* Super simple counter */
import { Language } from 'turingjs';

new Language<{ sum: number }>()
    .token({
        '+': state => { state.data.sum++ },
        '-': state => { state.data.sum-- }
    })
    .data({
        sum: 0
    })
    .run('++-+++--')
    .then(state => console.log(state.data.sum)/* 2 */);
    
/* The full Brainfuck language */
import { Language, GetTagFunction, Skip } from 'turingjs';

// Step 1: Define a new language
let brainfuck = new Language<{ in: string[], out: string[], loops: number[] }>()
    .token({
        '+': state => { state.stack[state.index]++ },
        '-': state => { state.stack[state.index]-- },
        '>': state => { state.index++ },
        '<': state => { state.index-- },
        ',': state => { state.stack[state.index] = state.data.in.shift().charCodeAt(0) },
        '.': state => { state.data.out.push(String.fromCharCode(state.stack[state.index])) },
        ']': (state, token) => { state.tokenPointer = state.data.loops.pop() - 1 },
        '[': (state, token) => {
            if (state.stack[state.index] === 0) {
                return Skip.until.balanced('[', ']', 1);
            }
            state.data.loops.push(token.position)
        }
    })
    .on('eof', state => state.data.loops.length === 0)
    .data({ in: [], out: [], loops: [] });

// Step 2: Run some code in the new language    
brainfuck
    .data({ in: 'ABC'.split('') })
    .run('+++[->,.+++.<]')
    .then(finalState => console.log(finalState.data.out.join(''))/* ADBECF */)
    .catch(error => console.log(error));

// Same thing as step 2, but using a tag function instead
let bf = GetTagFunction(brainfuck); //  Create tag function
let finalState = bf`+++[->,.+++.<]${{ in: 'ABC'.split('') }}`; // Run some code
console.log(finalState.data.out.join('')); // Get the output: ADBECF 

Developing

Built with

Tested with

Prerequisites

Setting up dev

git clone [email protected]:Olian04/Turing.js.git
cd Turing.js
npm install

Building

npm run build

Testing

npm run test

Publishing

Refer to: https://www.tsmean.com/articles/how-to-write-a-typescript-library/

Api reference

At the core of every Turing.js language lies a Language object, this object keeps track of what rules your language abides by. It is also this Language object that takes care of executing code written in your new language.

The Language object has 4 functions, each with several overloads, token, data, on, and run.

Function | Description ------|------------ token | Adds TokenHandlers, these are the bread and butter of your languages grammar. data | Provides a way of adding custom state properties to your language's interpreter. on | Adds event handlers for various events fired during an execution of code. run | Runs some code written in your new language.

For further reference please see the auto generated docs.

Credits

  • Logo: https://logomakr.com/6LYfIX