Methods
(static) article(string) → {String}
- Description:
Put an indefinite article in front of the word based on whether or not it starts with a vowel.
- Source:
Example
article('walkie talkie')
=> "a walkie talkie"
article('album')
=> "an album"
Parameters:
| Name | Type | Description |
|---|---|---|
string |
String | String to prefix with an indefinite article |
Returns:
The string with "a" or "an" in front of it.
- Type
- String
(static) bagSpecParser(spec) → {Object}
- Description:
Parses a bag specification string to define the properties to supply to the
createBagfunction.
- Source:
Examples
bagSpecParser("Bag(clothing)");
=> { value: 10, repeat: 20, tags: "clothing", uncountable: false }
bagSpecParser("Bag($10 clothing -military)");
=> { value: 10, repeat: 20, tags: "clothing -military", uncountable: false }
bagSpecParser("Shop Floor(5 clothing)");
=> { name: "Shop Floor", count: 5, repeat: 20, tags: "a b", uncountable: false }
// dice notation will be converted to a value; Sells/Stock sets uncountable = true
bagSpecParser("Sells($2d6/50% clothing)");
=> { value: 8, repeat: 50, tags: "clothing", uncountable: true }
bagSpecParser("Stock($10/50%/e10/5 items)");
=> { value: 10, repeat: 50, enc: 10, count: 5, tags: "items", uncountable: true }
Parameters:
| Name | Type | Description |
|---|---|---|
spec |
string | The bag specification string to parse (e.g., "Name($10 a b)" or "Stock($2d6/50%/e10 items)"). |
Returns:
An object containing:
- {string}
name[default=undefined] - the name for the bag. In some presentations this clarifies the container that the bag represents. - {number}
repeat[default=20] - the percent chance that the next item selected will be the same as the last item selected. Used to model collections with more or less repetition - {number}
value[default=20] - the total value of the items selected. - {number}
enc[default=Number.MAX_VALUE] - the total encumbrance of the items in a bag. Used to model containers of limited size. - {number}
minValue- 0.1 for uncountable bags and 0.0 for countable bags. This is because uncountable collections (stock or inventory) don’t represent collections of things without value. - {string}
tags[default=undefined] - search tags - {number}
count[default=Number.MAX_VALUE] - the total count of items in the collection. - {boolean}
uncountable[default=false] - are the items in this bag essentially not counted? They will be displayed in the plural to represent the indefinite plural.
- Type
- Object
(static) format(template, values+) → {String}
- Description:
Format a string with parameters. There are many ways to supply values to this method:
- Source:
Example
format('This {0} a {1}.', ['is', 'test']);
=> "This is a test."
format('This {0} a {1}.', 'is', 'test');
=> "This is a test."
format('This {verb} a {noun}.', {verb: 'is', noun: 'test'})
=> "This is a test."
Parameters:
| Name | Type | Description |
|---|---|---|
template |
String | template string |
values+ |
Object | An array, a set of values, or an object with key/value pairs that will be substituted into the template. |
Returns:
the formatted string
- Type
- String
(static) parseDelimiters(string, startCharopt, endCharopt)
- Description:
Parses a string for delimiters, returning a boolean indicating if they were found, the string without the delimiters, and the value within the delimiters.
- Source:
Example
parseDelimiters("Bag{$10 living}", "{", "}")
=> [true, "Bag", "$10 living"]
parseDelimiters("Bag($10 living)")
=> [true, "Bag", "$10 living"]
parseDelimiters("Bag")
=> [false, "Bag", null]
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
string |
String | the string to parse |
||
startChar |
String |
<optional> |
"("
|
the starting delimiter character |
endChar |
String |
<optional> |
")"
|
the ending delimiter character |
(static) pluralize(name, countopt) → {String}
- Description:
Pluralizes a string (usually a noun), if the count is greater than one. If it's a single item, an indefinite article will be added (see example below for cases where it should not be added, "uncountables"). The string should note the method of pluralizing the string in curly braces if it is not a simple noun that is pluralized using "s", "es" or "aries". For example:
- Source:
Example
pluralize('shoe', 3)
=> "3 shoes"
pluralize('status', 2)
=> "2 statuses"
pluralize('bag{s} of flour', 1)
=> "a bag of flour"
pluralize('bag{s} of flour', 2)
=> "2 bags of flour"
// Note suppression of the indefinite article!
pluralize('{|suits of }makeshift metal armor')
=> "makeshift metal armor"
pluralize('{|suits of }makeshift metal armor', 4)
=> "4 suits of makeshift metal armor"
let item = new Item('quarry');
pluralize(item, 3)
=> "3 quarries"
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name |
String | Item | A string name following the rules described above, or an Item with a name property |
||
count |
Number |
<optional> |
1
|
The number of these items |
Returns:
the correct singular or plural name
- Type
- String
(static) sentenceCase(string) → {String}
- Description:
Convert a string to sentence case (only the first letter capitalized).
- Source:
Example
sentenceCase('antwerp benedict');
=> "Antwerp benedict"
sentenceCase('antwerp-Benedict');
=> "Antwerp-benedict"
sentenceCase('bead to a small mouth');
=> "Bead to a small mouth"
Parameters:
| Name | Type | Description |
|---|---|---|
string |
String |
Returns:
in sentence case
- Type
- String
(static) startLowercase(string) → {String}
- Description:
Converts the first character of a string to lowercase. The rest of the string is unchanged.
- Source:
Example
startLowercase('Atomic Frontier');
=> "atomic Frontier"
Parameters:
| Name | Type | Description |
|---|---|---|
string |
* |
Returns:
the string with a lowercase first character
- Type
- String
(static) titleCase(string) → {String}
- Description:
Convert string to title case. There's a long list of rules for this kind of capitalization, see:
To Title Case 2.1 - http://individed.com/code/to-title-case/
Copyright 2008-2013 David Gouch. Licensed under the MIT License.
- Source:
Example
titleCase('antwerp benedict');
=> "Antwerp Benedict"
titleCase('antwerp-Benedict');
=> "Antwerp-Benedict"
titleCase('bead to a small mouth');
=> "Bead to a Small Mouth"
Parameters:
| Name | Type | Description |
|---|---|---|
string |
String | string to title case |
Returns:
in title case
- Type
- String
(static) toList(array, funcopt, joinopt, separatoropt) → {String}
- Description:
Format the elements of an array into a list phrase.
- Source:
Example
toList(['Apples', 'Bananas', 'Oranges'], (value) => '*'+value);
=> "*Apples, *Bananas, and *Oranges"
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
array |
Array | The array to format |
||
func |
function |
<optional> |
identity
|
An optional function to format the elements of the array in the returned string. |
join |
String |
<optional> |
and
|
the word to join the last word in the list. |
separator |
String |
<optional> |
,
|
the delimiter to separate items in the list. |
Returns:
the array formatted as a list.
- Type
- String
(inner) hasDelimiters(string, startCharopt, endCharopt)
- Description:
Checks if a string has the specified delimiters. Defaults to the use of parentheses.
- Source:
Examples
hasDelimiters("Bag($10 living)")
=> true
hasDelimiters("Bag")
=> false
hasDelimiters("Bag($10 living)")
=> true
hasDelimiters("Bag")
=> false
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
string |
String | the string to check |
||
startChar |
String |
<optional> |
"("
|
the starting delimiter character |
endChar |
String |
<optional> |
")"
|
the ending delimiter character |
(inner) resolve(value) → {String}
- Description:
Combines randomization with formatting. First, randomizes the first argument using the
random()function. Then formats the resulting string using the rest of the arguments passed in to the method, as described by theformat()function.resolve(["Mr. {name}", "Mrs. {name}"], {name: "Smith"}); => "Mrs. Smith"
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
value |
String | Array | function | A string with optional variants, or an array from which to select an element, or a function that returns a value. |
|
...args |
<optional> |
zero or more objects to use in formatting the final string |
Returns:
the randomly selected, formatted string
- Type
- String