polyfill-io-feature-detection
Advanced tools
Comparing version 1.1.13 to 1.1.14
47
index.js
@@ -15,3 +15,7 @@ 'use strict'; | ||
if (contains(fullFeature, "~")) { | ||
console.warn('Feature ' + fullFeature + ' can not be detected because it has not JavaScript API.'); | ||
if (contains(fullFeature, "Intl.~locale")) { | ||
supportedFeature = checkIntlLocale(window, fullFeature); | ||
} else { | ||
console.warn('Feature ' + fullFeature + ' can not be detected because it has not JavaScript API.'); | ||
} | ||
} else { | ||
@@ -33,8 +37,8 @@ // Get the feature and the container Object | ||
} | ||
// If the feature is not supported by the browser, then add it to polyfill it | ||
if (supportedFeature === false) { | ||
arrayUnsupportedFeatures.push(fullFeature); | ||
} | ||
} | ||
} | ||
// If the feature is not supported by the browser, then add it to polyfill it | ||
if (supportedFeature === false) { | ||
arrayUnsupportedFeatures.push(fullFeature); | ||
} | ||
} | ||
@@ -44,2 +48,35 @@ return arrayUnsupportedFeatures; | ||
function checkIntlLocale(obj, feature) { | ||
var localeArray = feature.split("Intl.~locale"); | ||
var locale = ""; | ||
if (localeArray.length === 2) { | ||
var tempLocale = localeArray[1]; | ||
if (tempLocale && tempLocale !== "") { | ||
locale = tempLocale.replace(".", ""); | ||
if (!("Intl" in obj && | ||
"Collator" in obj.Intl && | ||
"supportedLocalesOf" in obj.Intl.Collator && | ||
obj.Intl.Collator.supportedLocalesOf(locale).length === 1 && | ||
"DateTimeFormat" in obj.Intl && | ||
"supportedLocalesOf" in obj.Intl.DateTimeFormat && | ||
obj.Intl.DateTimeFormat.supportedLocalesOf(locale).length === 1 && | ||
"NumberFormat" in obj.Intl && | ||
"supportedLocalesOf" in obj.Intl.NumberFormat && | ||
obj.Intl.NumberFormat.supportedLocalesOf(locale).length === 1)) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} else { | ||
console.warn('Feature ' + feature + ' has wrong Intl.~locale.XX format. For example Intl.~locale.en-US'); | ||
} | ||
} else { | ||
console.warn('Feature ' + feature + ' has wrong Intl.~locale format. For example Intl.~locale.en-US'); | ||
} | ||
// if any error, returns false | ||
return false; | ||
} | ||
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes | ||
@@ -46,0 +83,0 @@ function contains(origin, search, start) { |
{ | ||
"name": "polyfill-io-feature-detection", | ||
"version": "1.1.13", | ||
"version": "1.1.14", | ||
"description": "Feature detection in the browser before loading polyfill using services like polyfill.io", | ||
@@ -9,3 +9,5 @@ "license": "MIT", | ||
"scripts": { | ||
"pretest": "npm install", | ||
"test": "mocha test/node/detectBrowserUnsupportedFeatures.test.js", | ||
"pretestLoaders": "npm install", | ||
"testLoader": "mocha test/node/polyfillLoader.test.js" | ||
@@ -12,0 +14,0 @@ }, |
@@ -141,3 +141,10 @@ /* | ||
it('should detect Intl.~locale.en-US as unsupported feature.', function () { | ||
// Available polyfills: https://github.com/Financial-Times/polyfill-service/blob/master/docs/assets/compat.json | ||
var features = "Intl.~locale.en-US"; | ||
expect(polyfillLoader.detectBrowserUnsupportedFeatures(features)).to.be.deep.eq(["Intl.~locale.en-US"]); | ||
}); | ||
}); |
@@ -66,2 +66,8 @@ // Testing Configuration Template | ||
window.Intl = function () { }; | ||
window.Intl.Collator = function () { }; | ||
window.Intl.DateTimeFormat = function () { }; | ||
window.Intl.NumberFormat = function () { }; | ||
window.Intl.Collator.supportedLocalesOf = function (a) { return [] }; | ||
window.Intl.DateTimeFormat.supportedLocalesOf = function (a) { return []; }; | ||
window.Intl.NumberFormat.supportedLocalesOf = function (a) { return []; }; | ||
window.JSON = function () { }; | ||
@@ -68,0 +74,0 @@ window.Map = function () { }; |
@@ -66,2 +66,9 @@ // Testing Configuration for IE 11 | ||
window.Intl = function () { }; | ||
window.Intl.Collator = function () { }; | ||
window.Intl.DateTimeFormat = function () { }; | ||
window.Intl.NumberFormat = function () { }; | ||
window.Intl.Collator.supportedLocalesOf = function (a) { return [] }; | ||
window.Intl.DateTimeFormat.supportedLocalesOf = function (a) { return []; }; | ||
window.Intl.NumberFormat.supportedLocalesOf = function (a) { return []; }; | ||
window.JSON = function () { }; | ||
@@ -68,0 +75,0 @@ //window.Map = function () { }; |
41474
744