react-native-webview.git

WebViewShared.js 690B

123456789101112131415161718192021222324252627
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow
  9. */
  10. 'use strict';
  11. const escapeStringRegexp = require('escape-string-regexp');
  12. const WebViewShared = {
  13. defaultOriginWhitelist: ['http://*', 'https://*'],
  14. extractOrigin: (url: string): string => {
  15. const result = /^[A-Za-z0-9]+:(\/\/)?[^/]*/.exec(url);
  16. return result === null ? '' : result[0];
  17. },
  18. originWhitelistToRegex: (originWhitelist: string): string => {
  19. return escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*');
  20. },
  21. };
  22. module.exports = WebViewShared;