@juice789/tf2items 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/schemaItems.js ADDED
@@ -0,0 +1,15 @@
1
+ const schema = require('./schema.json')
2
+
3
+ const safeItems = new Proxy(schema.items, {
4
+ get(receiver, name) {
5
+ return name in receiver ? receiver[name] : {
6
+ defindex: name,
7
+ item_name: 'Undefined item'
8
+ }
9
+ }
10
+ })
11
+
12
+ module.exports = {
13
+ ...schema,
14
+ safeItems,
15
+ }
package/sku.js ADDED
@@ -0,0 +1,142 @@
1
+ const {
2
+ compose, split, map, reduce, pickBy, mergeRight, converge, concat, of, join, head, tail, filter
3
+ } = require('ramda')
4
+
5
+ const {
6
+ safeItems
7
+ } = require('./schemaItems.js')
8
+
9
+ const {
10
+ qualityNames,
11
+ killstreakTiers,
12
+ wears
13
+ } = require('./schemaHelper.json')
14
+
15
+ const {
16
+ textures,
17
+ particleEffects
18
+ } = require('./schema.json')
19
+
20
+ const skuFromItem = ({
21
+ defindex,
22
+ quality,
23
+ uncraftable,
24
+ elevated,
25
+ effect,
26
+ killstreakTier,
27
+ festivized,
28
+ target,
29
+ output,
30
+ oq,
31
+ texture,
32
+ wear,
33
+ australium,
34
+ series,
35
+ craft
36
+ }) => [
37
+ defindex,
38
+ quality,
39
+ ['1', true].includes(uncraftable) && 'uncraftable',
40
+ ['1', true].includes(elevated) && 'strange',
41
+ effect && 'u-' + effect,
42
+ killstreakTier && ['1', '2', '3', 1, 2, 3].includes(killstreakTier) && 'kt-' + killstreakTier,
43
+ ['1', true].includes(festivized) && 'festive',
44
+ target && 'td-' + target,
45
+ output && 'od-' + output,
46
+ oq && 'oq-' + oq,
47
+ texture && 'pk-' + texture,
48
+ wear && 'w-' + wear,
49
+ ['1', true].includes(australium) && 'australium',
50
+ series && isNaN(series) === false && 'c-' + parseInt(series),
51
+ craft && isNaN(craft) === false && 'no-' + parseInt(craft),
52
+ ].filter(Boolean).join(';')
53
+
54
+ const rules = {
55
+ uncraftable: 'uncraftable',
56
+ strange: 'elevated',
57
+ u: "effect",
58
+ kt: "killstreakTier",
59
+ festive: 'festivized',
60
+ td: "target",
61
+ od: "output",
62
+ oq: "oq",
63
+ pk: "texture",
64
+ w: "wear",
65
+ australium: 'australium',
66
+ c: "series",
67
+ no: "craft"
68
+ }
69
+
70
+ const decodeRules = compose(
71
+ pickBy((v, k) => k !== 'undefined'),
72
+ reduce(mergeRight, {}),
73
+ map(
74
+ compose(
75
+ ([k, value = true]) => ({ [rules[k]]: value }),
76
+ converge(concat, [compose(of, head), compose(filter(Boolean), of, join('-'), tail)]),
77
+ split('-')
78
+ )
79
+ )
80
+ )
81
+
82
+ const itemFromSku = (sku) => {
83
+ const [defindex, quality, ...more] = sku.split(';')
84
+ const item = {
85
+ defindex,
86
+ quality,
87
+ ...decodeRules(more)
88
+ }
89
+ item.sku = sku
90
+ return item
91
+ }
92
+
93
+ const getName = ({
94
+ defindex,
95
+ quality,
96
+ uncraftable,
97
+ elevated,
98
+ effect,
99
+ killstreakTier,
100
+ festivized,
101
+ target,
102
+ output,
103
+ oq,
104
+ texture,
105
+ wear,
106
+ australium,
107
+ series,
108
+ craft
109
+ },
110
+ bpTexture = false,
111
+ qualityBpStyle = false
112
+ ) => [
113
+ craft && '#' + craft,
114
+ uncraftable && 'Non-Craftable',
115
+ elevated && 'Strange',
116
+ quality && !['6', '15'].includes(quality.toString()) && (qualityBpStyle ? effect : true) && qualityNames[quality],
117
+ oq && oq.toString() !== '6' && qualityNames[oq],
118
+ target && killstreakTier && killstreakTiers[killstreakTier],
119
+ target && safeItems[target].item_name,
120
+ output && safeItems[output].item_name,
121
+ effect && particleEffects[effect],
122
+ festivized && 'Festivized',
123
+ !target && killstreakTier && killstreakTiers[killstreakTier],
124
+ texture && textures[texture],
125
+ bpTexture && '|',
126
+ australium && 'Australium',
127
+ safeItems[defindex].item_name,
128
+ wear && '(' + wears[wear] + ')',
129
+ series && '#' + series
130
+ ].filter(Boolean).join(' ')
131
+
132
+ const itemNameFromSku = (sku) => {
133
+ const item = itemFromSku(sku)
134
+ return getName(item)
135
+ }
136
+
137
+ module.exports = {
138
+ skuFromItem,
139
+ itemFromSku,
140
+ getName,
141
+ itemNameFromSku
142
+ }
package/skuBp.js ADDED
@@ -0,0 +1,87 @@
1
+ const crypto = require('crypto')
2
+ const { safeItems: items } = require('./schemaItems.js')
3
+ const { qualityNames } = require('./schemaHelper.json')
4
+ const { itemFromSku, getName } = require('./sku.js')
5
+ const { omit } = require('ramda')
6
+
7
+ const toBpQuality = (sku) => {
8
+
9
+ const {
10
+ defindex,
11
+ quality,
12
+ effect,
13
+ elevated,
14
+ texture,
15
+ } = itemFromSku(sku)
16
+
17
+ const isWeaponEffect = ['701', '702', '703', '704'].includes(effect)
18
+
19
+ const isPainted = items[defindex].item_name === 'War Paint' || Boolean(texture) || isWeaponEffect
20
+
21
+ return [
22
+ (elevated || quality === '11' && isPainted) && 'Strange',
23
+ isPainted
24
+ ? !elevated && qualityNames[isWeaponEffect ? '5' : '15']
25
+ : qualityNames[quality]
26
+ ].filter(Boolean).join(' ')
27
+ }
28
+
29
+ const toBpName = (sku) => {
30
+
31
+ const item = omit(
32
+ ['quality', 'elevated', 'uncraftable', 'craft', 'target', 'output', 'oq', 'effect'],
33
+ itemFromSku(sku)
34
+ )
35
+
36
+ return getName(item, Boolean(item.texture)).replace('\\n', '%0A')
37
+ }
38
+
39
+ const toBpPriceIndex = (sku) => {
40
+
41
+ const {
42
+ effect,
43
+ killstreakTier,
44
+ target,
45
+ output,
46
+ oq,
47
+ series
48
+ } = itemFromSku(sku)
49
+
50
+ return [
51
+ effect,
52
+ !oq && killstreakTier && target && killstreakTier + '-' + target,//kit
53
+ output && target && oq && output + '-' + oq + '-' + target,//fabricator, strangifier chemistry set
54
+ !target && output && oq && output + '-' + oq, //collector's chemistry set
55
+ !killstreakTier && target && !output && target, //unusualifier
56
+ series
57
+ ].filter(Boolean).join('/')
58
+ }
59
+
60
+ const listingFromSku = (sku) => {
61
+ const { uncraftable } = itemFromSku(sku)
62
+ return {
63
+ quality: toBpQuality(sku),
64
+ craftable: uncraftable ? '0' : '1',
65
+ item_name: toBpName(sku),
66
+ priceindex: toBpPriceIndex(sku)
67
+ }
68
+ }
69
+
70
+ const toBpSku = (sku) => {
71
+ const item = omit(
72
+ ['craft'],
73
+ itemFromSku(sku)
74
+ )
75
+ return getName(item, null, Boolean(item.effect))
76
+ }
77
+
78
+ const toBpId = (sku) => crypto.createHash('md5').update(toBpSku(sku)).digest('hex')
79
+
80
+ module.exports = {
81
+ toBpQuality,
82
+ toBpName,
83
+ toBpId,
84
+ toBpPriceIndex,
85
+ listingFromSku,
86
+ toBpSku
87
+ }
@@ -0,0 +1,99 @@
1
+ const {
2
+ always,
3
+ prop,
4
+ ifElse,
5
+ propEq,
6
+ compose,
7
+ defaultTo,
8
+ __,
9
+ map,
10
+ applyTo,
11
+ complement,
12
+ allPass,
13
+ includes
14
+ } = require('ramda')
15
+
16
+ const { safeItems: items } = require('./schemaItems.js')
17
+ const { textures } = require('./schema.json')
18
+ const { itemFromSku } = require('./sku.js')
19
+
20
+ //collectors chem sets: output
21
+ //strangifier chem sets, strangifier, unusualifier, kit, fab: target
22
+
23
+ const item = ({ defindex, target, output }) => items[target || output || defindex].item_name
24
+
25
+ const quality = ({
26
+ defindex,
27
+ quality,
28
+ effect,
29
+ texture,
30
+ elevated
31
+ }) => items[defindex].item_name === 'War Paint' || (Boolean(texture) || ['701', '702', '703', '704'].includes(effect))
32
+ ? (elevated ? '11' : '5')
33
+ : quality
34
+
35
+ const australium = ifElse(
36
+ propEq('australium', true),
37
+ always(1),
38
+ always(-1)
39
+ )
40
+
41
+ const killstreak_tier = compose(
42
+ defaultTo(0),
43
+ prop('killstreakTier')
44
+ )
45
+
46
+ const craftable = ifElse(
47
+ propEq('uncraftable', true),
48
+ always(-1),
49
+ always(1)
50
+ )
51
+
52
+ const particle = prop('effect')
53
+
54
+ const item_type = ({ target, output }) =>
55
+ target
56
+ ? 'target'
57
+ : output
58
+ ? 'output'
59
+ : undefined
60
+
61
+ const wear_tier = prop('wear')
62
+
63
+ const texture_name = compose(prop(__, textures), prop('texture'))
64
+
65
+ const elevated = ifElse(
66
+ allPass([
67
+ propEq('elevated', true),
68
+ compose(
69
+ complement(includes)(__, ['701', '702', '703', '704']),
70
+ prop('effect')
71
+ )
72
+ ]),
73
+ always(11),
74
+ always(undefined)
75
+ )
76
+
77
+ const fns = {
78
+ item_names: always(1),
79
+ item,
80
+ quality,
81
+ intent: always('dual'),
82
+ australium,
83
+ killstreak_tier,
84
+ craftable,
85
+ page_size: always(30),
86
+ particle,
87
+ item_type,
88
+ texture_name,
89
+ wear_tier,
90
+ elevated
91
+ }
92
+
93
+ const toSearchParams = compose(
94
+ map(__, fns),
95
+ applyTo,
96
+ itemFromSku
97
+ )
98
+
99
+ module.exports = { toSearchParams }
package/todo.txt ADDED
@@ -0,0 +1,24 @@
1
+
2
+ option 1:
3
+
4
+ call the sagas anywhere your redux-saga app + add the api context from the api.js
5
+
6
+ const { fetchAppDataInventory } = require('@juice789/tf2items')
7
+
8
+ function* fetchAppDataINvnetorySaga(inventory){
9
+ const fetched = yield call(fetchAppDataINventry, inventory)
10
+ }
11
+
12
+ function* fetchInventorySaga(){
13
+ yielt takeEvery('FETCH_INVENTORY', fetchAppDataInventorySaga)
14
+ }
15
+
16
+ option 2:
17
+
18
+ initialize the library as a module, functions are available as promises
19
+
20
+ const { getInstance } = require('@juice789/tf2items')
21
+
22
+ const app = getInstance(options)
23
+
24
+ app.saveSchema().then(console.log)
@@ -0,0 +1,106 @@
1
+ const { prop, pick, map, compose, complement, includes, equals, length, allPass, mapObjIndexed, when, has, __, chain, assoc, pathEq, omit, split, keys, propEq, propOr, nth, of, range, path, uncurryN, mergeDeepRight, reduce, concat } = require('ramda')
2
+ const { qualityIds, strangifierTargets, crateSeries, chemsetDefindex } = require('./schemaHelper.json')
3
+
4
+ const propsToKeep = [
5
+ 'name',
6
+ 'defindex',
7
+ 'item_class',
8
+ 'item_name',
9
+ 'propername',
10
+ 'item_slot',
11
+ 'used_by_classes',
12
+ 'untradable',
13
+ 'festivized',
14
+ 'type2',
15
+ 'texture',
16
+ 'target',
17
+ 'series',
18
+ 'seriesHidden',
19
+ 'item_quality'
20
+ ]
21
+
22
+ const transformItems = uncurryN(3, (collections, itemsApi) => compose(
23
+ map((item) => mergeDeepRight(collections[item.name], item)),
24
+ reduce(mergeDeepRight, {}),
25
+ concat([itemsApi, crateSeries, strangifierTargets, chemsetDefindex]),
26
+ of,
27
+ map(
28
+ compose(
29
+ pick(propsToKeep),
30
+ when(
31
+ allPass([
32
+ compose(Boolean, prop('item_slot')),
33
+ compose(includes(__, ['primary', 'melee', 'secondary', 'pda', 'pda2', 'building']), prop('item_slot')),
34
+ compose(
35
+ includes(__, range(2, 9)),
36
+ length,
37
+ prop('used_by_classes')
38
+ )
39
+ ]),
40
+ assoc('used_by_classes', ['multi'])
41
+ ),
42
+ when(
43
+ allPass([
44
+ compose(Boolean, prop('item_slot')),
45
+ compose(equals(9), length, prop('used_by_classes'))
46
+ ]),
47
+ assoc('used_by_classes', ['all'])
48
+ ),
49
+ when(
50
+ has('used_by_classes'),
51
+ chain(assoc('used_by_classes'), compose(keys, prop('used_by_classes')))
52
+ ),
53
+ when(
54
+ compose(complement(Boolean), prop('item_name')),
55
+ chain(assoc('item_name'), prop('name'))
56
+ ),
57
+ when(
58
+ path(['static_attrs', 'tool target item']),
59
+ chain(assoc('target'), compose(of, path(['static_attrs', 'tool target item'])))
60
+ ),
61
+ when(
62
+ path(['static_attrs', 'hide crate series number']),
63
+ assoc('seriesHidden', true)
64
+ ),
65
+ when(
66
+ path(['static_attrs', 'set supply crate series']),
67
+ chain(assoc('series'), compose(of, path(['static_attrs', 'set supply crate series'])))
68
+ ),
69
+ when(
70
+ path(['attributes', 'tool target item', 'value']),
71
+ chain(assoc('target'), compose(of, path(['attributes', 'tool target item', 'value'])))
72
+ ),
73
+ when(
74
+ pathEq(['tags', 'can_be_festivized'], '1'),
75
+ assoc('festivized', '1')
76
+ ),
77
+ when(
78
+ pathEq(['attributes', 'cannot trade', 'value'], '1'),
79
+ assoc('untradable', '1')
80
+ ),
81
+ when(
82
+ pathEq(['tool', 'type'], 'paint_can'),
83
+ assoc('type2', 'paint')
84
+ ),
85
+ when(
86
+ pathEq(['tool', 'type'], 'decoder_ring'),
87
+ assoc('type2', 'key')
88
+ ),
89
+ when(
90
+ has('item_quality'),
91
+ chain(assoc('item_quality'), compose(prop(__, qualityIds), nth(0), split(' '), prop('item_quality')))
92
+ ),
93
+ when(
94
+ allPass([
95
+ compose(includes('paintkitweapon'), propOr('', 'item_quality')),
96
+ complement(propEq)('defindex', '9536')
97
+ ]),
98
+ chain(assoc('texture'), path(['static_attrs', 'paintkit_proto_def_index']))
99
+ )
100
+ )
101
+ ),
102
+ omit(['default']),
103
+ mapObjIndexed((v, k) => assoc('defindex', k, v))
104
+ ))
105
+
106
+ module.exports = { transformItems }