Other structures, mixins and functions

This is the documentation for 1.6.2 version, which is not the latest version. Consider upgrading to 3.4.0.


titlecase will capitalize the first letter of the main words in its content (which is surprisingly more subtle than just uppercasing each word).

It uses these libs:

Not available in German and Italian.

There are plenty of options for each of these libs, but they are not supported by RosaeNLG yet (you get the default output).


  • isSentenceStart() will return a true if you are at the very beginning of a sentence (i.e. no word has been output yet). Use the #[+flushBuffer] mixin just before to be sure that isSentenceStart() returns a valid value.

  • toHtmlList(obj) will generate an HTML structure of the js object, with <ul> and <li> etc. This is useful for outputting the data that was used to generate a text, in the same document.

  • uppercaseWords(str) will output all words of the string with the first letter uppercase.

  • eatSpace will 'eat' the spaces around him. bla #[+eatSpace()] bla outputs blabla.


  • gender and number of an object:

    • getRefGender(obj) gives the current gender of an object (according to the last triggered representant). It should not be used that often.

    • getRefNumber(obj) give the current number of an object.

  • getSorP(table, obj): table is an array with 2 elements. If obj is singular, the first item of the array will be output, if plural, it will be the second. It can be useful in referring expressions: #{getSorP(['it', 'they'], DIAMOND)}

  • getMFN(table, obj): same as getSorP but for masculine/feminine/neutral. You don’t need to provide a neutral if it does not exist in the target language. getMorF(table, obj) is an alias.

  • valueToSorP(val) will return 'S' (singular) if val is > 1 and 'P' (plural) otherwise. Useful in referring expressions when the number can vary: setRefNumber(DIAMONDS, valueToSorP(DIAMONDS.numberOfDiamonds));

  • logParams(params) will put in console the stringified param object.

  • access to embedded libs:

    • util.compromise give a direct access to compromise lib. #{ util.compromise('London is calling').sentences().toNegative().out() } will output London is not calling.

    • util.moment for Moment.js

    • util.numeral for Numeral.js

  • getting values in parameters:

    • hasFlag(obj, flag) checks if obj[flag] is true. It is just syntaxic sugar.

    • getFlagValue(obj, flag) does the same as hasFlag excepts it returns a value, not a boolean. Is also just syntaxic sugar.