1.0.0 • Published 1 year ago
@mann-conomy/tf-sku v1.0.0
tf-sku
A static Node.js class for formatting Team Fortress 2 items into strings or JSON objects.
Using npm:
$ npm install @mann-conomy/tf-skuUsing yarn:
$ yarn add @mann-conomy/tf-skuTesting
Using npm:
$ npm testUsing yarn:
$ yarn testExamples
Formatting Team Fortress 2 item objects into concise strings that captures their unique attributes.
import { SKU } from "@mann-conomy/tf-sku";
try {
    // Object representation of a Professional Festivized Australium Medi Gun
    const item = {
        defindex: 211,
        quality: 11,
        australium: true,
        killstreak: 3, 
        festive: true
    }
    // Convert the item object into a SKU string
    const sku = SKU.stringify(item);
    console.log(sku); // 211;11;australium;kt-3;festive
} catch (error) {
    console.error("Error creating SKU string", error.message);
}Converting strings into structured objects that represent the attributes of Team Fortress 2 items.
import { SKU } from "@mann-conomy/tf-sku";
try {
    // String representation of a Strange Purple Energy Villain's Veil
    const sku = "393;5;u10;strange";
    // Parse the SKU string into an item object
    const item = SKU.parse(sku);
    console.log(item);
    /*
    {
        defindex: 393,
        quality: 5,
        effect: 10,
        australium: false,
        craftable: true,
        tradable: true,
        wear: null,
        paintkit: null,
        elevated: true,
        killstreak: 0,
        target: null,
        festive: false,
        craftnumber: null,
        crateseries: null,
        output: null,
        outputQuality: null,
        paint: null
    }
    */
} catch (error) {
    console.error("Error parsing SKU string", error.message);
}Some more examples are available in the examples and test directories.
Documentation
See the Wiki pages for further documentation.
License
Copyright 2024, The Mann-Conomy Project
1.0.0
1 year ago