Constructor
new Bag(dataopt)
- Description:
Creates a new Bag instance.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object |
<optional> |
{}
|
Configuration data for the bag Properties
|
Extends
Members
tags
- Description:
An array of string tags that characterize this item.
- Source:
- Overrides:
Properties:
| Name | Type | Description |
|---|---|---|
tags |
Set |
An array of string tags that characterize this item.
Methods
add(item, countopt) → {Number}
- Description:
Adds items to the bag. If the item already exists, increases the count.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
item |
Item | The item to add |
||
count |
Number |
<optional> |
1
|
The number of items to add |
Throws:
-
If no item is provided, count is negative, or item is null
- Type
- Error
Returns:
The new total count of this item in the bag
- Type
- Number
addBag(bag)
- Description:
Adds all items from another bag to this bag.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
bag |
Bag | The bag whose items to add |
asJSON() → {String}
- Description:
Converts the model to JSON, converting sets to arrays.
- Source:
- Overrides:
Returns:
JSON
- Type
- String
count(itemopt) → {Number}
- Description:
Counts the total number of items in the bag.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
item |
Item |
<optional> |
Optional specific item to count |
Returns:
The total count of items
- Type
- Number
enc(itemopt) → {Number}
- Description:
Calculates the total encumbrance of items in the bag.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
item |
Item |
<optional> |
Optional specific item to calculate encumbrance for |
Returns:
The total encumbrance
- Type
- Number
find(name) → {Object|null}
- Description:
Finds an entry by item name or tag.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
String | The name or tag to search for |
Returns:
The matching entry or null if not found
- Type
- Object | null
has(tag) → {Boolean}
- Description:
Does this model have the given tag?
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
String |
Returns:
true if it does, false otherwise
- Type
- Boolean
is(tag) → {Boolean}
- Description:
Does this model have the given tag?
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
String |
Returns:
true if it does, false otherwise
- Type
- Boolean
not(tag) → {Boolean}
- Description:
Does this model not have the given tag?
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
String |
Returns:
true if it does not have the tag, false otherwise
- Type
- Boolean
remove(item, countopt) → {Number}
- Description:
Removes items from the bag. If count reaches zero, removes the entry entirely.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
item |
Item | The item to remove |
||
count |
Number |
<optional> |
1
|
The number of items to remove |
Throws:
-
If count is negative, item not in bag, or trying to remove more than available
- Type
- Error
Returns:
The new total count of this item in the bag
- Type
- Number
removeBag(bag)
- Description:
Removes all items from another bag from this bag.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
bag |
Bag | The bag whose items to remove |
toString() → {String}
- Description:
Converts the bag contents to a human-readable string with proper pluralization.
- Source:
Returns:
Human-readable description of bag contents
- Type
- String
toUncountableString() → {String}
- Description:
Converts the bag contents to a string using uncountable item names.
- Source:
Returns:
Human-readable description with uncountable names
- Type
- String
totalEnc() → {Number}
- Description:
Calculates the total encumbrance of all items in the bag.
- Source:
Returns:
The total encumbrance of all items
- Type
- Number
totalValue() → {Number}
- Description:
Calculates the total value of all items in the bag.
- Source:
Returns:
The total value of all items
- Type
- Number
typeOf(prefix) → {String}
- Description:
Given a prefix like
ammoormedia, will return the specific tag for this item, such asammo:22ormedia:35mm.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
String | the prefix to match |
Returns:
the first tag found that matches this prefix
- Type
- String
value(itemopt) → {Number}
- Description:
Calculates the total value of items in the bag.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
item |
Item |
<optional> |
Optional specific item to calculate value for |
Returns:
The total value
- Type
- Number
visit(startValue, pred, collectoropt) → {*}
- Description:
Visits each entry in the bag with a predicate and collector function.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
startValue |
* | Initial value for the accumulator |
|
pred |
function | Predicate function to test each entry |
|
collector |
function |
<optional> |
Function to collect/transform matching entries |
Returns:
The accumulated result
- Type
- *