react-native-webview/js/WebViewShared.js

27 lines
674 B
JavaScript
Raw Normal View History

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
2018-07-30 20:21:48 -07:00
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const WebViewShared = {
defaultOriginWhitelist: ['http://*', 'https://*'],
2018-09-09 22:40:32 -06:00
extractOrigin: (url: string) => {
2018-07-30 20:21:48 -07:00
const result = /^[A-Za-z0-9]+:(\/\/)?[^/]*/.exec(url);
2018-09-09 22:40:32 -06:00
return result === null ? '' : result[0];
2018-07-30 20:21:48 -07:00
},
2018-09-09 22:40:32 -06:00
originWhitelistToRegex: (originWhitelist: string) => {
2018-07-30 20:21:48 -07:00
return escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*');
},
};
module.exports = WebViewShared;