This repository was archived by the owner on Jul 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 524
Expand file tree
/
Copy pathutils.js
More file actions
166 lines (157 loc) · 5.59 KB
/
Copy pathutils.js
File metadata and controls
166 lines (157 loc) · 5.59 KB
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
export function matchStateToTerm(state, value) {
return (
state.name.toLowerCase().indexOf(value.toLowerCase()) !== -1 ||
state.abbr.toLowerCase().indexOf(value.toLowerCase()) !== -1
)
}
export function matchStateToTermWithHeaders(state, value) {
return (
state.header ||
state.name.toLowerCase().indexOf(value.toLowerCase()) !== -1 ||
state.abbr.toLowerCase().indexOf(value.toLowerCase()) !== -1
)
}
/**
* An example of how to implement a relevancy-based sorting method. States are
* sorted based on the location of the match - For example, a search for "or"
* will return "Oregon" before "North Carolina" even though "North Carolina"
* would normally sort above Oregon. Strings where the match is in the same
* location (or there is no match) will be sorted alphabetically - For example,
* a search for "or" would return "North Carolina" above "North Dakota".
*/
export function sortStates(a, b, value) {
const aLower = a.name.toLowerCase()
const bLower = b.name.toLowerCase()
const valueLower = value.toLowerCase()
const queryPosA = aLower.indexOf(valueLower)
const queryPosB = bLower.indexOf(valueLower)
if (queryPosA !== queryPosB) {
return queryPosA - queryPosB
}
return aLower < bLower ? -1 : 1
}
export function fakeRequest(value, cb) {
return setTimeout(cb, 500, value ?
getStates().filter(state => matchStateToTerm(state, value)) :
getStates()
)
}
export function fakeCategorizedRequest(value, cb) {
setTimeout(cb, 500, value ?
getCategorizedStates().filter(state => matchStateToTermWithHeaders(state, value)) :
getCategorizedStates()
)
}
export function getStates() {
return [
{ abbr: 'AL', name: 'Alabama' },
{ abbr: 'AK', name: 'Alaska' },
{ abbr: 'AZ', name: 'Arizona' },
{ abbr: 'AR', name: 'Arkansas' },
{ abbr: 'CA', name: 'California' },
{ abbr: 'CO', name: 'Colorado' },
{ abbr: 'CT', name: 'Connecticut' },
{ abbr: 'DE', name: 'Delaware' },
{ abbr: 'FL', name: 'Florida' },
{ abbr: 'GA', name: 'Georgia' },
{ abbr: 'HI', name: 'Hawaii' },
{ abbr: 'ID', name: 'Idaho' },
{ abbr: 'IL', name: 'Illinois' },
{ abbr: 'IN', name: 'Indiana' },
{ abbr: 'IA', name: 'Iowa' },
{ abbr: 'KS', name: 'Kansas' },
{ abbr: 'KY', name: 'Kentucky' },
{ abbr: 'LA', name: 'Louisiana' },
{ abbr: 'ME', name: 'Maine' },
{ abbr: 'MD', name: 'Maryland' },
{ abbr: 'MA', name: 'Massachusetts' },
{ abbr: 'MI', name: 'Michigan' },
{ abbr: 'MN', name: 'Minnesota' },
{ abbr: 'MS', name: 'Mississippi' },
{ abbr: 'MO', name: 'Missouri' },
{ abbr: 'MT', name: 'Montana' },
{ abbr: 'NE', name: 'Nebraska' },
{ abbr: 'NV', name: 'Nevada' },
{ abbr: 'NH', name: 'New Hampshire' },
{ abbr: 'NJ', name: 'New Jersey' },
{ abbr: 'NM', name: 'New Mexico' },
{ abbr: 'NY', name: 'New York' },
{ abbr: 'NC', name: 'North Carolina' },
{ abbr: 'ND', name: 'North Dakota' },
{ abbr: 'OH', name: 'Ohio' },
{ abbr: 'OK', name: 'Oklahoma' },
{ abbr: 'OR', name: 'Oregon' },
{ abbr: 'PA', name: 'Pennsylvania' },
{ abbr: 'RI', name: 'Rhode Island' },
{ abbr: 'SC', name: 'South Carolina' },
{ abbr: 'SD', name: 'South Dakota' },
{ abbr: 'TN', name: 'Tennessee' },
{ abbr: 'TX', name: 'Texas' },
{ abbr: 'UT', name: 'Utah' },
{ abbr: 'VT', name: 'Vermont' },
{ abbr: 'VA', name: 'Virginia' },
{ abbr: 'WA', name: 'Washington' },
{ abbr: 'WV', name: 'West Virginia' },
{ abbr: 'WI', name: 'Wisconsin' },
{ abbr: 'WY', name: 'Wyoming' }
]
}
export function getCategorizedStates() {
return [
{ header: 'West' },
{ abbr: 'AZ', name: 'Arizona' },
{ abbr: 'CA', name: 'California' },
{ abbr: 'CO', name: 'Colorado' },
{ abbr: 'ID', name: 'Idaho' },
{ abbr: 'MT', name: 'Montana' },
{ abbr: 'NV', name: 'Nevada' },
{ abbr: 'NM', name: 'New Mexico' },
{ abbr: 'OK', name: 'Oklahoma' },
{ abbr: 'OR', name: 'Oregon' },
{ abbr: 'TX', name: 'Texas' },
{ abbr: 'UT', name: 'Utah' },
{ abbr: 'WA', name: 'Washington' },
{ abbr: 'WY', name: 'Wyoming' },
{ header: 'Southeast' },
{ abbr: 'AL', name: 'Alabama' },
{ abbr: 'AR', name: 'Arkansas' },
{ abbr: 'FL', name: 'Florida' },
{ abbr: 'GA', name: 'Georgia' },
{ abbr: 'KY', name: 'Kentucky' },
{ abbr: 'LA', name: 'Louisiana' },
{ abbr: 'MS', name: 'Mississippi' },
{ abbr: 'NC', name: 'North Carolina' },
{ abbr: 'SC', name: 'South Carolina' },
{ abbr: 'TN', name: 'Tennessee' },
{ abbr: 'VA', name: 'Virginia' },
{ abbr: 'WV', name: 'West Virginia' },
{ header: 'Midwest' },
{ abbr: 'IL', name: 'Illinois' },
{ abbr: 'IN', name: 'Indiana' },
{ abbr: 'IA', name: 'Iowa' },
{ abbr: 'KS', name: 'Kansas' },
{ abbr: 'MI', name: 'Michigan' },
{ abbr: 'MN', name: 'Minnesota' },
{ abbr: 'MO', name: 'Missouri' },
{ abbr: 'NE', name: 'Nebraska' },
{ abbr: 'OH', name: 'Ohio' },
{ abbr: 'ND', name: 'North Dakota' },
{ abbr: 'SD', name: 'South Dakota' },
{ abbr: 'WI', name: 'Wisconsin' },
{ header: 'Northeast' },
{ abbr: 'CT', name: 'Connecticut' },
{ abbr: 'DE', name: 'Delaware' },
{ abbr: 'ME', name: 'Maine' },
{ abbr: 'MD', name: 'Maryland' },
{ abbr: 'MA', name: 'Massachusetts' },
{ abbr: 'NH', name: 'New Hampshire' },
{ abbr: 'NJ', name: 'New Jersey' },
{ abbr: 'NY', name: 'New York' },
{ abbr: 'PA', name: 'Pennsylvania' },
{ abbr: 'RI', name: 'Rhode Island' },
{ abbr: 'VT', name: 'Vermont' },
{ header:'Pacific' },
{ abbr: 'AK', name: 'Alaska' },
{ abbr: 'HI', name: 'Hawaii' },
]
}