.Phrase

The ishml.Phrase object is a text generation object. See the text generation tutorial for detailed examples of phrases in use.

Constructor

Instance of ishml.Phrase are created by invoking a template. The template defines the phrase; the phrase generates the text.

Properties

.data Object

Returns the data and meta-data associated with the first result from the phrase's array after .say() generates text. The availability of meta-data is dependent on the template that created phase. Different templates provide different meta-data.

.text String

Returns the text generated by .say().

Methods

.append( CSS selector string)

Append the contents of the .text property to the innerHTML of the document element specified in the CSS selector string. Returns the instance of ishml.Phrase.

.htmlTemplate()

Creates and returns an HTML Content Template element from the contents of the .text property.

.populate(object)
.populate(value1[, ...[, valueN]])
.populate([value1[, ...[, valueN]]])

Populates the phrase with data. Returns the instance of ishml.Phrase. See the the text generation tutorial for detailed examples.

.prepend( CSS selector string)

Prepends the contents of the .text property to the innerHTML of the document element specified in the CSS selector string. Returns the instance of ishml.Phrase.

.replace( CSS selector string)

Replaces the innerHTML of the document element specified in the CSS selector string with the the contents of the .text property. Returns the instance of ishml.Phrase.

.say( optional seed)

Generates text. Optionally a seed number between zero (inclusive) and one (exclusive) may be provided to set the seed value for random text generations. Returns the instance of ishml.Phrase. See the text generation tutorial for detailed examples.

Static Methods

ishml.Phrase.define( String).as(Phrase Factory Function)

Defines a custom phrase suffix. See the text generation tutorial for a detailed example.

Suffixes

.also

The .also suffix signals the start of another ishml.Phrase that will only be evaluated and appended if the preceding phrase returns at least one result. If the preceding phrase returns no results, the phrase associated with .also will be skipped. Although .also is technically a suffix in that it is a getter property for ishml.Phrase, it returns a template prefix instead of an ishml.Phrase. Therefore, it is acceptable to chain prefixes after .also. It is intended to pair with with the .series prefix. See the text generation tutorial for a detailed example.

.cache( String)

Attaches a cache tag to a phrase. Tagged phrases provides a means of referencing phrases within other phrases. Cached tags differ from standard tags in that the phrase's data assigned with .populate() does not automatically propogate to tagged sub-phrases. See the text generation tutorial for a detailed explanation and example.

.concur(callback function)

Filters the phrase's array so that it conforms to the criteria of specified in the callback function. See the text generation tutorial for a detailed example.

.ed

Modifies a phrase to inflect each item (verb) in the phrase's array to past tense according to standard American English.

.en

Modifies a phrase to inflect each item (verb) in the phrase's array to past participle according to standard American English.

.es

Modifies a phrase to inflect each item (verb) in the phrase's array to third person present tense according to standard American English. See example.

.first( Integer)

Limits the phrase's array to the first item in the array. Optionally, an integer may be provided to limit the array to the first n number of items specified.

.ing

Modifies a phrase to inflect each item (verb) in the phrase's array to present participle according to standard American English.

.inner ishml.Phrase

For nested phrases composed by multiple prefixes and/or suffixes, returns the inner phrase as it existed prior to the application of the outer phrase. See the text generation tutorial for an example of .inner in use.

.join( optional {separator=String, trim=Boolean})

Modifies a phrase by appending each item in the phrase's array with the provided separator and then concatenating the items into a single a single value. If no separator is given, it defaults to the empty string. By default, trim is set to true and will remove the trailing separator for the last item. Set it to false to append the separator to the last item in the phrase's array.

.last( Integer)

Limits the phrase's array to the last item in the array. Optionally, an integer may be provided to limit the array to the last n number of items specified.

.modify(callback function)

Applies the provided callback function to the items in the phrase's array to modify them. See the text generation tutorial for a detailed example.

.per( String)

Creates a new phrase by concatenating the results of a phrase for as many items as there are in the corresponding tagged phrase's array. See the text generation tutorial for a detailed example.

.s

Modifies a phrase to inflect each item (noun) in the phrase's array to plural form according to standard American English.

If using complex data and .number is set to ishml.enum.number.singular, the value is left uninflected. If .number is set to ishml.enum.number.plural or omitted, the value is inflected to the plural form. See example.

.tag( String)

Attaches a name to a phrase. Tagged phrases provides a means of referencing phrases within other phrases. See the text generation tutorial for a detailed example.

.then

The .then suffix signals the start of another ishml.Phrase that will only be evaluated and appended if the preceding phrase returns no results. If the preceding phrase returns at least one result, the phrase associated with .then will be skipped. Although .then is technically a suffix in that it is a getter property for ishml.Phrase, it returns a template prefix instead of an ishml.Phrase. Therefore, it is acceptable to chain prefixes after .then. It is intended to pair with with the .series prefix. See the text generation tutorial for a detailed example.