-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathparsers.js
613 lines (551 loc) · 15.6 KB
/
parsers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/* eslint-disable i18n-text/no-en */
/* eslint eslint-comments/no-use: off */
/**
* Brand specific implementations of SKU parsing.
*/
import {Product} from './product'
// ADATA (eg. AX4U460038G19-DRZ)
export function ADATA(sku) {
// https://regex101.com/r/MWiKJR/2
const regex = /AX4U(\d{4})3(\d)G(\d{2})C?-([BSDQ])([\w]{1,2}[\d]{0,2})/g
const groups = regex.exec(sku)
const brand = 'ADATA'
const code = groups[5]
const size = groups[2]
const sticks = groups[4] === 'Q' ? '4' : groups[4] === 'D' ? '2' : '1'
const speed = groups[1]
const cas = groups[3]
const color = null
const ecc = false
let series = ''
if (code === '' || code === 'RS' || code === 'R40') {
series = 'Spectrix D40'
} else if (code === 'R41' || code === 'T41') {
series = 'Spectrix D41'
} else if (code === 'T60') {
series = 'Spectrix D60G'
} else if (code === 'R80') {
series = 'Spectrix D80'
} else if (code === 'RZ') {
series = 'XPG Z1'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Apacer (eg. EK.16GA5.GGBK2)
export function Apacer(sku) {
return {
'EK.16GA5.GGBK2': Product('Apacer', 'Blade', sku, '4133', '18', '16', '2', null, false),
'EK.16GA4.GFAK2': Product('Apacer', 'Commando', sku, '3600', '17', '16', '2', null, false),
}[sku]
}
// Avexir (eg. AVD4UZ136001708G-2BZ1RR)
export function Avexir(sku) {
// https://regex101.com/r/T7pqzr/1
const regex = /AVD4UZ1([\d]{4})([\d]{2})[0]?([1,3,6]?[2,4,6,8])G-([\d])([\w]{3})([\w]{2})/g
const groups = regex.exec(sku)
const brand = 'Avexir'
const code = groups[5]
const size = (parseInt(groups[3]) * parseInt(groups[4])).toString()
const speed = groups[1]
const cas = groups[2]
const sticks = groups[4]
const ecc = false
let series = ''
if (code === 'BZ1') {
series = 'Blitz'
}
let color = groups[6]
if (color === 'RR') {
color = 'Red'
} else if (color === 'GY') {
color = 'Gold'
} else if (code === 'SW') {
color = 'White'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
const CorsairColors = {
null: 'black',
C: 'chrome',
M: 'black',
T: 'torque',
R: 'red',
W: 'white',
}
// Corsair (eg. CMD32GX4M4B3600C16)
export function Corsair(sku) {
// https://regex101.com/r/lM1T9q/4
const regex = /C([A-Z]{2})(\d{2,3})GX(\d)M(\d)[A-Z](\d{4})C(\d{2})([A-Z])?/g
const groups = regex.exec(sku)
const brand = 'Corsair'
const code = groups[1]
const size = groups[2]
const sticks = groups[4]
const speed = groups[5]
const cas = groups[6]
const color = CorsairColors[groups[7]]
const ecc = false
let series = ''
if (code === 'MD') {
series = 'Dominator'
} else if (code === 'MT') {
series = 'Dominator RGB'
} else if (code === 'MK' || code === 'MU') {
series = 'Vengeance'
} else if (code === 'MR') {
series = 'Vengeance RGB'
} else if (code === 'MW') {
series = 'Vengeance RGB Pro'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Team Group (eg. TXD416G3733HC18ADC01)
export function TeamGroup(sku) {
// https://regex101.com/r/aldDGe/1
const regex = /T([\w]{1,3})D4(\d{2})G(\d{4})HC(\d{2})\w([DQ]?)\w{2,3}/g
const groups = regex.exec(sku)
const brand = 'Team Group'
const code = groups[1]
const size = groups[2]
const speed = groups[3]
const cas = groups[4]
const sticks = groups[5] === 'Q' ? '4' : '2'
const ecc = false
let series = ''
let color = null
if (code.slice(0, 2) === 'DP') {
series = 'Xtreem Dark Pro'
color = code[2] === 'R' ? 'red' : 'grey'
} else if (code === 'X') {
series = 'T-Force Xtreem'
color = 'silver'
} else if (code === 'XK') {
series = 'T-Force Xtreem'
color = 'black'
} else if (code === 'XB') {
series = 'T-Force Xtreem' // 8Pack Edition
} else if (code === 'XG') {
series = 'T-Force Xtreem' // Gold
color = 'gold'
} else if (code === 'XOB') {
series = 'T-Force Xtreem' // OnePageBook Edition
} else if (code === 'L') {
series = 'T-Force Vulcan'
} else if (code === 'F10') {
series = 'T-Force Xtreem'
color = 'ARGB'
} else if (code === 'F13') {
series = 'T-Force Xtreem'
color = 'ARGB White'
} else if (code[0] === 'F') {
series = 'T-Force Night Hawk RGB'
color = 'RGB'
} else if (code === 'DZF') {
series = 'T-Force Dark Z FPS'
color = 'black'
} else if (code === 'TCE') {
series = 'T-Create Expert'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
const GskillTridentZColors = {
'': 'silver-red',
A: 'silver-red',
B: 'silver-red',
KK: 'black-black',
KKE: 'black-black',
KKF: 'black-black',
KW: 'black-white',
KO: 'black-orange',
KY: 'black-yellow',
R: 'rgb',
RF: 'rgb',
RX: 'rgb',
SK: 'silver-black',
SW: 'silver-white',
SWE: 'silver-white',
SWF: 'silver-white',
}
const GskillTridentZRoyalColors = {
S: 'silver',
G: 'gold',
}
const GskillTridentZRoyalEliteColors = {
S: 'silver',
G: 'gold',
SA: 'silver',
GA: 'gold',
}
const GskillRipjawsColors = {
G: 'black',
K: 'black',
KD: 'black', // with fans
R: 'red',
RD: 'red', // with fans
S: 'silver',
}
// G-Skill (eg. F4-3200C14D-16GFX)
export function GSkill(sku) {
// https://regex101.com/r/CjUiJS/4
const regex = /F4-(\d{4})C(\d{2})([SDQ2]{1,2})-(\d{2,3})G([A-Z]{2,6})/g
const groups = regex.exec(sku)
const brand = 'G.Skill'
const speed = groups[1]
const cas = groups[2]
const sticks = groups[3] === 'Q2' ? '8' : groups[3] === 'Q' ? '4' : groups[3] === 'D' ? '2' : '1'
const size = groups[4]
const code = groups[5]
const ecc = false
let series = ''
let color = null
if (code.indexOf('TZN') === 0) {
series = 'Trident Z Neo'
color = 'rgb'
} else if (code.indexOf('TZ') === 0) {
series = 'Trident Z'
color = GskillTridentZColors[code.replace('TZ', '')]
} else if (code.indexOf('TR') === 0) {
series = 'Trident Z Royal'
color = GskillTridentZRoyalColors[code.replace('TR', '')]
} else if (code.indexOf('TE') === 0) {
series = 'Trident Z Royal Elite'
color = GskillTridentZRoyalEliteColors[code.replace('TE', '')]
} else if (code.indexOf('FX') === 0) {
series = 'Flare X'
} else if (code.indexOf('SX') === 0) {
series = 'Sniper X'
} else if (code[0] === 'V') {
series = 'Ripjaws V'
color = GskillRipjawsColors[code[1]]
} else if (code.indexOf('RS') === 0) {
series = 'Ripjaws so-dimm'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Samsung (eg. M391A1K43BB1-CRC)
export function Samsung(sku) {
// https://regex101.com/r/smbbzc/1
const regex = /M3(\d{2})A(\d{1})K43(BB\d{1})-(C[A-Z]{2})/g
const groups = regex.exec(sku)
const brand = 'Samsung'
const code = groups[4]
const size = groups[2] === '2' ? '16' : '8'
const sticks = '1'
const color = null
const ecc = groups[1] === '91'
const series = ecc ? 'ECC' : 'NON-ECC'
let speed = ''
let cas = ''
if (code === 'CPB') {
speed = '2133'
cas = '15'
} else if (code === 'CRC') {
speed = '2400'
cas = '17'
} else if (code === 'CTD') {
speed = '2666'
cas = '19'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
const GeilSeries = {
EX: 'EVO X',
EXB: 'EVO X',
EXG: 'EVO X',
EXW: 'EVO X',
FR: 'EVO Forza',
PR: 'EVO Potenza',
WW: 'White Dragon',
LS: 'Super Luce RGB Sync',
}
// GEiL (eg. GEX416GB3200C16ADC)
export function Geil(sku) {
// https://regex101.com/r/mOcKR8/8
const regex = /G([A-Z]{2,6})\w(\d{1,2})GB(\d{4})C(\d{2})A?(\w)C/g
const groups = regex.exec(sku)
const brand = 'GEiL'
const series = GeilSeries[groups[1]] || 'das'
const speed = groups[3]
const cas = groups[4]
const size = groups[2]
const sticks = groups[5] === 'Q' ? '4' : '2'
const ecc = false
let color = ''
if (sku.indexOf('EXG') > 0 || sku.indexOf('EXW') > 0) {
color = 'white'
} else if (sku.indexOf('EX4') > 0 || sku.indexOf('EXB') > 0) {
color = 'black'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Hall of Fame / Galax (eg. HOF4CXLBS3600K17LD162C) or KFA2 (eg. HOF4CXLBS3600K17LD162K)
export function HOF(sku) {
// https://regex101.com/r/pNEsPg/1
const regex = /([A-Z]{3,6})4([A-Z]{3})[1-4]?([A-Z]{2,3})(\d{4})[A-Z](\d{2})[A-Z]{2}(\d{2})(\d)([CK])/g
const groups = regex.exec(sku)
const brand = groups[8] === 'K' ? 'KFA2' : 'Galax'
const code = groups[3]
const code2 = groups[2]
const speed = groups[4]
const cas = groups[5]
let size = groups[6]
const sticks = groups[7]
const color = null
const ecc = false
let series = ''
if (code === 'BS') {
series = 'Hall of Fame'
} else if (code === 'BST' && (code2 === 'CXL' || code2 === 'KXL')) {
series = 'Hall of Fame Extreme'
} else if (code === 'BST' && code2 === 'CRL') {
series = 'Hall of Fame OC Lab Arduino'
} else if (code === 'BST' && code2 === 'RJL') {
series = 'Hall of Fame OC Lab Water Cooling'
} else if (code === 'CST') {
series = 'Hall of Fame II'
}
// GALAX HOF Extreme OC Lab Edition DDR4-4600MHz 16GB Kit
// see http://galaxstore.net/GALAX-HOF-Extreme-OC-Lab-Edition-DDR4-4600MHz-16GB-Kit_p_182.html
if (sku === 'HOF4KXL1BST4600S19TC081CZGG') {
size = '16'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Galax Hall of Fame (ES) (eg. HEX4D16G4800C19)
export function HEX(sku) {
// https://regex101.com/r/fBfV5X/1
const regex = /(HEX)4(D)(\d{2})(G)(\d{4})C(\d{2})/g
const groups = regex.exec(sku)
const brand = 'Galax'
const series = 'Hall of Fame (ES)'
const speed = groups[5]
const cas = groups[6]
const size = groups[3]
const sticks = groups[1] === 'Q' ? 4 : 2
const color = null
const ecc = false
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
const KingstonSeries = {
PB3: 'Hyper X Predator',
PB3A: 'Hyper X Predator RGB',
}
// Kingston Hyper X (eg. HX436C17PB3K4/32)
export function Kingston(sku) {
// https://regex101.com/r/sZJJWU/2
const regex = /HX4(\d{2})C(\d{2})(PB3A?)K?([\d]?)\/(\d{1,2})/g
const groups = regex.exec(sku)
const brand = 'Kingston'
const series = KingstonSeries[groups[3]]
const speed = groups[1] === '13' ? '4133' : `${groups[1]}00`
const cas = groups[2]
const size = groups[5]
const sticks = groups[4] || '1'
const color = null
const ecc = false
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
const PatriotSeries = {
V: 'Viper 4',
VE: 'Viper 4 Elite',
VLW: 'Viper LED',
VR: 'Viper RGB',
VS: 'Viper Steel',
VB: 'Viper Blackout',
}
// Patriot Viper (eg. PV416G373C7K)
export function Patriot(sku) {
// https://regex101.com/r/yYVaIh/4
const regex = /P([BVELWRS]*)4(\d{2})G(\d{3})C(\d{1})K/g
const groups = regex.exec(sku)
const brand = 'Patriot'
const series = PatriotSeries[groups[1]]
const speed = `${groups[3]}${groups[3][2]}`
const cas = `1${groups[4]}`
const size = groups[2]
const sticks = '2'
const color = null
const ecc = false
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// SuperTalent (eg. F3600UX16G)
export function SuperTalent(sku) {
// https://regex101.com/r/kKlg3h/3
const regex = /F(\d{4})U([ABX])(\d{1,2})G/g
const groups = regex.exec(sku)
const brand = 'Super Talent'
const series = 'Project X'
const speed = groups[1]
const cas = '17'
const size = groups[3]
const sticks = groups[2] === 'X' ? '2' : '1'
const color = null
const ecc = false
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Crucial Ballistix Elite (eg. BLE2K8G4D34AEEAK) - no info on cas latency
export function Crucial(sku) {
// https://regex101.com/r/WvBqxu/1
const regex = /BLE([\d]?)\w?([\d])G4D(\d{2})AEEAK/g
const groups = regex.exec(sku)
const brand = 'Crucial'
const series = 'Ballistix Elite'
const speed = `${groups[3]}00`
const cas = '17'
const sticks = groups[1] === '' ? '1' : groups[1]
const size = (parseInt(groups[2]) * parseInt(sticks)).toString()
const color = null
const ecc = false
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Inno3d iChill RGB (eg. RCX2-16G3600R) - no info on cas latency
export function Inno3d(sku) {
// https://regex101.com/r/R3HIDO/1
const regex = /RCX([\d])-([\d]{2})G(\d{4})([A|R])/g
const groups = regex.exec(sku)
const brand = 'Inno3d'
const series = 'iChill RGB'
const speed = groups[3]
const sticks = groups[1]
const size = groups[2]
const ecc = false
let cas = null
if (speed === '3600') {
cas = '17'
} else if (speed === '4000') {
cas = '19'
}
let color = groups[4]
if (color === 'A') {
color = 'Aura Sync'
} else if (color === 'R') {
color = 'RGB'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Zadak Shield (eg. ZD4-SHC3200C14-64GDSD)
export function Zadak(sku) {
// https://regex101.com/r/LTr1ZE/1/
const regex = /ZD4-SH[C|K]([\d]{4})C([\d]{2})-([\d]{2})G/g
const groups = regex.exec(sku)
const brand = 'Zadak'
const series = 'Shield'
const speed = groups[1]
const cas = groups[2]
const color = null
const sticks = '2'
const size = groups[3] === '08' ? '16' : groups[3]
const ecc = false
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// OLOy (eg. ND4U0836144BRADE)
export function OLOy(sku) {
// https://regex101.com/r/iHims8/1/
const regex = /ND4U([\d]{2})([\d]{2})([\d]{2})\d([A-Z]{3})DE/g
const groups = regex.exec(sku)
const brand = 'OLOy'
const series = 'Blade'
const speed = `${groups[2]}00`
const cas = groups[3]
const size = groups[1].replaceAll('0', '')
const sticks = 2
const color = 'RGB'
const ecc = false
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// HP (eg. 48U41AA)
export function HP(sku) {
// https://regex101.com/r/CF3TJ0/1
const regex = /([\d]{2})[UN]([\d])([\d])AA/g
const groups = regex.exec(sku)
const brand = 'HP'
const series = 'V10'
const cas = '14'
const sticks = 2
const color = 'RGB'
const ecc = false
let speed = groups[1]
if (speed === '48') {
speed = '3200'
} else if (speed === '54') {
speed = '3600'
}
let size = groups[3]
if (size === '1') {
size = '16'
} else if (size === '3') {
size = '8'
} else if (size === '5') {
size = '32'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// Asgard (eg. VMA47UG-AMC1U2AV3)
export function Asgard(sku) {
// https://regex101.com/r/uqlVql/1
const regex = /VMA4(\d)UG-AMC1U2(\w{2})3/g
const groups = regex.exec(sku)
const brand = 'Asgard'
const size = '8'
const sticks = 2
const color = 'Black'
const ecc = false
let series = groups[2]
if (series === 'AV') {
series = 'Bragi V3'
} else if (series === '3T') {
series = 'Loki'
}
const model = groups[1]
let cas = ''
let speed = ''
if (model === '7') {
speed = '3600'
cas = '14'
} else if (model === '8') {
speed = '4000'
cas = '17'
} else if (model === '9') {
speed = '4000'
cas = '16'
}
return Product(brand, series, sku, speed, cas, size, sticks, color, ecc)
}
// turns any SKU into a Product
export function parse(sku) {
const parser = {
48: HP,
54: HP,
AV: Avexir,
AX: ADATA,
BL: Crucial,
CM: Corsair,
EK: Apacer,
F3: SuperTalent,
F4: GSkill,
GE: Geil,
GF: Geil,
GL: Geil,
GP: Geil,
GW: Geil,
HO: HOF,
HE: HEX,
HX: Kingston,
M3: Samsung,
ND: OLOy,
PV: Patriot,
RC: Inno3d,
TD: TeamGroup,
TF: TeamGroup,
TL: TeamGroup,
TT: TeamGroup,
TX: TeamGroup,
VM: Asgard,
ZD: Zadak,
}[sku.slice(0, 2)]
if (parser === undefined) {
// no parser found
return
}
return parser(sku)
}