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

rtng

v0.3.1

Published

RTNG.js is a lightweight, template driven, and easy to use random text and number generator.

Downloads

1

Readme

rtng-js

0.3.1 (2023-02-09)

by Michael Kubina

https://github.com/michaelkubina/rtng-js

Description

RTNG.js is a lightweight and easy to use random text and number generator, that requires little programming knowledge. Of course it can be used with other libraries as well.

It's core features are:

  • primitive text & number types
  • custom templates and recursive template calls
  • organized in datapacks written in JSON notation
  • side-loading of external datapacks (recursive)
  • allows for using multiple instances simultaniously
  • accessing templates through paths in "dot.notation"
  • no dependencies

It can be used for different tasks, where you rely on varying random text and number output, e.g.:

  • creating fictive persons
  • creating characters
  • rolling dices, picking cards, drawing numbers
  • game scenario suggestions and challenges
  • pseudo reviews
  • custom games
  • etc.

In order to expand the possibilities further there are planned features like:

  • adding datetime type
  • adding number range type
  • scope of random generation
  • outputs being dependend of other template results (e.g. writing gender specific)
  • using templates as attributes for other templates
  • prevent recursive endless loops from happening
  • debugging information
  • returning raw values (string, array, int) as well instead/on top of parsed results

Usage

Using RTNG.js requires a valid datapack following the RTNG.js specific schema in JSON notation. It can be accessed and used through a variety of functions. The simplest way is described in these three steps.

1. Add the script to your page

<head>
    <script src="rtng-js/rtng.js"></script>
</head>

2. Load a datapack

async function myScript() {
            const example = await rtng.init('https://raw.githubusercontent.com/michaelkubina/rtng-js/main/example.json');

3. Parse a Template

            console.log(await example.parseTemplate("number.any-percent"));
            console.log(await example.parseTemplate("text.favourite-color"));
        }
        myScript();

Create your own RTNG.js datapack

A RTNG.js datapack is for the most part a hierarchical organized tree of templates, that by themselves are constructed from configurable data type primitives. The smallest possible datapack consists of one or more templates not being in any hierarchy at all. A template must have a sequence that should be parsed when called and that indicates, that its actually a template and not part of the hierarchy. A template must not have another hierarchy within it.

{
    ...
    "0-to-100": {          <-- a template
        "@sequence":[      <-- because it has a @sequence
            {
                ...
            }
        ]
    },
    ...
    "number": {            <-- a hierarchy, because it does not have a @sequence
        "any-percent": {       <-- a template within a hierarchy
            "@sequence":[      <-- because it has a @sequence
                {
                ...
                }
            ]
        },
    },
    ...
}

A "@sequence" is a list of configurable data primitive objects. The @ symbol is required to clearly distinguish it from not being a hierarchy of the name sequence. A sequence must not have any other than the allowed RTNG.js data types.

There are currently four primitive data types that have their own set of attributes, through which the output can be configured. The first two main data types are "number" and "string", where the former allows for one or more random number picks, and the latter one or more random text snippets from a list.

{
    ...
    "0-to-100": {
        "title": "A number from 0 to 100",
        "@sequence": [
            {
                "number": {
                "min": 0,
                "max": 100,
                "min_picks": 1
                }
            }
        ]
    },
    "3-colors": {
        "title": "Three colors from a list of ten",
        "@sequence": [
            {
                "string": {
                    "list": [
                        "red",
                        "green",
                        "blue",
                        "yellow",
                        "cyan",
                        "magenta",
                        "purple",
                        "pink",
                        "black",
                        "white"
                        ],
                    "min_picks": 2,
                    "max_picks": 4,
                    "unique": true,
                    "punctuation": ",",
                    "conjunction": "and"
                }
            }
        ]
    },

The other two data type are "raw", which is used for a direct string output, and most importantly the "template" data type. This allows for parsing another template directly into the template, that is currently being processed.

Adding a template means actually just writing the absolute path in dot.notation to another template within the datapack. The use of dot.notation for the names of your templates or hierarchies is not allowed, as it will break things. For readability benefits the use of kebab-case is encouraged instead.

    "number": {
        "any-percent": {
            "@sequence":[
                {
                    "template": "0-to-100"
                },
                {
                    "raw": "%"
                }
            ]
        },
    },
    "text": {
        "favourite-color": {
            "@sequence":[
                {
                    "raw": "Let me think about it... I am"
                },
                {
                    "template": "number.any-percent"
                },
                {
                    "raw": "sure that"
                },
                {
                    "template": "3-colors"
                },
                {
                    "raw": "are my favourite colors!"
                }
            ]
        }
    }
}

You are allowed to enrich the datapack with your JSON data as long as you follow the notation rules. This way you will not break things and will be able to retrieve the data through some RTNG.js functions as well.

{
    "metadata": {
        "title": "example.json",
        "author": "Michael Kubina",
        "description": "a small example datapack for RTNG.js",
        ...
    },
    ...
}

For a detailed overview of the functions and an in depth view on the data types, please visit the documentation.

version history

0.3.1

  • add initial documentation

0.3.0

  • change initialization method to static async factory function
  • add sideloading of external datapacks
  • add punctuation, conjunction and sorting options to number and string primitives
  • add some factory datapacks
  • update README.md
  • update example datapack

0.2.x

  • add README.md
  • add number, string, raw and template primitives
  • add pick options to number and string primitives
  • add example datapack

0.1.x

  • experimenting