UNPKG

typed-catch-of-the-day

Version:

typescript version of wes bos' catch of the day app

48 lines (34 loc) 1.14 kB
'use strict'; exports.__esModule = true; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _warning = require('warning'); var _warning2 = _interopRequireDefault(_warning); function extractPath(string) { var match = string.match(/https?:\/\/[^\/]*/); if (match == null) return string; _warning2['default'](false, 'A path must be pathname + search + hash only, not a fully qualified URL like "%s"', string); return string.substring(match[0].length); } function parsePath(path) { var pathname = extractPath(path); var search = ''; var hash = ''; 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 }; } exports['default'] = parsePath; module.exports = exports['default'];