How to use the url-parse function in url-parse

To help you get started, we’ve selected a few url-parse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github decred / dcrdata / cmd / dcrdata / public / js / helpers / turbolinks_helper.js View on Github external
constructor (turbolinks) {
    const tq = this
    tq.replaceTimer = 0
    tq.appendTimer = 0
    tq.turbolinks = turbolinks || Turbolinks || false
    if (!tq.turbolinks || !tq.turbolinks.supported) {
      console.error('No passed or global Turbolinks instance detected. TurboQuery requires Turbolinks.')
      return
    }
    // These are timer callbacks. Bind them to the TurboQuery instance.
    tq.replaceHistory = tq._replaceHistory.bind(tq)
    tq.appendHistory = tq._appendHistory.bind(tq)
    tq.url = Url(window.location.href, true)
  }
github expo / expo / packages / expo-asset / build / AssetSources.js View on Github external
if (assetUrlOverride) {
        const uri = path.join(assetUrlOverride, hash);
        return { uri: resolveUri(uri), hash };
    }
    const fileScale = scale === 1 ? '' : `@${scale}x`;
    const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';
    const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}?platform=${encodeURIComponent(Platform.OS)}&hash=${encodeURIComponent(meta.hash)}`;
    // For assets with a specified absolute URL, we use the existing origin instead of prepending the
    // development server or production CDN URL origin
    if (/^https?:\/\//.test(meta.httpServerLocation)) {
        const uri = meta.httpServerLocation + suffix;
        return { uri, hash };
    }
    // For assets during development, we use the development server's URL origin
    if (Constants.manifest && Constants.manifest.developer) {
        const baseUrl = new URL(Constants.manifest.bundleUrl);
        baseUrl.set('pathname', meta.httpServerLocation + suffix);
        return { uri: baseUrl.href, hash };
    }
    // Production CDN URIs are based on each asset file hash
    return {
        uri: `https://d1wp6m56sqw74a.cloudfront.net/~assets/${encodeURIComponent(hash)}`,
        hash,
    };
}
/**
github bilibili-helper / bilibili-helper / src / js / modules / ShowDisabledVideo / index.js View on Github external
chrome.webRequest.onBeforeSendHeaders.addListener(details => {
            const {tabId, initiator, requestHeaders} = details;
            const fromHelper = !_.isEmpty(_.find(requestHeaders, ({name, value}) => name === 'From' && value === 'bilibili-helper'));
            if (/^chrome-extension:\/\//.test(initiator) || fromHelper) {
                return;
            }
            const url = new Url(details.url, '', true);
            const {query} = url;
            if (query && query.requestFrom) return;
            const tabData = this.messageStore.createData(tabId);
            fetchFromHelper(url.href)
            .then(res => res.json())
            .then((res) => {
                tabData.queue.push({
                    command: 'showDisabledVideoURLRequest',
                    data: res,
                });
                this.messageStore.dealWith(tabId); // 处理queue
            });

        }, requestFilter, ['requestHeaders']);
    };
github GetStream / react-activity-feed / src / utils.js View on Github external
export function sanitizeURL(url: ?string): ?string {
  if (url == null) {
    return url;
  }

  const proto = URL(url).protocol;
  // allow http, https, ftp
  // IMPORTANT: Don't allow data: protocol because of:
  // <a>here</a>
  if (proto === 'https:' || proto === 'http:' || proto === 'ftp:') {
    return url;
  }
  return undefined;
}
github matvp91 / indigo-player / src / extensions / ThumbnailsExtension / ThumbnailsExtension.ts View on Github external
.map(item => {
        const url = parse(item.part);
        const parts = parse(url.hash.replace('#', '?'), true);
        const [x, y, width, height] = parts.query.xywh.split(',').map(Number);

        url.set('hash', null);
        const src = url.toString();

        return {
          start: Math.trunc(item.start / 1000),
          src,
          x,
          y,
          width,
          height,
        };
      })
      .sort((a, b) => b.start - a.start);
github thoov / mock-socket / src / helpers / url-verification.js View on Github external
export default function urlVerification(url) {
  const urlRecord = new URL(url);
  const { pathname, protocol, hash } = urlRecord;

  if (!url) {
    throw new TypeError(`${ERROR_PREFIX.CONSTRUCTOR_ERROR} 1 argument required, but only 0 present.`);
  }

  if (!pathname) {
    urlRecord.pathname = '/';
  }

  if (protocol === '') {
    throw new SyntaxError(`${ERROR_PREFIX.CONSTRUCTOR_ERROR} The URL '${urlRecord.toString()}' is invalid.`);
  }

  if (protocol !== 'ws:' && protocol !== 'wss:') {
    throw new SyntaxError(
github micky2be / superlogin-client / src / index.js View on Github external
function parseHostFromUrl(url) {
	const parsedURL = new URL(url);
	return parsedURL.host;
}
github expo / expo / packages / expo-asset / build / AssetSources.js View on Github external
export function resolveUri(uri) {
    if (!manifestBaseUrl) {
        return uri;
    }
    const { protocol } = new URL(uri);
    if (protocol !== '') {
        return uri;
    }
    const baseUrl = new URL(manifestBaseUrl);
    const resolvedPath = uri.startsWith('/') ? uri : path.join(baseUrl.pathname, uri);
    baseUrl.set('pathname', resolvedPath);
    return baseUrl.href;
}
//# sourceMappingURL=AssetSources.js.map

url-parse

Small footprint URL parser that works seamlessly across Node.js and browser environments

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis

Popular url-parse functions