5.9.12 • Published 3 months ago

tf2-item-format v5.9.12

Weekly downloads
298
License
MIT
Repository
github
Last release
3 months ago

TF2 Item Format

Formatting for TF2 items.

Use v5 branch for current version. Install it via npm install tf2-item-format

Features

  • Parses item name into attribute object
  • Stringifies attribute object into item name same as backpack.tf
  • Parses ECON item into attributes
  • Parses SKU into attributes
  • Makes SKU out of attributes
  • Creates backpack.tf compatible format for listing creation

Support the project

tf2-item-format is now used in number of production grade projects for handling item data, help support the project by donating items here.

Migrating from v4 to v5

To keep your application working like before with version 5 you have to:

import { parseString } from 'tf2-item-format/static' // -> from 'tf2-item-format'

const { parseString } = require('tf2-item-format/static') // -> from 'tf2-item-format'

New

To inject your own schema use this interface:

export type ISchema = {
    getDefindex(search: number | string): number|null;
    getName(search: number | string): string;
    getEffectName(effect: number | string): string;
    getWearName(wear: number | string): string;
    getKillstreakName(killstreak: number | string): string;
    getTextureName(texture: number | string): string;
    getQualityName(quality: number | string): string;
    getEffectEnum(effect: number | string): number;
    getWearEnum(wear: number | string): number;
    getKillstreakEnum(killstreak: number | string): number;
    getTextureEnum(texture: number | string): number;
    getQualityEnum(quality: number | string): number;
    getTextures(): SchemaEnum;
    getEffects(): SchemaEnum;
    isUniqueHat(defindexOrName: string | number): boolean;
}

// Extra types you might need:
export type NameToDefindex = { [name: string]: number };
export type DefindexToName = { [defindex: number]: string };
export type SchemaEnum = NameToDefindex & DefindexToName;

// Import these like:
// import { ISchema, NameToDefindex, DefindexToName, SchemaEnum } from 'tf2-item-format'

Then you just have to:

import { createFormat } from 'tf2-item-format';

const format = createFormat(schema);

Every method is then export same as before.

You can use parseSKU and toSKU without schema:

import { parseSKU, toSKU } from 'tf2-item-format';

Please note that static schema has implemented a lot of overwrites for defindexes that simply cannot be obtained by the limited data we have, so when you are implementing it yourself you should use the current Schema as your guide.

Instalation

Via NPM: npm install tf2-item-format Or Yarn: yarn add tf2-item-format

Documentation

Currently there is no full documentation.

We export these methods:

  • parseString
  • stringify
  • parseEconItem
  • toSKU
  • parseSKU
  • createBPListing
  • fixName

And static schema:

  • under property schema

Everything is fully typed so you should be able to get this working on your own, until I make a documentation. Some of the types are a bit confusing which will get fixed in next major version.

parseEconItem

parseEconItem(econ: EconItem, inNumbers: boolean, useDefindexes: boolean, options?: { useTrueDefindex: boolean }): ParsedEconItem;
  • econ is raw item you receive from the api
  • inNumbers - changes return type of certain attributes to numbers instead of pure strings, eg. quality, texture, wear, ...
  • useDefindexes - appends item defindex to the object, adds target & output aswell
  • options
    • useTrueDefindex - returns true defindex item has on this econ, doesn't ask schema.
  • Returns ParsedEconItem which is an object of all attributes the econ gives us

createBPListing

createBPListing(attributes: ItemAttributes | StringifySKUAttributes, options?: CreateBPListingOptions): BackpackTFListing
  • attributes - these you get from parseString, parseSKU or parseEconItem, all are compatible
  • options
    • unuSkinsToDecorated - defaults unusual skins to decorated weapon quality, default value is true
  • Returns BackpackTFListing object compatible with item object in backpack.tf listing creation api

stringify

