Simple-to-use parser for TF2 items. Fully typed and lightning fast.
Provides a unified interface for items, which allows parsing from and to largely any format you might come across:
- Item names
- SKU
- EconItem (steam api, node-steam-user and node-steamcommunity)
- TF2 (node-tf2, GC and backpack.tf api)
- Backpack Documents (old and new backpack.tf api)
- Backpack.tf URLs
- Attribute objects (tf2-item-format)
No longer must we suffer from too many item formats
npm install tf2-item-parser
import Item from "tf2-item-parser";
const item = Item.fromName("Strange Professional Killstreak Australium Rocket Launcher");
console.log(item.toSKU()); // 18;11;australium;kt-3
console.log(item.toString()); // Strange Professional Killstreak Australium Rocket Launcher
This module relies on preprocessed item definitions to efficiently parse items. These come already bundled with the module, but can be updated by calling the init method.
It is not strictly required to call this method since most methods will function without it, but it is needed to parse new items following tf2 updates. Generally, I recommend calling this method once on startup.
If you do not call this method, the following will not be available: Item.fromTF2 and global_info.schema.
You can also use an instance of tf2-schema for initialization. When providing an api key, init will automatically call itself every few hours, so you will not need to call it again.
import Item from "tf2-item-parser";
await Item.init(""); // Steam API Key
The main Item class.
Create with Item.fromX. Compare with .equal(item). Convert with .toX.
- name: The item's base name.
- def_index: The item's definition index.
- quality: number. The item's quality as a number (see EItemQuality).
- id?: The item's id.
- craftable: Whether the item is craftable.
- killstreak: The item's killstreak tier (see EKillstreakTier).
- killstreak_sheen: The item's killstreak sheen (see EKillstreakSheen).
- killstreaker: The item's killstreaker (see EKillstreaker).
- australium: Whether the item is australium.
- festivized: Whether the item is festivized.
- unusual: The item's unusual effect (see EUnusualEffects).
- texture: The item's texture (see ETexture).
- wear: The item's wear (see EWear).
- strange: Whether the item is strange.
- tradable: Whether the item is tradable.
- paint: The item's paint (see EPaints).
- spells: List of the item's spells (see ESpells).
- strange_parts: List of the item's strange parts (see EStrangeParts).
- usable: Whether the item is usable.
- max_uses?: The item's max uses. Specified for usable items.
- remaining_uses?: The item's remaining uses. Specified for usable items.
- item_number?: The item's item number. Meaning depends on the item's type, one of: craft number, crate number, chemistry set series, medal number
- target_def_index?: def_index of item that this can be used on (for killstreak kits, strangifiers, etc)
- input_items?: List of items (as strings) that are required to craft this item.
- output_item?: Item received when crafting this item. Specifies .def_index and .quality for Strangifiers. Specifies .item for Chemistry Sets, Kit Fabricators and Wrapped Gifts.
- def_index?: The item's definition index.
- quality?: number. The item's quality as a number (see EItemQuality).
- item?: A Item instance indicating the item received when using this item.
- type: The item's type (see ItemType).
- needs_the: Whether the item needs "The" in front of its name.
- never_tradable: Whether the item is never tradable (as opposed to not currently tradable).
Create a new item directly from known item traits.
Initialize the item parser with a Steam API Key or a tf2-schema instance.
Parses an item from a string. Ignores case and special characters. Will return undefined if the string is not a valid item.
Parses an item from a SKU.
Parses an item from the steam api, node-steam-user and node-steamcommunity.
Parses an item from the node-tf2 module and older backpack.tf api endpoints (including snapshots).
Parses an item from newer backpack.tf api endpoints (websocket, /v2).
Parses an item from a URL to a backpack.tf "stats" page (https://backpack.tf/stats/...).
Parses an item from a tf2-item-format attribute object.
Creates an Item from an ItemTraits object. Useful for converting an Item back after using .toJSON.
Some Items have several possible def_index values depending on quality, style or obtain method. This method returns the lowest possible def_index for the item.
Compares two Items.
Only compares traits that meaningfully differentiate items (i.e. ignores paint, killstreak sheens, killstreakers, strange parts and spells). Use .equalExact to compare all traits.
Converts the Item to its fully qualified name. Includes name, quality, killstreak, etc.
Converts the Item to a SKU. Equivalent to the widely used Marketplace.tf SKU.
Note that the backpack.tf api usually expects a name (use toString) when using the sku parameter.
Converts the Item to JSON. Useful for saving items to a database or file.
Convert them back to items using fromJSON.
Obtains the URL to the item on backpack.tf.
Converts the item to the new backpack.tf item format. Used across the new v2 api endpoints.
Converts the item to an item for the old backpack.tf api endpoints.
Creates a TradeOfferManager item from the Item. Used for sending trade offers using steam-tradeoffer-manager.
Checks if the Item is a key, ref, rec or scrap.
Duplicate the Item. Useful for creating a copy of an item that can be modified without affecting the original.
Holds various internal objects used by the module, including a reference to the tf2-schema instance used for parsing.
- EItemQuality
- EItemKillstreak
- EKillstreakSheen
- EKillstreaker
- EUnusualEffects
- ETexture
- EWear
- EPaints
- ESpells
- EStrangeParts
- ETraits (for ignore_traits parameter of .equal)
- Various types
MIT