If there’s one thing the world needs, it’s more text. But making good text is hard and takes much time, so I created Apep to write text for me.
// Generate quips for a hacker on a TV show. const pep = require('apep'); // Declare allows for forward references const tvHackerQuip = pep.declare(() => pep.seq(exlaimation, ' ', pep.choice( pep.seq('The ' , subject, ' is ', somethingBad, '!'), pep.seq(evilDoer, ' ', isDoingSomethingBadTo, ' the ', target, '!')))); const evilDoer = pep.choice("She's", "He's", "They're"); const subject = pep.choice('CPU', 'HTML', 'GUI', 'IPv6', 'file system', 'ACL'); const somethingBad = pep.choice('on fire', 'doxxed', 'SQL injected', 'double encrypted'); const isDoingSomethingBadTo = pep.choice('pinging', 'ROT13ing', 'seg faulting', 'doxxing', 'DDOSing'); const target = pep.choice('NSA', 'CIA', 'FBI', 'mainframe', 'shell', 'cloud'); const exlaimation = pep.choice('BLARK', 'ARG', 'BARF', 'GROK', 'ACK') .seq(pep.many1('!')); // Generate some output for (var i = 0; i < 10; ++i) console.log(tvHackerQuip.run())
ACK! The CPU is double encrypted! GROK! She's pinging the FBI! ARG!! They're doxxing the mainframe! ARG!!! They're ROT13ing the shell! BARF!! He's doxxing the mainframe! BARF! The HTML is SQL injected! ACK!!! The file system is on fire! BLARK!!! He's DDOSing the shell! ARG!!!! The IPv6 is on fire! GROK! He's seg faulting the NSA!
Although the library is small (around 200 lines of actual logic), it provides:
- A set of core generators and combinators.
- Forward references and self references.
- Custom state objects
- Custom random number generators
Check out the documentation for more details and the complete API.
Any contributions to Apep are welcome. If you come across any problems, please open an issue. And if you use Apep to generate something awesome, please submit a pull request to add it to the README in the source.