stringify(attributes: StrigifySKUAttributes | ItemAttributes, options?: StringifyOptions): string
  • attributes - these you get from parseString, parseSKU or parseEconItem, all are compatible
  • options
    • determineUniqueHat - if set it checks in schema if given item should use The in name, defaults to false
  • Returns the item name

Note for stringify

If you are using sku format to store your items and want to use The in your names, you have to turn determineUniqueHat to true.

Compability usage

// Have a name, want a sku
const attributes = parseString(name, true, true); // To get defindexes and enums
const sku = toSKU(attributes);

// Have a sku, want a name
const attributes = parseSKU(sku);
const name = stringify(attributes);

// Have a sku, want a bp listing
const attributes = parseSKU(sku);
const listing = createBPListing(attributes);

Every method should be interchangable in similar ways.

5.9.12

3 months ago

5.9.10

3 months ago

5.9.11

3 months ago

5.9.9

3 months ago

5.9.8

5 months ago

5.9.7

5 months ago

5.9.6

7 months ago

5.9.5

7 months ago

5.8.10

11 months ago

5.9.4

8 months ago

5.9.3

8 months ago

5.9.2

9 months ago

5.9.1

10 months ago

5.9.0

10 months ago

5.8.9

1 year ago

5.8.8

1 year ago

5.8.7

1 year ago

5.8.6

1 year ago

5.8.5

2 years ago

5.8.4

2 years ago

5.8.3

2 years ago

5.6.17

2 years ago

5.6.16

2 years ago

5.8.2

2 years ago

5.8.1

2 years ago

5.8.0

2 years ago

5.7.0

2 years ago

5.6.15

2 years ago

5.6.14

2 years ago

5.6.13

2 years ago

5.6.11

2 years ago

5.6.10

2 years ago

5.6.12

2 years ago

5.6.9

2 years ago

5.6.8

2 years ago

5.6.7

2 years ago

5.6.6

2 years ago

5.6.5

3 years ago

5.6.4

3 years ago

5.6.3

3 years ago

5.6.2

3 years ago

5.6.1

3 years ago

5.6.0-beta

3 years ago

5.6.0

3 years ago

5.5.9

3 years ago

5.5.8

3 years ago

5.5.7

3 years ago

5.5.6

3 years ago

5.5.11

3 years ago

5.5.5

3 years ago

5.5.4

3 years ago

5.5.3

3 years ago

5.5.10

3 years ago

5.5.2

3 years ago

5.5.1

3 years ago

5.5.0

3 years ago

5.4.3

3 years ago

5.4.2

3 years ago

5.4.1

3 years ago

5.4.0

3 years ago

5.3.2

3 years ago

5.3.1

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

4.3.5

3 years ago

5.0.3

3 years ago

5.2.0

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

4.3.4

3 years ago

4.3.3

3 years ago

4.3.2

3 years ago

4.3.1

3 years ago

4.3.0

3 years ago

4.2.6

3 years ago

4.2.5

3 years ago

4.2.4

3 years ago

4.2.3

3 years ago

4.2.2

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

5.0.0

3 years ago

4.1.3-beta.6

3 years ago

4.1.3-beta.3

3 years ago

4.1.3-beta.4

3 years ago

4.1.3-beta.5

3 years ago

4.1.3-beta.2

3 years ago

4.1.3-beta.1

3 years ago

4.1.3-beta

3 years ago

4.1.3-beta.0

3 years ago

4.1.2-beta

3 years ago

1.0.0-beta.1

3 years ago

4.1.1-beta

4 years ago

4.1.0-beta

4 years ago

4.0.0-beta

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago

2.8.2

4 years ago

2.5.0

4 years ago

2.7.0

4 years ago

2.6.0

4 years ago

2.8.1

4 years ago

2.8.0

4 years ago

2.4.7

4 years ago

2.4.6

4 years ago

2.4.3

4 years ago

2.4.5

4 years ago

2.4.4

4 years ago

2.4.2

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.3.4

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.2

4 years ago

2.3.3

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago