Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function normalizeSamsungVersion(browser, version) {
try {
browserslist(`${browser} ${version}`);
// browserslist didn't throw, return the valid version
return version;
} catch (error) {
// we gave an invalid version to browserslist, so we try to
// find the nearest matching major version for samsung browser
const validVersions = [
...Object.keys(browserslist.versionAliases.samsung),
...browserslist.data.samsung.versions,
];
return validVersions.find(validVersion => validVersion[0] === version[0]);
}
}
test("isSupported test with browsers caniuse doesn't know", (t) => {
browserslist.data.notabrowser = {
name: 'notabrowser',
versions: ['1'],
released: ['1']
};
browserslist.versionAliases.notabrowser = {}
t.notOk(caniuse.isSupported("border-radius", "notabrowser 1"), "do not throw on non existing data")
delete browserslist.data.notabrowser
delete browserslist.versionAliases.notabrowser
t.end()
})
test("isSupported test with browsers caniuse doesn't know", (t) => {
browserslist.data.notabrowser = {
name: 'notabrowser',
versions: ['1'],
released: ['1']
};
browserslist.versionAliases.notabrowser = {}
t.notOk(caniuse.isSupported("border-radius", "notabrowser 1"), "do not throw on non existing data")
delete browserslist.data.notabrowser
delete browserslist.versionAliases.notabrowser
t.end()
})