A TypeScript SDK for Counter-Strike 2 schema data with ID/name resolution utilities
npm install cs2schema
pnpm add cs2-schema-sdk
`
Usage
`ts
import { CS2SchemaSDK } from "cs2-schema-sdk";
const sdk = new CS2SchemaSDK();
// Example: Search for an item
const results = sdk.searchItems("ak-47");
`
API
$3
- new CS2SchemaSDK(schemaPath?: string)
- Loads the schema from the given path or defaults to schema.json in the package root.
$3
- clearCache()
- Clears the internal search cache.
- searchItems(query: string, options?: SearchOptions): ResolveResult[]
- Search for items by name or partial name. Options: caseSensitive, category, exactMatch.
- resolveIdToName(id: string, category: ItemCategory): string | null
- Get the market hash name for a given item ID and category.
- resolveNameToId(name: string, category: ItemCategory, options?: SearchOptions): string | null
- Get the item ID for a given name and category. Options: caseSensitive, exactMatch.
- getItemById(id: string, category: ItemCategory): ResolveResult | null
- Get the item object for a given ID and category.
- getItemByName(name: string, category: ItemCategory, options?: SearchOptions): ResolveResult | null
- Get the item object for a given name and category.
- searchSkins(query: string, options?: Omit
- Search for weapon skins by name or partial name.
- getCollections(): Collection[]
- Get all collections.
- getRarities(): Rarity[]
- Get all rarities.
- getCollectionByKey(key: string): Collection | null
- Get a collection by its key.
- getRarityByKey(key: string): Rarity | null
- Get a rarity by its key.
- getAllItemsInCategory(category: ItemCategory): ResolveResult[]
- Get all items in a given category.
- getAllCharmNames(): string[]
- Get all charm names from the keychains category.
- generateAllWeaponMarketHashNames(options?: { includeSouvenir?: boolean; includeStatTrak?: boolean; specificCollections?: string[] }): GeneratedMarketHashName[]
- Generate all possible weapon market hash names with wear states. Options: includeSouvenir, includeStatTrak, specificCollections.
- generateWeaponMarketHashNamesByCollection(collectionKey: string, options?: { includeSouvenir?: boolean; includeStatTrak?: boolean }): GeneratedMarketHashName[]
- Generate weapon market hash names for a specific collection.
- getCategoryStats(): Record
- Get the number of items in each category.
- isInitialized(): boolean
- Check if the SDK is initialized and schema loaded.
- getSchema(): Schema
- Get the full processed schema object.
Types
See src/types.ts for all type definitions used in the SDK.
$3
`typescript
interface GeneratedMarketHashName {
baseName: string;
wearState: string;
fullName: string;
minFloat: number;
maxFloat: number;
collection?: string;
isSouvenir?: boolean;
}
`
$3
`typescript
interface WeaponWearState {
name: string;
minFloat: number;
maxFloat: number;
}
``