@thi.ng/proctext 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-07-19T14:56:21Z
3
+ - **Last updated**: 2024-07-22T13:15:57Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 189 standalone projects, maintained as part
10
+ > This is one of 198 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -22,6 +22,7 @@
22
22
  - [Variable assignments](#variable-assignments)
23
23
  - [Hidden assignments](#hidden-assignments)
24
24
  - [Dynamic, indirect variable references](#dynamic-indirect-variable-references)
25
+ - [Modifiers](#modifiers)
25
26
  - [Controlled randomness](#controlled-randomness)
26
27
  - [Status](#status)
27
28
  - [Installation](#installation)
@@ -166,9 +167,8 @@ console.log(result);
166
167
  ### Hidden assignments
167
168
 
168
169
  Normally, variable assignments are also causing the chosen value to be emitted
169
- as part of the generated text. Sometimes it is useful to _not_ do so and
170
- emission can be surpressed/hidden by using the prefix `!` as part of the
171
- assignment, like so:
170
+ as part of the generated text. Sometimes it's useful to _not_ do so and
171
+ suppress/hide output by using the prefix `!` as part of the assignment, like so:
172
172
 
173
173
  ```ts tangle:export/readme-hidden-var.ts
174
174
  import { generate } from "@thi.ng/proctext";
@@ -224,6 +224,73 @@ baking bread
224
224
 
225
225
  console.log(result);
226
226
 
227
+ // B is a baker, baking bread.
228
+ ```
229
+
230
+ ### Modifiers
231
+
232
+ Variable references can be optionally processed via one or more modifiers via
233
+ `<varname;mod>` or `<varname;mod1;mod2...>`. Each modifier is a simple async
234
+ function receiving a string and transforming it into another string. These
235
+ functions are async to allow modifiers consulting external data
236
+ sources/processes...
237
+
238
+ The following modifiers are provided by default:
239
+
240
+ - `uc`: uppercase
241
+ - `lc`: lowercase
242
+ - `cap`: capitalize
243
+
244
+ Custom modifiers can be provided via options given to `generate()`:
245
+
246
+ ```ts tangle:export/readme-modifiers.ts
247
+ import { generate } from "@thi.ng/proctext";
248
+
249
+ const DIRECTIONS = {
250
+ e: "east",
251
+ w: "west",
252
+ n: "north",
253
+ s: "south",
254
+ d: "down",
255
+ u: "up",
256
+ };
257
+
258
+ const ROOMS = {
259
+ house: {
260
+ desc: "very homely",
261
+ exits: { e: "garden", u: "rafters" },
262
+ },
263
+ rafters: {
264
+ desc: "pretty dark",
265
+ exits: { d: "house" },
266
+ },
267
+ garden: {
268
+ desc: "super lush",
269
+ exits: { w: "house" },
270
+ },
271
+ };
272
+
273
+ // partially data-driven template
274
+ const { result } = await generate(`
275
+ [room]
276
+ ${Object.keys(ROOMS).join("\n")}
277
+
278
+ You're in the <here=room> (exits: <here;exits;uc>)...
279
+ It feels <here;desc> here.
280
+ `, {
281
+ // custom modifiers (will be added to existing defaults)
282
+ mods: {
283
+ // produce a list of exits for given room ID
284
+ exits: async (id) => Object.keys(ROOMS[id].exits).map((dir) => DIRECTIONS[dir]).join(", "),
285
+ // return a room's description
286
+ desc: async (id) => ROOMS[id].desc
287
+ }
288
+ });
289
+
290
+ console.log(result);
291
+
292
+ // You're in the house (exits: EAST, UP)...
293
+ // It feels very homely here.
227
294
  ```
228
295
 
229
296
  ### Controlled randomness
@@ -297,12 +364,14 @@ Package sizes (brotli'd, pre-treeshake): ESM: 1.14 KB
297
364
 
298
365
  - [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
299
366
  - [@thi.ng/arrays](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays)
300
- - [@thi.ng/associative](https://github.com/thi-ng/umbrella/tree/develop/packages/associative)
301
367
  - [@thi.ng/defmulti](https://github.com/thi-ng/umbrella/tree/develop/packages/defmulti)
368
+ - [@thi.ng/object-utils](https://github.com/thi-ng/umbrella/tree/develop/packages/object-utils)
302
369
  - [@thi.ng/parse](https://github.com/thi-ng/umbrella/tree/develop/packages/parse)
303
370
  - [@thi.ng/random](https://github.com/thi-ng/umbrella/tree/develop/packages/random)
304
371
  - [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
305
372
 
373
+ Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
374
+
306
375
  ## Usage examples
307
376
 
308
377
  One project in this repo's
package/generate.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { peek } from "@thi.ng/arrays/peek";
2
- import { mergeDeepObj } from "@thi.ng/associative/merge-deep";
3
2
  import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
3
+ import { mergeDeepObj } from "@thi.ng/object-utils/merge-deep";
4
4
  import { defContext } from "@thi.ng/parse/context";
5
5
  import { defGrammar } from "@thi.ng/parse/grammar";
6
6
  import { SYSTEM } from "@thi.ng/random/system";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/proctext",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Extensible procedural text generation engine with dynamic, mutable state, indirection, randomizable & recursive variable expansions",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -27,7 +27,7 @@
27
27
  "build": "yarn build:esbuild && yarn build:decl",
28
28
  "build:decl": "tsc --declaration --emitDeclarationOnly",
29
29
  "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
30
- "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
30
+ "clean": "bun ../../tools/src/clean-package.ts",
31
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
32
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
33
33
  "doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
@@ -36,13 +36,13 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.6",
40
- "@thi.ng/arrays": "^2.9.11",
41
- "@thi.ng/associative": "^6.3.65",
42
- "@thi.ng/defmulti": "^3.0.44",
43
- "@thi.ng/parse": "^2.4.47",
44
- "@thi.ng/random": "^3.8.5",
45
- "@thi.ng/strings": "^3.8.0"
39
+ "@thi.ng/api": "^8.11.7",
40
+ "@thi.ng/arrays": "^2.9.13",
41
+ "@thi.ng/defmulti": "^3.0.45",
42
+ "@thi.ng/object-utils": "^1.1.0",
43
+ "@thi.ng/parse": "^2.4.48",
44
+ "@thi.ng/random": "^4.0.1",
45
+ "@thi.ng/strings": "^3.8.1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@microsoft/api-extractor": "^7.47.0",
@@ -82,5 +82,5 @@
82
82
  "status": "alpha",
83
83
  "year": 2023
84
84
  },
85
- "gitHead": "c7aaa453b01a45e5235517db9d2a283b97abac96\n"
85
+ "gitHead": "bd22b0826134b79064169371665b4d6caa9b6066\n"
86
86
  }