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

mdif

v0.0.5

Published

dialog/interactive fiction engine that lets you use markdown to describe conversations and games

Downloads

5

Readme

Markdown Interactive Fiction

This is a dialog/interactive fiction engine (for nodejs) that lets you describe conversations and games. It uses a subset of markdown to define your dialogs, and mustache to express light logic/formatting. It can be used in any sort of game/app that has dialog with (or without) logic.

usage

In your own project:

npm i mdif
import { promises as fs } from 'node:fs'
import { runDialog, getASTInfo } from 'mdif'

const md = await fs.readFile('example.md')

// read some info
console.log(getASTInfo(md).info)


// get the first line of dialog from "start"
const variables = {
  player: { name: 'Peter' },
  konsumer: { scared: false }
}
let screen = runDialog(md, 'start', variables)

// increment to the next page
screen = runDialog(md, 'start', variables, 1)

console.log(screen)

try it out here

git clone https://github.com/konsumer/mdif.git
cd mdif

npm i          # install deps & tools

npm start      # run examples/cli demo
npm run raylib # run examples/raylib demo
npm test       # run unit-tests in test.js, that also have some usage info

story reference

Essentially, you can use mustache for all logic, and markdown for the dialogs, which are made up of conversation, options, and code.

markdown

  • An h2 (##) defines a new dialog.
  • a blockquote (>) defines something someone is saying. Optionally, wrap "who" in italic: *Feindish Guy* Oh hey, my fellow feind
  • a list of links is options available at the end. It looks like this:
- [hmm?](#start)
- [yes](#thats_my_name)
- [no](#lie_about_name)
- [wait, how do you know my name?](#lie_about_name)

The URLs should be #id (to link to other dialogs) or file#id (to load a different conversation-collection.) This library doesn't manage that at all, so you will have to parse the url, in your code:


let md = await fs.readFile('example.md')

// user has progressed to page 1, which in this case has a menu (it's an id not in conversation lines)
let dialog = runDialog(md, 'start', variables, 1) 

// is this a menu or a line of text
if (Array.isArray(dialog)) {
  // ... show options and get user-selection here

  const [file, hash] = dialog[SELECTION].url.split('#')

  // it's another file, so set that to be the main md
  if (file) {
    md = await fs.readFile(file)
  }

  // load next dialog
  dialog = runDialog(md, hash, variables)
}

// do other stuff in loop, like show current dialog, allow user to progress, etc

code

Code is pulled out of codeblocks, like this (surround with 3 backticks, and set language):

player.happy = true

It is run when the individual dialog first loads. Currently, the only supported langage is js, but we may support more later.

frontmatter

You can use frontmatter to define any meta-information for the whole file. It goes at the top, and can be used externally with getASTInfo(md).info. We support TOML & YAML.

YAML:

---
name: My Cool World
friendly: true
---

TOML:

+++
preferred_language = 'TOML'
name = 'My Cool World'
+++

mustache

Go read the docs for more about how to use it, but essentially mustache is parsed before the dialog section is run, so you can insert logic based on your variables, like substitution, loops, condtionals, etc.