How to use url-parse - 10 common examples

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 launchlet / launchlet / os-app / dev-launcher / recipes / TypeURL / main.js View on Github external
import * as _URLParser from 'url-parse';
const URLParser = typeof _URLParser === 'function' ? _URLParser : _URLParser.default;

export const LCHTypeURLCallback = function(inputData) {
	if (typeof inputData !== 'string') {
		// throw new Error('LCHErrorInputInvalid');
		return false
	}

	if (!(new URLParser(inputData)).hostname) {
		return false;
	}

	return true;
};

export const LCHTypeStringCanonicalExampleCallback = function() {
	return 'http://example.com';
github launchlet / launchlet / os-app / dev-launcher / recipes / primitives / URL / main.js View on Github external
import * as _URLParser from 'url-parse';
const URLParser = typeof _URLParser === 'function' ? _URLParser : _URLParser.default;

export const LCHPrimitiveURLCallback = function(inputData) {
	if (typeof inputData !== 'string') {
		// throw new Error('LCHErrorInputInvalid');
		return false;
	}

	if (!(new URLParser(inputData, {})).hostname) { // To parse an input independently of the browser's current URL (e.g. for functionality parity with the library in a Node environment), pass an empty location object as the second parameter
		return false;
	}

	return true;
};

export const LCHPrimitiveStringCanonicalExampleCallback = function() {
	return 'http://example.com';
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 decred / dcrdata / cmd / dcrdata / public / js / controllers / pagenavigation_controller.js View on Github external
setPageSize () {
    const url = Url(window.location.href)
    const q = Url.qs.parse(url.query)
    delete q.offset
    delete q.height
    q[this.pagesizeTarget.dataset.offsetkey] = this.pagesizeTarget.dataset.offset
    q.rows = this.pagesizeTarget.selectedOptions[0].value
    if (this.hasVotestatusTarget) {
      q.byvotestatus = this.votestatusTarget.selectedOptions[0].value
    }
    url.set('query', q)
    Turbolinks.visit(url.toString())
  }

url-parse

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

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis

Popular url-parse functions