* Returns a set of experiment IDs currently on. * @param {Window} win * @return {ExperimentTogglesMap}
(win)
| 181 | * @return {ExperimentTogglesMap} |
| 182 | */ |
| 183 | function getExperimentToggles(win) { |
| 184 | let experimentsString = ''; |
| 185 | try { |
| 186 | if ('localStorage' in win) { |
| 187 | experimentsString = win.localStorage.getItem(LOCAL_STORAGE_KEY) ?? ''; |
| 188 | } |
| 189 | } catch { |
| 190 | dev().warn(TAG, 'Failed to retrieve experiments from localStorage.'); |
| 191 | } |
| 192 | const tokens = experimentsString?.split(/\s*,\s*/g) || []; |
| 193 | |
| 194 | const toggles = map(); |
| 195 | for (const token of tokens) { |
| 196 | if (!token) { |
| 197 | continue; |
| 198 | } |
| 199 | if (token[0] == '-') { |
| 200 | toggles[token.substr(1)] = false; |
| 201 | } else { |
| 202 | toggles[token] = true; |
| 203 | } |
| 204 | } |
| 205 | return toggles; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Saves a set of experiment IDs currently on. |
no test coverage detected