Skip to content

Latest commit

 

History

History
112 lines (85 loc) · 3.16 KB

README.md

File metadata and controls

112 lines (85 loc) · 3.16 KB

tf-sku

A static Node.js class for formatting Team Fortress 2 items into strings or JSON objects.

npm version npm downloads Node.js version GitHub actions GitHub license

Installation

Using npm:

$ npm install @mann-conomy/tf-sku

Using yarn:

$ yarn add @mann-conomy/tf-sku

Testing

Using npm:

$ npm test

Using yarn:

$ yarn test

Examples

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

MIT

Copyright 2024, The Mann-Conomy Project