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

pratjs

v1.6.3

Published

<div align="center"> <img src="assets/prat.svg" width="400" alt="Logo."/> </div>

Downloads

58

Readme

PratJS

Prat is a dialog system. PratJS is an interpreter of Prat, for the web.

Installation

npm i pratjs

Syntax highlighting

Prat is the official VSCode extension for Prat.

Demos

Basic usage

import { Prat } from 'pratjs';

const pratString = `
Hello, this is Prat!
\tHey, Prat!
\t\tIt's nice to meet you.
\tWhat is Prat?
\t\tPrat is a dialog system with some cool features.
`;

const prat = Prat.fromString(pratString);

prat.get();
/*
{
  statement: 'Hello, this is Prat!'
  responses: ['Hey, Prat!', 'What is Prat?']
  author: ''
}
*/
prat.print();
/*
Hello, this is Prat!
  (0) Hey, Prat!
  (1) What is Prat?
*/
prat.respond(1);
prat.print();
/*
Prat is a dialog system with some cool features.
*/

More examples may be seen below or in the tests.

API

class Prat {
  constructor(lines: PratLine[]);
  static fromString(pratString: string): Prat;
  get(): {
    statement: string;
    responses: string[];
    author: string;
  };
  getFromKey(key: string): {
    statement: string;
    responses: string[];
    author: string;
  };
  print(callback?: (result: string) => void): Prat;
  respond(responseIndex?: string | number): Prat;
  pushLine(line: PratLine): Prat;
  onEnd(callback: () => void): Prat;
  hasEnded(): boolean;
  resetContext(): Prat;
}

Prat docs

A Prat consists of statements and responses. A statement may lead to multiple selectable responses, but a response may only lead to one statement. An even number of tabs indicates a statement, and an odd number of tabs indicates a response.

This is a statement.
	This is a response.
		This statement will follow the first response.
	This is another response.
		This statement will follow the second response.
This statement will follow regardless of what response was selected.

Extensions

Any line may be extended by the following extensions. They are all on the form <symbol>{<content>}. The placement of an extension within a line does not matter (except for insertions). However, the convention is to place key and author symbols at the beginning and the rest at the end.

class PratSymbol {
  key = '#';
  goto = '>';
  author = '@';
  prepare = '!!';
  action = '!';
  condition = '?';
  insert = '$';
  comment = '%';
  inherit = '+';
  left = '{';
  right = '}';
}

Key: #{key}

By default, all lines are are assigned #<line number> as their key. This may be overridden with the key symbol.

#{main} The key of this line is 'main'

Goto: >{key}

By default, all lines lead to the following line. This may be changed with the goto symbol.

#{start}
This is an infinite loop.
>{start}

Author: @{author}

The author symbol is used to assign an author to the line. The author may be accessed with prat.get().author

@{Magne} The author of this line is 'Magne'

Prepare: !!{javascript}

The prepare symbol is used to run code at talk initialization. This is useful to initialize variables. $g indicates global context.

Let's initialize a global variable !!{$g.shouldSkipLine = true}

Action: !{javascript}

The action symbol is used to run code when a line is reached. This is useful to update variables.

Let's toggle this variable !{$g.shouldSkipLine = !$g.shouldSkipLine}

Condition: ?{javascript}

With the condition symbol, one may set conditions to when the line show be shown or skipped.

?{$g.shouldShowLine} This line is skipped if the local variable 'shouldShowLine' is false.

Insert: ${javascript}

With insertions, one may include dynamic content in a line.

!!{$g.age = '< 18'}
Are you over 18?
	Yes !{$g.age = '18+'}
	No
Your age is ${$g.age}.

Comment: %{comment}

This is part of the Prat %{but this will not be included.}

Inherit: +{key}

With the inherit symbol, a line may use extensions from another line. This is useful to prevent copying and pasting.

>{start}

%{Declarations}
#{showOnce} !!{$l.show = true} ?{$l.show} !{$l.show = false}

#{start}
Hello.
These lines will be shown in every loop.
But this line will only be shown in the first loop. +{showOnce}
These lines will be shown in every loop.
>{start}

Context

Variables should be assigned to global g or local l context. Global variables are accessible from the whole talk, while local variables are local to a single line. You may also access the Prat and PratLine instances from the talk with g.instance and l.instance, but this is highly experimental.