is-forced.js 618 B

12345678910111213141516171819202122
  1. var fails = require('../internals/fails');
  2. var isCallable = require('../internals/is-callable');
  3. var replacement = /#|\.prototype\./;
  4. var isForced = function (feature, detection) {
  5. var value = data[normalize(feature)];
  6. return value == POLYFILL ? true
  7. : value == NATIVE ? false
  8. : isCallable(detection) ? fails(detection)
  9. : !!detection;
  10. };
  11. var normalize = isForced.normalize = function (string) {
  12. return String(string).replace(replacement, '.').toLowerCase();
  13. };
  14. var data = isForced.data = {};
  15. var NATIVE = isForced.NATIVE = 'N';
  16. var POLYFILL = isForced.POLYFILL = 'P';
  17. module.exports = isForced;