rantjs 1.0.10 → 2.0.0

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2014-2026 Sven Anders Robbestad
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,158 +1,144 @@
1
1
  # Rantjs
2
2
 
3
- Rantjs is a procedural text generator. The goal is to augment human creativity with the boundless potential of randomness. Inspired by [Rant][1].
3
+ Procedural text for JavaScript. Write a pattern, get a sentence.
4
4
 
5
- <img src="http://res.cloudinary.com/sven-anders-robbestad/image/upload/c_scale,w_350/v1418975366/rantjs_0.8.4.png">
5
+ Inspired by [Rant](https://github.com/TheBerkin/rant3). This is the Rantjs dialect (`<noun>`, `[rep:3]{...}`), not a Rant 4 VM.
6
6
 
7
- The project is available via npm (do _npm install rantjs_).
7
+ ```js
8
+ import { rant } from "rantjs";
8
9
 
10
+ const sentence = rant(
11
+ "<firstname male> likes to <verb-transitive> <noun.plural> with <pron poss male> pet <noun-animal> on <timenoun dayofweek plural>.",
12
+ );
9
13
 
10
- ## Demo and more information
11
-
12
- Interactive demo available [here][5]
13
-
14
- Click [here][4] for a writeup on my blog
15
-
16
-
17
- ## Usage
18
-
19
- # When using the npm module
20
-
21
- var rant = require("rantjs");
22
- var sentence=rant('<firstname male> likes to <verb-transitive> <noun.plural> with <pron poss male> pet <noun-animal> on <timenoun dayofweek plural>.');
23
-
24
- console.log(sentence); // 'Sean likes to chop parrots with his pet cat on Saturdays.'
25
-
26
- For implementation details, please visit the [npmjs page][3]
27
-
28
- # When using the CDN version at https://cdnjs.com/libraries/rantjs
29
-
30
- <script src="https://cdnjs.cloudflare.com/ajax/libs/rantjs/1.0.6/rant.min.js">
31
- <script type="text/javascript">
32
- var sentence=rant('<firstname male> likes to <verb-transitive> <noun.plural> with <pron poss male> pet <noun-animal> on <timenoun dayofweek plural>.');
33
- console.log(sentence); // 'Sean likes to chop parrots with his pet cat on Saturdays.'
34
- document.querySelector('#app').textContent=sentence;
35
- </script>
36
-
37
- ## Install
14
+ console.log(sentence);
15
+ // 'Sean likes to chop parrots with his pet cat on Saturdays.'
16
+ ```
38
17
 
39
18
  ```bash
40
- git clone https://github.com/svenanders/rantjs && cd rantjs
41
- npm i
42
- gulp serve
19
+ npm install rantjs
20
+ npx rantjs --seed 42 '<firstname male> found [a] <noun-animal>.'
43
21
  ```
44
- Then open http://localhost:8000
45
-
46
-
47
- ## Development Plan
48
-
49
- Easy way to choose alternative dictionaries
50
-
51
- Indefinite article (a/an) automation
52
-
53
- Overwriting (targets)
54
22
 
55
- ~~Capitalisation~~
23
+ ## Patterns
56
24
 
57
- ~~Looping (repeaters)~~
25
+ **Queries** pull a random dictionary entry. Filters and inflections can be separated with a space, dash, or dot:
58
26
 
59
- Conditionals
60
-
61
- ## Contributions
62
-
63
- Contributions are welcome. Feel free to submit an issue/pull request. The following areas are
64
- of particular interest:
27
+ ```
28
+ <firstname male>
29
+ <noun-animal plural>
30
+ <verb.ed>
31
+ <pron poss male>
32
+ <yn yes>
33
+ ```
65
34
 
66
- Documentation (wiki/code)
35
+ **Blocks** choose an alternative. A block with no repeater runs once. `|` splits options. Nested braces work.
67
36
 
68
- Fixing bugs
37
+ ```
38
+ {heads|tails}
39
+ {Example text}
40
+ [rep:3][sep:\s]{click|clack}
41
+ ```
69
42
 
70
- Optimization
43
+ **Tags**
71
44
 
72
- Functions in the development plan
45
+ | Tag | Effect |
46
+ | --- | --- |
47
+ | `[case:none\|default\|first\|word\|title\|upper\|lower\|sentence]` | Casing for the finished string |
48
+ | `[rep:n]` | Repeat the next block `n` times |
49
+ | `[sep:\s\|\n\|literal]` | Join those repetitions |
50
+ | `[a]` | Insert *a* or *an* before the next word |
51
+ | `[if:name]{then}{else}` | Branch on whether carrier `name` is set |
73
52
 
74
- New language features
53
+ **Carriers** remember a result so a character stays the same person:
75
54
 
76
- Testing. Currently, this is the result of the coverage report:
55
+ ```
56
+ <firstname male :: hero> saw <::hero> in the <place>.
57
+ ```
77
58
 
78
- Statements : 96.44% ( 461/478 )
79
- Branches : 67.65% ( 46/68 )
80
- Functions : 100% ( 18/18 )
81
- Lines : 97.24% ( 458/471 )
59
+ **Escapes:** `\C` is a random A–Z letter.
82
60
 
83
- Ideally, it should be 100% on everything
61
+ NSFW entries are omitted unless the query asks (`<noun nsfw>`) or you pass `{ nsfw: true }`.
84
62
 
85
- ## New in version 1.0.0
63
+ ## API
86
64
 
87
- Added option for custom dictionaries. Note that this replaces the built-in dictionary.
88
-
89
- var yourCustomDic = {}
90
- ...
91
- rant('your text', yourCustomDic);
92
-
93
- A sample dictionary file can be found in the ./src folder. Also take a look at the built-in english dicionary in the same folder for reference.
65
+ ```ts
66
+ import { rant, createRant, enUS } from "rantjs";
94
67
 
95
- ## New in version 0.9.x
68
+ rant(pattern);
69
+ rant(pattern, { seed: 42 });
70
+ rant(pattern, { seed: "chapter-1", nsfw: false, dictionary: enUS });
71
+ rant(pattern, customDictionary); // 1.x-compatible second argument
96
72
 
97
- 0.9.7 - Added nonsense verbs from Rantionary
98
-
99
- 0.9.5 - Added verbs for success and defeat
100
-
101
- 0.9.4 - Added Death (<verb death>)
102
-
103
- 0.9.3 - Added climb (<verb climb up|down>)
73
+ const r = createRant({ seed: 42 });
74
+ r.run(pattern);
75
+ r.run(pattern, { seed: 99 });
76
+ ```
104
77
 
105
- ## New in version 0.9.1
78
+ Custom dictionary shape:
79
+
80
+ ```ts
81
+ const pets = {
82
+ tables: {
83
+ pet: {
84
+ name: "pet",
85
+ subs: ["default", "plural"],
86
+ entries: [{ forms: ["capybara", "capybaras"], classes: ["animal"] }],
87
+ },
88
+ },
89
+ };
90
+ ```
106
91
 
107
- Rewrote Rantjs for CommonJS.
108
-
109
- Removed several gulp tasks (concat, minify)
110
-
111
- Refactored the tests
112
-
113
- Renamed the app internally
114
-
115
- New usage syntax (not compatible with 0.8.x)
116
-
117
- You can now call Rantjs directly from require:
118
-
119
- var sentence=require("rantjs")("<firstname male> likes to <verb-transitive>
120
- <noun.plural> with <pron poss male> pet <noun-animal> on <timenoun dayofweek plural>.");
121
-
122
- Added randomization:
123
-
124
- require("rantjs")("A random string: [rep:8][sep:\N]{\C}");
125
- //A random string: XUACJGOGN
92
+ ## Browser
126
93
 
127
- ## New in version 0.8.6
94
+ ESM:
128
95
 
129
- Added support for [rep:x]
96
+ ```html
97
+ <script type="module">
98
+ import { rant } from "https://cdn.jsdelivr.net/npm/rantjs@2.0.0/+esm";
99
+ document.body.textContent = rant("<greet> <firstname>.");
100
+ </script>
101
+ ```
130
102
 
131
- Usage:
103
+ Script tag (cdnjs / jsDelivr):
132
104
 
133
- [case:title][sep:\n][rep:3]{I like <noun animal plural> but not <noun animal plural>}
105
+ ```html
106
+ <script src="https://cdn.jsdelivr.net/npm/rantjs@2.0.0/dist/rant.min.js"></script>
107
+ <script>
108
+ document.body.textContent = rant("<greet> <firstname>.");
109
+ </script>
110
+ ```
134
111
 
135
- // I Like Ogres but not Turtles
136
- // I Like Bulls but not Horses
137
- // I Like Poodles but not Owls
112
+ The IIFE build assigns `rant` on `globalThis`. The Node/ESM build does not touch `window`.
138
113
 
139
- Note: [sep:\n] dictates newlines. Alternatively, you can specify \s for space.
114
+ ## CLI
140
115
 
141
- ## New in version 0.8.5
116
+ ```bash
117
+ rantjs '<pattern>'
118
+ rantjs --seed 7 -f story.rant
119
+ rantjs --nsfw '<adj nsfw> <noun>'
120
+ ```
142
121
 
143
- Added support for [case]-tag.
122
+ ## Development
144
123
 
145
- Usage:
124
+ ```bash
125
+ npm install
126
+ npm test
127
+ npm run demo # playground at http://localhost:5173
128
+ ```
146
129
 
147
- [case:upper]<firstname male>
130
+ Dictionary sources live in `vocab/` (Rantionary plus a few custom tables). `npm run build:dict` compiles them into `src/dictionaries/en-US.ts`.
148
131
 
149
- Variants:
132
+ The playground is `npm run demo`. After GitHub Pages is enabled it will live at `https://robbestad.github.io/Rantjs/`.
150
133
 
151
- [case:none|default|word|upper|lower|case|sentence]
134
+ ## Migrating from 1.x
152
135
 
136
+ - Node 18+.
137
+ - `import { rant } from "rantjs"` (or `require("rantjs").rant`).
138
+ - `window.rant` is only set by the IIFE browser file, not by `require("rantjs")`.
139
+ - `String.prototype` is no longer patched.
140
+ - Some dictionary words changed; the query syntax did not.
153
141
 
142
+ ## License
154
143
 
155
- [1]: https://github.com/TheBerkin/Rant
156
- [3]: https://www.npmjs.com/package/rantjs
157
- [4]: http://www.robbestad.com/blog/procedurally-generated-text-with-rantjs
158
- [5]: http://rantjs.surge.sh/
144
+ ISC