Extensible procedural text generation engine with dynamic, mutable state, indirection, randomizable & recursive variable expansions
npm install @thi.ng/proctext
!npm downloads

> [!NOTE]
> This is one of 214 standalone projects, maintained as part
> of the @thi.ng/umbrella monorepo
> and anti-framework.
>
> 🚀 Please help me to work full-time on these projects by sponsoring me on
> GitHub. Thank you! ❤️
- About
- Features
- Line comments
- Multi-value variables
- Recursive variable expansion
- Variable assignments
- Hidden assignments
- Dynamic, indirect variable references
- Modifiers
- Controlled randomness
- Status
- Installation
- Dependencies
- Usage examples
- API
- Authors
- License
Extensible procedural text generation engine with dynamic, mutable state, indirection, randomizable & recursive variable expansions.
> [!NOTE]
> The generated output of the code examples in this readme might vary due to the
> inherent randomness in the system. Please consult the controlled
> randomness section for further information about
> deterministic outputs.
The generator works with a simple plain text format, supporting the following
features:
Lines starting with # are comments and completely ignored, and invisible in
the output. No block comments are available.
Text generation and expansion relies on variables, which are defined inline
(inside the text given to the generator). New variables can be defined as
follows and each variable can define one or more possible values (one value per
line!):
``text`
[name]
alice
bob
ciara
If more than a single value is given, a semi-random
choice will be made for each instance/occurrence of the
var...
Variables are case-sensitive (i.e. NAME is a different var than name) and
can also be re-defined overridden in different parts of the document.
Variables are referenced via: . By default, an error will be thrown if amissing
variable cannot be resolved. Via the option given to generate() a
default fallback value can be defined, which when given will not trigger an
error in these cases.
> [!NOTE]
> The special variable reference can be used to produce an empty
> string (or used as single value placeholder option inside another variable
> definition). This variable can not be redefined.
`ts tangle:export/readme-intro.ts
import { generate } from "@thi.ng/proctext";
const { result } = await generate(
[name]
alice
bob
[action]
walked
cycled
ran
swam
[place]
office
shop
cafe
lake
[time]
this morning
last night
a week ago