electron-react-boilerplate
Version:
Electron application boilerplate based on React, React Router, Webpack, React Hot Loader for rapid application development
41 lines (31 loc) • 985 B
JavaScript
export { extractPath };
export { parsePath };
import warning from 'warning';
function extractPath(string) {
var match = string.match(/^https?:\/\/[^\/]*/);
if (match == null) return string;
return string.substring(match[0].length);
}
function parsePath(path) {
var pathname = extractPath(path);
var search = '';
var hash = '';
process.env.NODE_ENV !== 'production' ? warning(path === pathname, 'A path must be pathname + search + hash only, not a fully qualified URL like "%s"', path) : undefined;
var hashIndex = pathname.indexOf('#');
if (hashIndex !== -1) {
hash = pathname.substring(hashIndex);
pathname = pathname.substring(0, hashIndex);
}
var searchIndex = pathname.indexOf('?');
if (searchIndex !== -1) {
search = pathname.substring(searchIndex);
pathname = pathname.substring(0, searchIndex);
}
if (pathname === '') pathname = '/';
return {
pathname: pathname,
search: search,
hash: hash
};
}
;