Catalog aims to provide an extensive standardised identifier system similar to a stock-keeping unit (SKU) system for TF2 items.
We may have data objects representing the full details of an item as large as this but we can represent the object as minimally as 5918;6
. In this example, 5918
represents the item's defindex
that tells us the item we have (a Scream Fortress XII War Paint Case
) and 6
represents the item's quality
of Unique
quality in this case. Almost all other item details can (and should) be functionally determined from the SKU.
Other libraries such as tf2-sku
and tf2-item-format
already provide standards for keeping to this SKU system, however, there is currently not a standard for including item modifications e.g spells, parts etc.
This means that applications will need to continue holding onto complete item information within databases should they wish to account for item modifications. As such, this library provides an extension for item modifications on top of the current standard.
You can install this module with npm within your project by running the command:
npm install @automatedtf/catalog
There are a number of ways this module can be used.
// Get an EconItem somehow e.g Steam Inventory JSON API
const econItem = { ... };
// Parse to a SKU
const baseSKU: string = toBaseSKU(econItem);
const fullSKU: string = toFullSKU(econItem);
// Get a human-readable item name
// NOTE: toName does not support full SKUs yet
const baseName: string = toName(baseSKU); // e.g Unique Brown Bomber
const theSameBaseName: string = toName(fullSKU);
// Parse a SKU into a ParsedSKUItem
const baseItemDetails: ParsedSKUItem = parseSKU(baseSKU);
const fullItemDetails: ParsedSKUItem = parseSKU(fullSKU); // includes item modifications
// Strip a full SKU into its base SKU
const _baseSKU: string = stripFullSKU(fullSKU); // remove item modifications
// Assertion: baseSKU === _baseSKU;
There are two concepts covered here when using this module: a base SKU and a full SKU.
A base SKU is the standard provided by other SKU libraries such as tf2-item-format
and tf2-sku
. This library uses tf2-item-format
as it provides an intermediate object from parseEconItem
that holds all information on item types and modifications. Calling toSKU
from tf2-item-format
upon this object will create a base SKU that considers the item type but not any modifications.
This can be used to identify items that are of the same type e.g an Unusual Green Confetti Brigade Helm and an Unusual Green Confetti Bridge Helm painted Australium Gold, however, won't take into account a modification such as paint.
This is more than sufficient for usage when one may not be concerned about item modifications within their item management system.
The regular expression for a base SKU roughly comes out to this:
[defindex];[quality](;uncraftable)?(;(u[effectenum])?(;[kt-X])?
defindex
-number
representing the identifier for what the item; seen in the TF2 schemaquality
-number
representing an item's quality; seen in the TF2 schemauncraftable
- 'uncraftable' if item is uncraftable, nothing if not.effectenum
-number
representing the (generally Unusual) effect on an item; seen in the TF2 schemakt-X
- Represents the killstreak tier on an itemkt-1
- Killstreakkt-2
- Specialized Killstreakkt-3
- Professional Killstreak
🚧 TODO 🚧
The full SKU is a concept introduced with this library that extends a base SKU to include string mappings for item modifications. This can be used for representing an item compactly by capturing every customisation for an item.
The regular expression for a full SKU is:
([base_sku])(;pnt[paintdefindex])?(;prt[partdefindex])*(;spl[spelldefindex])*(;shn[sheenenum])?(;ksr[killstreakerenum])?
base_sku
- Base SKU of item as previouslypaintdefindex
-number
representing the paint can used to paint the item; defindex seen in the TF2 schemapartdefindex
-number
representing the part attached on Strange item; in TF2 schema. There may be multiple parts.spelldefindex
-number
representing the spells applied onto item, using spell's defindex in TF2 schema. All voice spells are treated as the defindex8905
or the constantHALLOWEEN_SPELL_FIRST_VOICE
. There may be multiple spells.sheenenum
-number
representing the sheen of a Specialized Killstreak'd or Professional Killstreak'd item0
- Agonizing Emerald1
- Deadly Daffodil2
- Hot Rod3
- Manndarin4
- MeanGreen5
- TeamShine6
- VillainousViolet
killstreakerenum
-number
representing killstreaker of Professional Killstreak'd item0
- Cerebral Discharge1
- Fire Horns2
- Flames3
- Hypno-Beam4
- Incinerator5
- Singularity6
- Tornado
🚧 TODO 🚧
There are a number of ways that the module can be improved. This can include new functionalities, but some improvements can just be a refactoring - to reduce memory usage, minimise code duplication, and increase code hygiene.
There are several places in which a refactor could take place for parsing or expansion, including techniques such as grouping constants together and functions together for better management.
These are:
- Prefix Constants
- Parse Functions
- Expander Functions
- Killstreaker / Part / Sheen / Spell Enums
When representing an item as a SKU to be used later for the frontend, it may be helpful to differentiate an item's name based on its modifications e.g an 'Unusual Green Confetti Brigade Helm painted Australium Gold'. toName
could be extended for full SKUs later down the line.