const toError = (message) => ({
code: 'error',
message
});
const toInfo = (message) => ({
code: 'info',
message
});
toError('Hello'); // { code: 'error', message: 'Hello' }
toInfo('World'); // { code: 'info', message: 'World' }
const href = 'https://example.com/?user=John&some_key=1&id=3';
const url = new URL(href);
const availableKeys = ['user', 'id'];
for (const key of [...url.searchParams.keys()]) {
if (!availableKeys.includes(key)) {
url.searchParams.delete(key);
}
}
console.log(url.toString()); // 'https://example.com/?user=John&id=3'
utm_delete
, тогда так:params.delete('utm_delete');
utm
: тогда из примера код. Можете и в enum
запихать:const utm = [utmType.UtmSource, utmType.UtmMedium];
for (const key of utm) {
params.delete(key);
}
// или
params.delete(utmType.UtmSource);
id
не очень хорошее.