variete

Variete allows your to vary your copy (useful for descriptions, to avoid repetitive text)

Usage no npm install needed!

<script type="module">
  import variete from 'https://cdn.skypack.dev/variete';
</script>

README

Variété.js

This NPM module (no dependencies!) will help you when you need to vary your copy randomly (think SEO).

Duplicate descriptions? A thing of the past

Say you'd like to output a description meta, here's how to do it:

npm install variete
var variete = require("variete");
var description = variete.parse('This {amazing|extraordinary|nice} module {will help me|already helps me} when I {need|have to} vary my copy.');

Now description contains a random string (among 322=12 variations) with the alternatives you've specified.

Note that you can't nest multiple alternatives, and parsing an empty string will fail with an error.

It would be nice if we could seed the random number generator, so that result could depend on an page Id for instance...

This module is using a parser generated online at http://pegjs.majda.cz/online (nice!).