kylestetz / Sentencer

:pencil2: madlibs-style sentence templating in Javascript
http://kylestetz.github.io/Sentencer
MIT License
378 stars 40 forks source link

Allow recursive variable expansion #7

Open shawrkbait opened 5 years ago

shawrkbait commented 5 years ago

This change allows recursive variable expansion.

For example: we can choose from a list of questions:

var Sentencer = require('sentencer');
var randy = require('randy');

var questions = ["what is {{ a_noun }}", "why is {{ a_noun }} so {{ adjective }}"];

Sentencer.configure({
  actions: {
    question: function() {
      return randy.choice(questions);
    }
  }
});

console.log( Sentencer.make("Question 1: {{ question }}");