-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
198 lines (187 loc) · 4 KB
/
index.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
'use strict'
const MODEL_S = [
['60D', [['BT60', 'DV4W']]],
['60', [['BT60', 'DV2W']]],
['70', [['BT70', 'DV2W']]],
['70D', [['BT70', 'DV4W']]],
[
'75',
[
['BTX5', 'DV2W'],
['BTX7', 'DV2W'],
['BTX8', 'DV2W']
]
],
[
'75D',
[
['BTX5', 'DV4W'],
['BTX7', 'DV4W'],
['BTX8', 'DV4W']
]
],
['P85+', [['PX01']]],
[
'P85',
[
['BT85', 'X024', 'DV2W'],
['PBT85', 'X024', 'DV2W']
]
],
['85', [['BT85', 'DV2W']]],
['85D', [['BT85', 'DV4W']]],
['P85D', [['P85D'], ['PBT85', 'X024', 'DV4W']]],
[
'P90D',
[
['X024', 'BTX4', 'DV4W'],
['X024', 'PX4D', 'DV4W']
]
],
['90', [['BTX4', 'DV2W']]],
['90D', [['BTX4', 'DV4W']]],
['P100D', [['BTX6', 'X024', 'DV4W']]],
['100D', [['BTX6', 'DV4W']]],
['Standard Range', [['MTS01'], ['MTS17']]],
['Long Range', [['MTS03'], ['MTS05'], ['MTS10']]],
['Performance', [['MTS04'], ['MTS06'], ['MTS08']]],
['Long Range Plus', [['MTS07']]],
['', [['MTS13'], ['MTS18']]],
['Plaid', [['MTS11'], ['MTS12'], ['MTS14'], ['MTS19'], ['MTS21']]],
['Plaid+', [['MTS09']]]
]
const MODEL_X = [
[
'75D',
[
['BTX5', 'DV4W'],
['BTX7', 'DV4W'],
['BTX8', 'DV4W']
]
],
[
'P90D',
[
['X024', 'BTX4', 'DV4W'],
['X024', 'PX4D', 'DV4W']
]
],
['90D', [['BTX4', 'DV4W']]],
['P100D', [['BTX6', 'X024', 'DV4W']]],
['100D', [['BTX6', 'DV4W']]],
['Standard Range', [['MTX01'], ['MTX17']]],
['Long Range', [['MTX03'], ['MTX10']]],
['Long Range Plus', [['MTX05'], ['MTX07']]],
['Performance', [['MTX04'], ['MTX06'], ['MTX08']]],
['', [['MTX12'], ['MTX13'], ['MTX15'], ['MTX18'], ['MTX20']]],
['Plaid', [['MTX11'], ['MTX14'], ['MTX16'], ['MTX19'], ['MTX21']]],
['Plaid+', [['MTX09']]]
]
const MODEL_3 = [
['', [['MT322'], ['MT351']]],
['Standard Range', [['MT300']]],
[
'Standard Range Plus',
[
['MT301'],
['MT308'],
['MT309'],
['MT314'],
['MT320'],
['MT327'],
['MT332'],
['MT333'],
['MT336'],
['MT337']
]
],
['Mid Range', [['MT305'], ['MT307']]],
['Long Range RWD', [['MT302'], ['MT341'], ['MT334'], ['MT355'], ['MT356']]],
[
'Long Range AWD',
[
['MT303'],
['MT310'],
['MT315'],
['MT316'],
['MT321'],
['MT323'],
['MT324'],
['MT328'],
['MT352'],
['MT354'],
['MT357']
]
],
[
'Performance',
[
['MT304'],
['MT311'],
['MT317'],
['MT325'],
['MT329'],
['MT339'],
['MT340'],
['MT353']
]
]
]
const MODEL_Y = [
['', [['MTY18'], ['MTY19'], ['MTY23'], ['MTY26'], ['MTY32']]],
['Standard Range', [['MTY01'], ['MTY08'], ['MTY13']]],
['Long Range RWD', [['MTY02'], ['MTY29'], ['MTY35'], ['MTY36']]],
[
'Long Range AWD',
[
['MTY03'],
['MTY06'],
['MTY07'],
['MTY09'],
['MTY11'],
['MTY14'],
['MTY20'],
['MTY24'],
['MTY27'],
['MTY33'],
['MTY37']
]
],
[
'Performance',
[
['MTY04'],
['MTY05'],
['MTY10'],
['MTY12'],
['MTY21'],
['MTY25'],
['MTY28'],
['MTY34'],
['MTY38']
]
]
]
const getCollection = optionCodes => {
if (optionCodes.includes('MDLS')) return MODEL_S
if (optionCodes.includes('MDLX')) return MODEL_X
if (optionCodes.includes('MDL3')) return MODEL_3
if (optionCodes.includes('MDLY')) return MODEL_Y
}
const fromOptionCodes = ({ onError, ...opts } = {}) => {
const { optionCodes } = opts
const collection = getCollection(optionCodes)
let result
collection.find(([title, allConditions]) => {
const isMatch = allConditions.some(conditions =>
conditions.every(optionCode => optionCodes.includes(optionCode))
)
return isMatch && (result = title)
})
return result ?? onError?.(opts)
}
module.exports = fromOptionCodes
module.exports.MODEL_S = MODEL_S
module.exports.MODEL_X = MODEL_X
module.exports.MODEL_3 = MODEL_3
module.exports.MODEL_Y = MODEL_Y