marlarky 1.0.1 → 1.0.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/README.md CHANGED
@@ -1,495 +1,503 @@
1
- # Marlarky
2
-
3
- **Generate syntactically plausible English nonsense, steered by lexicons.**
4
-
5
- Marlarky is a faker-like library and CLI that produces grammatically correct English text that sounds meaningful but isn't. Perfect for:
6
-
7
- - Placeholder text generation (like Lorem Ipsum, but in English)
8
- - Testing and mocking
9
- - Creative writing prompts
10
- - Procedural content generation
11
- - Corporate buzzword bingo
12
-
13
- ## Features
14
-
15
- - **Syntactically correct** -- Proper grammar, subject-verb agreement, punctuation
16
- - **Lexicon-driven** -- Guide output with custom vocabularies and style presets
17
- - **Deterministic** -- Seedable RNG for reproducible output
18
- - **Configurable** -- Control sentence types, lengths, complexity
19
- - **Output transforms** -- Pipe text through built-in transforms (Pig Latin, leet speak, pirate, and more)
20
- - **Traceable** -- Debug mode shows exactly how text was generated
21
- - **Full CLI** -- Generate text, apply transforms, and validate lexicons from the command line
22
- - **Zero dependencies** -- Works standalone or with @faker-js/faker
23
-
24
- ## Installation
25
-
26
- ```bash
27
- npm install marlarky
28
- ```
29
-
30
- ## Source Code & Issues
31
- **Source**: https://github.com/JPaulDuncan/malarky
32
- **Issues**: https://github.com/JPaulDuncan/malarky/issues
33
- **Additional Usage**: https://jpaulduncan.github.io/malarky/usage.md
34
- **License**: MIT
35
-
36
- ## Quick Start
37
-
38
- ### TypeScript / JavaScript
39
-
40
- ```typescript
41
- import { TextGenerator, SimpleFakerAdapter } from 'marlarky';
42
-
43
- const generator = new TextGenerator({
44
- fakerAdapter: new SimpleFakerAdapter(),
45
- });
46
-
47
- generator.setSeed(42);
48
-
49
- console.log(generator.sentence());
50
- // "Generally, the change called."
51
-
52
- console.log(generator.paragraph({ sentences: 3 }));
53
- // Three sentences of plausible nonsense
54
-
55
- console.log(generator.textBlock({ paragraphs: 2 }));
56
- // Two paragraphs of corporate-sounding marlarky
57
- ```
58
-
59
- ### Command Line
60
-
61
- ```bash
62
- # Generate a sentence
63
- marlarky sentence
64
-
65
- # Generate a deterministic question
66
- marlarky sentence --seed 42 --type question
67
-
68
- # Generate a paragraph with a corporate lexicon
69
- marlarky paragraph --sentences 5 --lexicon ./corp.json --archetype corporate
70
-
71
- # Apply Pig Latin transform and output as JSON
72
- marlarky sentence --seed 42 --transform pigLatin --json
73
- ```
74
-
75
- ## CLI
76
-
77
- After installing globally (`npm install -g marlarky`) or locally, the `marlarky` command is available.
78
-
79
- ### Commands
80
-
81
- | Command | Description |
82
- | ------------ | ----------------------------------------------- |
83
- | `sentence` | Generate one or more sentences |
84
- | `paragraph` | Generate one or more paragraphs |
85
- | `text` | Generate a text block (multiple paragraphs) |
86
- | `validate` | Validate a lexicon JSON file |
87
- | `list` | List available transforms or sentence types |
88
-
89
- ### Global Options
90
-
91
- These options work with `sentence`, `paragraph`, and `text`:
92
-
93
- | Option | Short | Description |
94
- | -------------------------- | ----- | -------------------------------------------------------- |
95
- | `--seed <n>` | `-s` | RNG seed for deterministic output |
96
- | `--lexicon <path>` | `-l` | Path to a lexicon JSON file |
97
- | `--archetype <name>` | `-a` | Archetype to activate from the lexicon |
98
- | `--transform <id>` | `-x` | Apply an output transform (repeatable, comma-separated) |
99
- | `--trace` | `-t` | Output JSON trace to stderr |
100
- | `--json` | `-j` | Output full result as JSON to stdout |
101
- | `--count <n>` | `-n` | Number of items to generate (default: 1) |
102
- | `--help` | `-h` | Show help |
103
- | `--version` | `-v` | Show version |
104
-
105
- ### Generating Sentences
106
-
107
- ```bash
108
- # Random sentence
109
- marlarky sentence
110
-
111
- # Specific type
112
- marlarky sentence --type question
113
- marlarky sentence --type compound
114
- marlarky sentence --type subordinate
115
-
116
- # Control word count
117
- marlarky sentence --min-words 10 --max-words 20
118
-
119
- # Multiple sentences
120
- marlarky sentence --count 5
121
-
122
- # With hints (activate lexicon tags)
123
- marlarky sentence --hints domain:tech,register:formal
124
- ```
125
-
126
- ### Generating Paragraphs
127
-
128
- ```bash
129
- # Random paragraph
130
- marlarky paragraph
131
-
132
- # Control sentence count
133
- marlarky paragraph --sentences 5
134
- marlarky paragraph --min-sentences 3 --max-sentences 8
135
-
136
- # Multiple paragraphs
137
- marlarky paragraph --count 3
138
- ```
139
-
140
- ### Generating Text Blocks
141
-
142
- ```bash
143
- # Random text block
144
- marlarky text
145
-
146
- # Control paragraph count
147
- marlarky text --paragraphs 4
148
- marlarky text --min-paragraphs 2 --max-paragraphs 6
149
- ```
150
-
151
- ### Applying Transforms
152
-
153
- Use `--transform` (or `-x`) to pipe generated text through built-in transforms:
154
-
155
- ```bash
156
- # Pig Latin
157
- marlarky sentence --seed 42 --transform pigLatin
158
- # "Enerallygay, ethay angechay alledcay."
159
-
160
- # Leet speak
161
- marlarky sentence --seed 42 --transform leet
162
-
163
- # Chain multiple transforms (comma-separated)
164
- marlarky sentence --seed 42 --transform leet,uwu
165
-
166
- # Or use repeated flags
167
- marlarky sentence --seed 42 -x pirate -x mockCase
168
- ```
169
-
170
- Run `marlarky list transforms` to see all available transforms.
171
-
172
- ### JSON Output
173
-
174
- Use `--json` (or `-j`) to get structured output including metadata and trace:
175
-
176
- ```bash
177
- marlarky sentence --seed 42 --json
178
- ```
179
-
180
- ```json
181
- {
182
- "text": "Generally, the change called.",
183
- "trace": { "..." : "..." },
184
- "meta": {
185
- "archetype": "default",
186
- "seed": 42
187
- }
188
- }
189
- ```
190
-
191
- ### Validating Lexicons
192
-
193
- ```bash
194
- # Human-readable output
195
- marlarky validate ./my-lexicon.json
196
-
197
- # Machine-readable JSON output
198
- marlarky validate ./my-lexicon.json --json
199
- ```
200
-
201
- ### Listing Available Features
202
-
203
- ```bash
204
- # List all output transforms
205
- marlarky list transforms
206
-
207
- # List all sentence types
208
- marlarky list types
209
-
210
- # Output as JSON
211
- marlarky list transforms --json
212
- ```
213
-
214
- ## Output Transforms
215
-
216
- Marlarky includes 10 built-in output transforms that modify generated text at the token level. All transforms are deterministic (same seed = same output) and safe to chain.
217
-
218
- | Transform | Description |
219
- | --------------- | ----------------------------------------- |
220
- | `pigLatin` | Classic Pig Latin |
221
- | `ubbiDubbi` | Ubbi Dubbi language game |
222
- | `leet` | Leetspeak character substitution |
223
- | `uwu` | Cute speak (w-substitution, suffixes) |
224
- | `pirate` | Pirate speak |
225
- | `redact` | Redact/mask words |
226
- | `emoji` | Add emoji replacements |
227
- | `mockCase` | rAnDoM cAsE aLtErNaTiOn |
228
- | `reverseWords` | Reverse word order |
229
- | `bizJargon` | Business jargon patterns |
230
-
231
- ### Using Transforms in Code
232
-
233
- ```typescript
234
- const result = generator.sentence({
235
- outputTransforms: {
236
- enabled: true,
237
- pipeline: [{ id: 'pigLatin' }],
238
- },
239
- });
240
- ```
241
-
242
- Transforms can also be configured at the lexicon level or per-archetype in your lexicon JSON. See the [usage guide](https://jpaulduncan.github.io/malarky/usage.md) for details.
243
-
244
- ## Sentence Types
245
-
246
- Marlarky generates six sentence structures:
247
-
248
- ```typescript
249
- // Simple declarative: "The system processes data."
250
- generator.sentence({ type: 'simpleDeclarative' });
251
-
252
- // Question: "Does the team deliver results?"
253
- generator.sentence({ type: 'question' });
254
-
255
- // Compound: "The strategy evolved, and the metrics improved."
256
- generator.sentence({ type: 'compound' });
257
-
258
- // Subordinate clause: "Because the pipeline scales, the throughput increases."
259
- generator.sentence({ type: 'subordinate' });
260
-
261
- // Intro adverbial: "Furthermore, the initiative drives innovation."
262
- generator.sentence({ type: 'introAdverbial' });
263
-
264
- // Interjection: "Indeed, the team delivered results."
265
- generator.sentence({ type: 'interjection' });
266
- ```
267
-
268
- ## Deterministic Output
269
-
270
- Same seed produces the same text every time:
271
-
272
- ```typescript
273
- generator.setSeed(12345);
274
- const a = generator.sentence();
275
-
276
- generator.setSeed(12345);
277
- const b = generator.sentence();
278
-
279
- console.log(a === b); // true
280
- ```
281
-
282
- From the CLI:
283
-
284
- ```bash
285
- marlarky sentence --seed 12345
286
- marlarky sentence --seed 12345
287
- # Both print the same sentence
288
- ```
289
-
290
- ## Custom Lexicons
291
-
292
- Create domain-specific marlarky with JSON lexicon files:
293
-
294
- ```json
295
- {
296
- "id": "lexicon.startup",
297
- "language": "en",
298
- "termSets": {
299
- "noun.startup": {
300
- "pos": "noun",
301
- "tags": ["domain:startup"],
302
- "terms": [
303
- { "value": "disruptor", "weight": 5 },
304
- { "value": "unicorn", "weight": 3 },
305
- { "value": "pivot", "weight": 4 },
306
- { "value": "runway", "weight": 2 }
307
- ]
308
- },
309
- "verb.startup": {
310
- "pos": "verb",
311
- "tags": ["domain:startup"],
312
- "terms": [
313
- { "value": "disrupt", "weight": 5 },
314
- { "value": "scale", "weight": 4 },
315
- { "value": "pivot", "weight": 3 },
316
- { "value": "iterate", "weight": 3 }
317
- ]
318
- }
319
- },
320
- "archetypes": {
321
- "startup": {
322
- "tags": ["domain:startup"]
323
- }
324
- }
325
- }
326
- ```
327
-
328
- Load it in code:
329
-
330
- ```typescript
331
- import { TextGenerator, SimpleFakerAdapter, loadLexiconFromString } from 'marlarky';
332
- import { readFileSync } from 'fs';
333
-
334
- const lexicon = loadLexiconFromString(readFileSync('./startup.json', 'utf-8'));
335
-
336
- const generator = new TextGenerator({
337
- fakerAdapter: new SimpleFakerAdapter(),
338
- lexicon,
339
- });
340
-
341
- generator.setArchetype('startup');
342
- console.log(generator.paragraph());
343
- ```
344
-
345
- Or from the CLI:
346
-
347
- ```bash
348
- marlarky paragraph --lexicon ./startup.json --archetype startup
349
- ```
350
-
351
- See the [usage guide](usage.md#lexicon-schema) for the full lexicon schema reference.
352
-
353
- ## Morphology Utilities
354
-
355
- Marlarky exports standalone English morphology functions:
356
-
357
- ```typescript
358
- import {
359
- pluralize,
360
- singularize,
361
- getPastTense,
362
- getPresentParticiple,
363
- getThirdPersonSingular,
364
- getIndefiniteArticle,
365
- } from 'marlarky';
366
-
367
- pluralize('synergy'); // "synergies"
368
- pluralize('child'); // "children"
369
- singularize('stakeholders'); // "stakeholder"
370
- getPastTense('leverage'); // "leveraged"
371
- getPastTense('go'); // "went"
372
- getPresentParticiple('run'); // "running"
373
- getThirdPersonSingular('do'); // "does"
374
- getIndefiniteArticle('hour'); // "an"
375
- getIndefiniteArticle('user'); // "a"
376
- ```
377
-
378
- ## With @faker-js/faker
379
-
380
- For more word variety, use the optional faker-js adapter:
381
-
382
- ```typescript
383
- import { TextGenerator, FakerJsAdapter } from 'marlarky';
384
- import { faker } from '@faker-js/faker';
385
-
386
- const generator = new TextGenerator({
387
- fakerAdapter: new FakerJsAdapter(faker),
388
- });
389
- ```
390
-
391
- `@faker-js/faker` is an optional peer dependency -- Marlarky works without it using the built-in `SimpleFakerAdapter`.
392
-
393
- ## Configuration
394
-
395
- Fine-tune generation behavior:
396
-
397
- ```typescript
398
- const generator = new TextGenerator({
399
- fakerAdapter: new SimpleFakerAdapter(),
400
- config: {
401
- minWordsPerSentence: 10,
402
- maxWordsPerSentence: 25,
403
- minSentencesPerParagraph: 3,
404
- maxSentencesPerParagraph: 6,
405
- questionRate: 0.05,
406
- compoundRate: 0.20,
407
- subordinateClauseRate: 0.15,
408
- maxPPChain: 2,
409
- maxAdjectivesPerNoun: 2,
410
- },
411
- });
412
- ```
413
-
414
- See the [usage guide](usage.md#configuration) for all configuration options.
415
-
416
- ## Tracing
417
-
418
- Enable trace mode to see how text was generated:
419
-
420
- ```typescript
421
- const generator = new TextGenerator({
422
- fakerAdapter: new SimpleFakerAdapter(),
423
- enableTrace: true,
424
- });
425
-
426
- const result = generator.sentence();
427
-
428
- console.log(result.text);
429
- // "The robust system efficiently processes data."
430
-
431
- console.log(result.trace.paragraphs[0].sentences[0].template);
432
- // "simpleDeclarative"
433
-
434
- console.log(result.trace.paragraphs[0].sentences[0].tokens);
435
- // [{ value: "The", source: "default" }, { value: "robust", source: "adj.business" }, ...]
436
- ```
437
-
438
- From the CLI, use `--trace` to send trace data to stderr, or `--json` to include it in structured stdout output.
439
-
440
- ## Examples
441
-
442
- ```bash
443
- # Run the basic usage example
444
- npm run example:basic
445
-
446
- # Run the corporate lexicon example
447
- npm run example:corporate
448
- ```
449
-
450
- ## Development
451
-
452
- ```bash
453
- # Install dependencies
454
- npm install
455
-
456
- # Build
457
- npm run build
458
-
459
- # Run tests (watch mode)
460
- npm test
461
-
462
- # Run tests once
463
- npm run test:run
464
-
465
- # Run tests with coverage
466
- npm run test:coverage
467
-
468
- # Lint
469
- npm run lint
470
- ```
471
-
472
- ## API Summary
473
-
474
- For the complete API reference including all types, interfaces, and configuration options, see the [usage guide](usage.md).
475
-
476
- | Method / Function | Description |
477
- | ----------------------------- | ---------------------------------------- |
478
- | `new TextGenerator(opts)` | Create a generator instance |
479
- | `generator.sentence(opts?)` | Generate one sentence |
480
- | `generator.paragraph(opts?)` | Generate a paragraph (2-7 sentences) |
481
- | `generator.textBlock(opts?)` | Generate multiple paragraphs |
482
- | `generator.setSeed(n)` | Set RNG seed for reproducibility |
483
- | `generator.setLexicon(lex)` | Load or replace a lexicon at runtime |
484
- | `generator.setArchetype(name)`| Activate a style preset |
485
- | `validateLexicon(obj)` | Validate a lexicon object |
486
- | `loadLexiconFromString(json)` | Parse a lexicon JSON string |
487
-
488
- ## License
489
-
490
- MIT
491
-
492
- ---
493
-
494
- _"Leveraging synergistic paradigms to facilitate robust deliverables across the ecosystem."_
495
- -- marlarky
1
+ # Marlarky
2
+
3
+ **Generate syntactically plausible English nonsense, steered by lexicons.**
4
+
5
+ Marlarky is a faker-like library and CLI that produces grammatically correct English text that sounds meaningful but isn't. Perfect for:
6
+
7
+ - Placeholder text generation (like Lorem Ipsum, but in English)
8
+ - Testing and mocking
9
+ - Creative writing prompts
10
+ - Procedural content generation
11
+ - Corporate buzzword bingo
12
+
13
+ ## Features
14
+
15
+ - **Syntactically correct** -- Proper grammar, subject-verb agreement, punctuation
16
+ - **Lexicon-driven** -- Guide output with custom vocabularies and style presets
17
+ - **Deterministic** -- Seedable RNG for reproducible output
18
+ - **Configurable** -- Control sentence types, lengths, complexity
19
+ - **Output transforms** -- Pipe text through built-in transforms (Pig Latin, leet speak, pirate, and more)
20
+ - **Traceable** -- Debug mode shows exactly how text was generated
21
+ - **Full CLI** -- Generate text, apply transforms, and validate lexicons from the command line
22
+ - **Zero dependencies** -- Works standalone or with @faker-js/faker
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install marlarky
28
+ ```
29
+
30
+ ## Source Code & Issues
31
+
32
+ **Source**: https://github.com/JPaulDuncan/marlarky
33
+
34
+ **Issues**: https://github.com/JPaulDuncan/marlarky/issues
35
+
36
+ **Additional Usage**: https://jpaulduncan.github.io/marlarky/usage.md
37
+
38
+ **License**: MIT
39
+
40
+ ## Quick Start
41
+
42
+ ### TypeScript / JavaScript
43
+
44
+ ```typescript
45
+ import { TextGenerator, SimpleFakerAdapter } from 'marlarky';
46
+
47
+ const generator = new TextGenerator({
48
+ fakerAdapter: new SimpleFakerAdapter(),
49
+ });
50
+
51
+ generator.setSeed(42);
52
+
53
+ console.log(generator.sentence());
54
+ // "Generally, the change called."
55
+
56
+ console.log(generator.paragraph({ sentences: 3 }));
57
+ // Three sentences of plausible nonsense
58
+
59
+ console.log(generator.textBlock({ paragraphs: 2 }));
60
+ // Two paragraphs of corporate-sounding marlarky
61
+ ```
62
+
63
+ ### Command Line
64
+
65
+ ```bash
66
+ # Generate a sentence
67
+ marlarky sentence
68
+
69
+ # Generate a deterministic question
70
+ marlarky sentence --seed 42 --type question
71
+
72
+ # Generate a paragraph with a corporate lexicon
73
+ marlarky paragraph --sentences 5 --lexicon ./corp.json --archetype corporate
74
+
75
+ # Apply Pig Latin transform and output as JSON
76
+ marlarky sentence --seed 42 --transform pigLatin --json
77
+ ```
78
+
79
+ ## CLI
80
+
81
+ After installing globally (`npm install -g marlarky`) or locally, the `marlarky` command is available.
82
+
83
+ ### Commands
84
+
85
+ | Command | Description |
86
+ | ----------- | ------------------------------------------- |
87
+ | `sentence` | Generate one or more sentences |
88
+ | `paragraph` | Generate one or more paragraphs |
89
+ | `text` | Generate a text block (multiple paragraphs) |
90
+ | `validate` | Validate a lexicon JSON file |
91
+ | `list` | List available transforms or sentence types |
92
+
93
+ ### Global Options
94
+
95
+ These options work with `sentence`, `paragraph`, and `text`:
96
+
97
+ | Option | Short | Description |
98
+ | -------------------- | ----- | ------------------------------------------------------- |
99
+ | `--seed <n>` | `-s` | RNG seed for deterministic output |
100
+ | `--lexicon <path>` | `-l` | Path to a lexicon JSON file |
101
+ | `--archetype <name>` | `-a` | Archetype to activate from the lexicon |
102
+ | `--transform <id>` | `-x` | Apply an output transform (repeatable, comma-separated) |
103
+ | `--trace` | `-t` | Output JSON trace to stderr |
104
+ | `--json` | `-j` | Output full result as JSON to stdout |
105
+ | `--count <n>` | `-n` | Number of items to generate (default: 1) |
106
+ | `--help` | `-h` | Show help |
107
+ | `--version` | `-v` | Show version |
108
+
109
+ ### Generating Sentences
110
+
111
+ ```bash
112
+ # Random sentence
113
+ marlarky sentence
114
+
115
+ # Specific type
116
+ marlarky sentence --type question
117
+ marlarky sentence --type compound
118
+ marlarky sentence --type subordinate
119
+
120
+ # Control word count
121
+ marlarky sentence --min-words 10 --max-words 20
122
+
123
+ # Multiple sentences
124
+ marlarky sentence --count 5
125
+
126
+ # With hints (activate lexicon tags)
127
+ marlarky sentence --hints domain:tech,register:formal
128
+ ```
129
+
130
+ ### Generating Paragraphs
131
+
132
+ ```bash
133
+ # Random paragraph
134
+ marlarky paragraph
135
+
136
+ # Control sentence count
137
+ marlarky paragraph --sentences 5
138
+ marlarky paragraph --min-sentences 3 --max-sentences 8
139
+
140
+ # Multiple paragraphs
141
+ marlarky paragraph --count 3
142
+ ```
143
+
144
+ ### Generating Text Blocks
145
+
146
+ ```bash
147
+ # Random text block
148
+ marlarky text
149
+
150
+ # Control paragraph count
151
+ marlarky text --paragraphs 4
152
+ marlarky text --min-paragraphs 2 --max-paragraphs 6
153
+ ```
154
+
155
+ ### Applying Transforms
156
+
157
+ Use `--transform` (or `-x`) to pipe generated text through built-in transforms:
158
+
159
+ ```bash
160
+ # Pig Latin
161
+ marlarky sentence --seed 42 --transform pigLatin
162
+ # "Enerallygay, ethay angechay alledcay."
163
+
164
+ # Leet speak
165
+ marlarky sentence --seed 42 --transform leet
166
+
167
+ # Chain multiple transforms (comma-separated)
168
+ marlarky sentence --seed 42 --transform leet,uwu
169
+
170
+ # Or use repeated flags
171
+ marlarky sentence --seed 42 -x pirate -x mockCase
172
+ ```
173
+
174
+ Run `marlarky list transforms` to see all available transforms.
175
+
176
+ ### JSON Output
177
+
178
+ Use `--json` (or `-j`) to get structured output including metadata and trace:
179
+
180
+ ```bash
181
+ marlarky sentence --seed 42 --json
182
+ ```
183
+
184
+ ```json
185
+ {
186
+ "text": "Generally, the change called.",
187
+ "trace": { "...": "..." },
188
+ "meta": {
189
+ "archetype": "default",
190
+ "seed": 42
191
+ }
192
+ }
193
+ ```
194
+
195
+ ### Validating Lexicons
196
+
197
+ ```bash
198
+ # Human-readable output
199
+ marlarky validate ./my-lexicon.json
200
+
201
+ # Machine-readable JSON output
202
+ marlarky validate ./my-lexicon.json --json
203
+ ```
204
+
205
+ ### Listing Available Features
206
+
207
+ ```bash
208
+ # List all output transforms
209
+ marlarky list transforms
210
+
211
+ # List all sentence types
212
+ marlarky list types
213
+
214
+ # Output as JSON
215
+ marlarky list transforms --json
216
+ ```
217
+
218
+ ## Output Transforms
219
+
220
+ Marlarky includes 10 built-in output transforms that modify generated text at the token level. All transforms are deterministic (same seed = same output) and safe to chain.
221
+
222
+ | Transform | Description |
223
+ | -------------- | ------------------------------------- |
224
+ | `pigLatin` | Classic Pig Latin |
225
+ | `ubbiDubbi` | Ubbi Dubbi language game |
226
+ | `leet` | Leetspeak character substitution |
227
+ | `uwu` | Cute speak (w-substitution, suffixes) |
228
+ | `pirate` | Pirate speak |
229
+ | `redact` | Redact/mask words |
230
+ | `emoji` | Add emoji replacements |
231
+ | `mockCase` | rAnDoM cAsE aLtErNaTiOn |
232
+ | `reverseWords` | Reverse word order |
233
+ | `bizJargon` | Business jargon patterns |
234
+
235
+ ### Using Transforms in Code
236
+
237
+ ```typescript
238
+ const result = generator.sentence({
239
+ outputTransforms: {
240
+ enabled: true,
241
+ pipeline: [{ id: 'pigLatin' }],
242
+ },
243
+ });
244
+ ```
245
+
246
+ Transforms can also be configured at the lexicon level or per-archetype in your lexicon JSON. See the [usage guide](https://jpaulduncan.github.io/marlarky/usage.md) for details.
247
+
248
+ ## Sentence Types
249
+
250
+ Marlarky generates six sentence structures:
251
+
252
+ ```typescript
253
+ // Simple declarative: "The system processes data."
254
+ generator.sentence({ type: 'simpleDeclarative' });
255
+
256
+ // Question: "Does the team deliver results?"
257
+ generator.sentence({ type: 'question' });
258
+
259
+ // Compound: "The strategy evolved, and the metrics improved."
260
+ generator.sentence({ type: 'compound' });
261
+
262
+ // Subordinate clause: "Because the pipeline scales, the throughput increases."
263
+ generator.sentence({ type: 'subordinate' });
264
+
265
+ // Intro adverbial: "Furthermore, the initiative drives innovation."
266
+ generator.sentence({ type: 'introAdverbial' });
267
+
268
+ // Interjection: "Indeed, the team delivered results."
269
+ generator.sentence({ type: 'interjection' });
270
+ ```
271
+
272
+ ## Deterministic Output
273
+
274
+ Same seed produces the same text every time:
275
+
276
+ ```typescript
277
+ generator.setSeed(12345);
278
+ const a = generator.sentence();
279
+
280
+ generator.setSeed(12345);
281
+ const b = generator.sentence();
282
+
283
+ console.log(a === b); // true
284
+ ```
285
+
286
+ From the CLI:
287
+
288
+ ```bash
289
+ marlarky sentence --seed 12345
290
+ marlarky sentence --seed 12345
291
+ # Both print the same sentence
292
+ ```
293
+
294
+ ## Custom Lexicons
295
+
296
+ Create domain-specific marlarky with JSON lexicon files:
297
+
298
+ ```json
299
+ {
300
+ "id": "lexicon.startup",
301
+ "language": "en",
302
+ "termSets": {
303
+ "noun.startup": {
304
+ "pos": "noun",
305
+ "tags": ["domain:startup"],
306
+ "terms": [
307
+ { "value": "disruptor", "weight": 5 },
308
+ { "value": "unicorn", "weight": 3 },
309
+ { "value": "pivot", "weight": 4 },
310
+ { "value": "runway", "weight": 2 }
311
+ ]
312
+ },
313
+ "verb.startup": {
314
+ "pos": "verb",
315
+ "tags": ["domain:startup"],
316
+ "terms": [
317
+ { "value": "disrupt", "weight": 5 },
318
+ { "value": "scale", "weight": 4 },
319
+ { "value": "pivot", "weight": 3 },
320
+ { "value": "iterate", "weight": 3 }
321
+ ]
322
+ }
323
+ },
324
+ "archetypes": {
325
+ "startup": {
326
+ "tags": ["domain:startup"]
327
+ }
328
+ }
329
+ }
330
+ ```
331
+
332
+ Load it in code:
333
+
334
+ ```typescript
335
+ import {
336
+ TextGenerator,
337
+ SimpleFakerAdapter,
338
+ loadLexiconFromString,
339
+ } from 'marlarky';
340
+ import { readFileSync } from 'fs';
341
+
342
+ const lexicon = loadLexiconFromString(readFileSync('./startup.json', 'utf-8'));
343
+
344
+ const generator = new TextGenerator({
345
+ fakerAdapter: new SimpleFakerAdapter(),
346
+ lexicon,
347
+ });
348
+
349
+ generator.setArchetype('startup');
350
+ console.log(generator.paragraph());
351
+ ```
352
+
353
+ Or from the CLI:
354
+
355
+ ```bash
356
+ marlarky paragraph --lexicon ./startup.json --archetype startup
357
+ ```
358
+
359
+ See the [usage guide](usage.md#lexicon-schema) for the full lexicon schema reference.
360
+
361
+ ## Morphology Utilities
362
+
363
+ Marlarky exports standalone English morphology functions:
364
+
365
+ ```typescript
366
+ import {
367
+ pluralize,
368
+ singularize,
369
+ getPastTense,
370
+ getPresentParticiple,
371
+ getThirdPersonSingular,
372
+ getIndefiniteArticle,
373
+ } from 'marlarky';
374
+
375
+ pluralize('synergy'); // "synergies"
376
+ pluralize('child'); // "children"
377
+ singularize('stakeholders'); // "stakeholder"
378
+ getPastTense('leverage'); // "leveraged"
379
+ getPastTense('go'); // "went"
380
+ getPresentParticiple('run'); // "running"
381
+ getThirdPersonSingular('do'); // "does"
382
+ getIndefiniteArticle('hour'); // "an"
383
+ getIndefiniteArticle('user'); // "a"
384
+ ```
385
+
386
+ ## With @faker-js/faker
387
+
388
+ For more word variety, use the optional faker-js adapter:
389
+
390
+ ```typescript
391
+ import { TextGenerator, FakerJsAdapter } from 'marlarky';
392
+ import { faker } from '@faker-js/faker';
393
+
394
+ const generator = new TextGenerator({
395
+ fakerAdapter: new FakerJsAdapter(faker),
396
+ });
397
+ ```
398
+
399
+ `@faker-js/faker` is an optional peer dependency -- Marlarky works without it using the built-in `SimpleFakerAdapter`.
400
+
401
+ ## Configuration
402
+
403
+ Fine-tune generation behavior:
404
+
405
+ ```typescript
406
+ const generator = new TextGenerator({
407
+ fakerAdapter: new SimpleFakerAdapter(),
408
+ config: {
409
+ minWordsPerSentence: 10,
410
+ maxWordsPerSentence: 25,
411
+ minSentencesPerParagraph: 3,
412
+ maxSentencesPerParagraph: 6,
413
+ questionRate: 0.05,
414
+ compoundRate: 0.2,
415
+ subordinateClauseRate: 0.15,
416
+ maxPPChain: 2,
417
+ maxAdjectivesPerNoun: 2,
418
+ },
419
+ });
420
+ ```
421
+
422
+ See the [usage guide](usage.md#configuration) for all configuration options.
423
+
424
+ ## Tracing
425
+
426
+ Enable trace mode to see how text was generated:
427
+
428
+ ```typescript
429
+ const generator = new TextGenerator({
430
+ fakerAdapter: new SimpleFakerAdapter(),
431
+ enableTrace: true,
432
+ });
433
+
434
+ const result = generator.sentence();
435
+
436
+ console.log(result.text);
437
+ // "The robust system efficiently processes data."
438
+
439
+ console.log(result.trace.paragraphs[0].sentences[0].template);
440
+ // "simpleDeclarative"
441
+
442
+ console.log(result.trace.paragraphs[0].sentences[0].tokens);
443
+ // [{ value: "The", source: "default" }, { value: "robust", source: "adj.business" }, ...]
444
+ ```
445
+
446
+ From the CLI, use `--trace` to send trace data to stderr, or `--json` to include it in structured stdout output.
447
+
448
+ ## Examples
449
+
450
+ ```bash
451
+ # Run the basic usage example
452
+ npm run example:basic
453
+
454
+ # Run the corporate lexicon example
455
+ npm run example:corporate
456
+ ```
457
+
458
+ ## Development
459
+
460
+ ```bash
461
+ # Install dependencies
462
+ npm install
463
+
464
+ # Build
465
+ npm run build
466
+
467
+ # Run tests (watch mode)
468
+ npm test
469
+
470
+ # Run tests once
471
+ npm run test:run
472
+
473
+ # Run tests with coverage
474
+ npm run test:coverage
475
+
476
+ # Lint
477
+ npm run lint
478
+ ```
479
+
480
+ ## API Summary
481
+
482
+ For the complete API reference including all types, interfaces, and configuration options, see the [usage guide](usage.md).
483
+
484
+ | Method / Function | Description |
485
+ | ------------------------------ | ------------------------------------ |
486
+ | `new TextGenerator(opts)` | Create a generator instance |
487
+ | `generator.sentence(opts?)` | Generate one sentence |
488
+ | `generator.paragraph(opts?)` | Generate a paragraph (2-7 sentences) |
489
+ | `generator.textBlock(opts?)` | Generate multiple paragraphs |
490
+ | `generator.setSeed(n)` | Set RNG seed for reproducibility |
491
+ | `generator.setLexicon(lex)` | Load or replace a lexicon at runtime |
492
+ | `generator.setArchetype(name)` | Activate a style preset |
493
+ | `validateLexicon(obj)` | Validate a lexicon object |
494
+ | `loadLexiconFromString(json)` | Parse a lexicon JSON string |
495
+
496
+ ## License
497
+
498
+ MIT
499
+
500
+ ---
501
+
502
+ _"Leveraging synergistic paradigms to facilitate robust deliverables across the ecosystem."_
503
+ -- marlarky