react-native-webview.git

WebViewShared.js 662B

123456789101112131415161718192021222324252627
  1. /**
  2. * Copyright (c) 2018-present, Infinite Red, 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) => {
  15. const result = /^[A-Za-z0-9]+:(\/\/)?[^/]*/.exec(url);
  16. return result === null ? null : result[0];
  17. },
  18. originWhitelistToRegex: (originWhitelist) => {
  19. return escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*');
  20. },
  21. };
  22. export default WebViewShared;