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

sweettext

v1.3.0

Published

A simple, custom narration library.

Downloads

21

Readme

NPM version

This library does not include a graphical interface, you must implement that yourself in something like the command line or an electron app, it's up to you.

Installation

$ npm install sweettext

Basic Usage

narrative.xml

<scene>
  <s>
    <text>
      Which color do you prefer?
    </text>
    <choice prompt="Red">
      <set color="red"/>
    </choice>
    <choice prompt="Blue">
      <set color="blue"/>
    </choice>
    <s>
      <text>
        You prefer the color v{color}!
      </text>
    </s>
  </s>
</scene>

index.js

const st = require('sweettext')

// Override onAddText
st.onAddText = function (text) {
  // TODO: Display text
}

// Override onAddChoice
st.onAddChoice = function (choice, i) {
  // TODO: Display choice
}

// Override
st.onAddChoiceListeners = function () {
  // TODO: Make a click/touch listener for each choice button and run st.next(i)
}

// Override onClearChoices
st.onClearChoices = function () {
  // TODO: Empty choice display, ready for new choices
}

// Override onFinish
st.onFinish = function () {
  // TODO: Display "THE END"
}

// Load from xml file
st.load(__dirname + '/narrative.xml');

Features

Sweets

'sweets' or s/choice tags are used as branches to the story often through choices. Each sweet goes through each of it's children as far as it can before returning and running the next one in order. For example:

<s>
  <text>
    One
  </text>
  <s>
    <text>
      Two
    </text>
  </s>
</s>
<s>
  <text>
    Three
  </text>
</s>

Output

One
Two
Three

Sweets can contain <choice>, <text>, <set>, <add> and <s> but it cannot contain <choice> and <s> at the same time as each <choice> would be ignored.

id & next

You can use the id and next properties to force the next sweet to be that which matches the id of another. However, this may not work as you'd expect. When next is set, it only runs after the children have run to a stop. For example:

<s next="three">
  <text>
    One
  </text>
  <s>
    <text>
      Two
    </text>
  </s>
</s>
<s>
  <text>
    This is skipped
  </text>
</s>
<s id="three">
  <text>
    Three
  </text>
</s>

Output

One
Two
Three

Conditions

Evaluate values of inserts to determine if a sweet should be skipped or a choice not displayed. Quotes around strings are not necessary.

<s>
  <set skip="true"/>
</s>
<s if="skip == false">
  <text>
    This will not show
  </text>
</s>

Choices

Choices display a prompt which a player selects in order to continue. It's contents are the same as that of a sweet and runs like one when selected.

<choice prompt="Do the thing">
  <text>
    🍋 The thing, the thing!
  </text>
</choice>

Set, Add

<set> and <add> manipulate values used as inserts in the story. There can only be one set and add per sweet/choice.

<set name="lemongrab"/>
<add angerLevel="1"/>

Inserts

Within <text> you have inserts where values are placed into the text, there are different kinds. Sets and adds always take place before the text.

Simple replacement

<set dog="Jake" human="Finn"/>
<text>
  v{dog} the dog
  and v{human} the human
</text>

output

Jake the dog
and Finn the human

Ternary replacement

<set isHuman="true"/>
<text>
  v{isHuman|Finn|Jake} the v{isHuman|Human|Dog}
</text>

output

Finn the Human

Inclusions

Additional scenes can be included from different scene xml files and accessed using next and id attributes on sweets and choices. The .xml is assumed and optional.

<include src="adventureTime.xml"/>
<include src="theGreatMushroomWar"/>

Contributing

Please drop in feature suggestions or bug reports to the github repository for this module. I would love to see what people make with this so tweet me @IAmSyntaxError.

Planned Features

  • Inventory management with inventory inserts i{thing}
  • Number based inserts <set val="1"/> v{val|zero|one|two|etc}
  • Run scripts on sweets/choices <script>function doStuff() { console.log('stuff') }</script>

License

MIT License Copyright © 2017 Austin "Felix" Lee