This repository was archived by the owner on Jun 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +72
-1
lines changed
Expand file tree Collapse file tree 4 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 1- local
1+ local
2+ examples
Original file line number Diff line number Diff line change 1+ const Schema = require ( 'tf2-schema' ) ;
2+
3+ const schemaManager = new Schema ( { apiKey : 'your steam api key' } ) ;
4+
5+ schemaManager . init ( function ( err ) {
6+ if ( err ) {
7+ throw err ;
8+ }
9+ } ) ;
10+
11+ schemaManager . on ( 'ready' , function ( ) {
12+ // item object to get the name off, only the defindex and quality is required
13+ const item = {
14+ defindex : 5021 ,
15+ quality : 6
16+ } ;
17+
18+ // get the name of the item
19+ const name = schemaManager . schema . getName ( item ) ;
20+
21+ console . log ( name ) ; // -> Mann Co. Supply Crate Key
22+ } ) ;
Original file line number Diff line number Diff line change 1+ const Schema = require ( 'tf2-schema' ) ;
2+ const fs = require ( 'fs' ) ;
3+
4+ const SCHEMA_PATH = './path-to-schema-file.json' ;
5+
6+ const schemaManager = new Schema ( { apiKey : 'your steam api key' } ) ;
7+
8+ if ( fs . existsSync ( SCHEMA_PATH ) ) {
9+ // a cached schema exists
10+
11+ // read and parse the cached schema
12+ const cachedData = JSON . parse ( fs . readFileSync ( SCHEMA_PATH ) ) ;
13+
14+ // set the schema data
15+ schemaManager . setSchema ( cachedData ) ;
16+ }
17+
18+ // initialize tf2-schema like normally
19+ schemaManager . init ( function ( err ) {
20+ if ( err ) {
21+ throw err ;
22+ }
23+ } ) ;
24+
25+ schemaManager . on ( 'schema' , function ( schema ) {
26+ // this event is emitted when the schema has been fetched
27+
28+ // writes the schema data to disk
29+ fs . writeFileSync ( SCHEMA_PATH , JSON . stringify ( schemaManager . toJSON ( ) ) ) ;
30+ } ) ;
Original file line number Diff line number Diff line change 1+ const Schema = require ( 'tf2-schema' ) ;
2+
3+ // Create new instance of tf2-schema
4+ const schema = new Schema ( { apiKey : 'your steam api key' } ) ;
5+
6+ // Initialize tf2-schema
7+ schema . init ( function ( err ) {
8+ if ( err ) {
9+ // Error occurred fetching the schema
10+ throw err ;
11+ }
12+
13+ // tf2-schema is now ready to be used
14+ } ) ;
15+
16+ schema . on ( 'ready' , function ( ) {
17+ // this event is emitted when the init function has been called and finished without errors
18+ } ) ;
You can’t perform that action at this time.
0 commit comments