Sentencer icon indicating copy to clipboard operation
Sentencer copied to clipboard

Add custom lists to configure that can be articlized and pluralized

Open rmtuckerphx opened this issue 4 years ago • 1 comments

Type: FEATURE REQUEST

Challenge: Imagine a UI that builds templates and lists and then executes them dynamically. Adding those lists as actions is not currently possible.

Solution: Allow configure to accept custom lists. Besides a key and values, you can specify whether to support articlize and pluralize:

var Sentencer = require('sentencer');

Sentencer.configure({
    // the list of nouns to use. Sentencer provides its own if you don't have one!
    nounList: [],

    // the list of adjectives to use. Again, Sentencer comes with one!
    adjectiveList: [],

    customLists: [
        {
            key: "animal",
            values: ["dog", "cat", "horse", "pig", "elephant"],
            articlize: "an_animal", // if named, add action that calls articlize
            pluralize: "animals"    // if named, add action that calls pluralize
        },
        {
            key: "band",
            values: ["The Beatles", "The Who", "Styx"],
            articlize: "",  // no key or empty value, don't articlize
            pluralize: ""   // no key or empty value, don't pluralize
        }
    ],

    // additional actions for the template engine to use.
    // you can also redefine the preset actions here if you need to.
    // See the "Add your own actions" section below.
    actions: {
        my_action: function () {
            return "something";
        }
    }
});

The templates available for custom lists:

"{{ animal }}"
// "dog", "cat", "horse", "pig", "elephant"

"{{ an_animal }}"
// "a dog", "a cat", "a horse", "a pig", "an elephant"

"{{ animals }}"
// "dogs", "cats", "horses", "pigs", "elephants"


"{{ band }}"
// "The Beatles", "The Who", "Styx"

"{{ a_band }}"
// ignore

"{{ bands }}"
// ignore

rmtuckerphx avatar Apr 19 '20 17:04 rmtuckerphx

It's awesome! But it's still not merged? 🥲

xxxcrow avatar Dec 15 '21 19:12 xxxcrow