How to use valid-url - 10 common examples

To help you get started, we’ve selected a few valid-url 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 fffunction / backstop-crawl / index.js View on Github external
alias: {
            o: 'outfile',
        },
    }
);

if (cli.flags.limitSimilar) {
    if (!Number.isInteger(cli.flags.limitSimilar)) {
        // Set default if true
        cli.flags.limitSimilar = 3;
    }
}

if (cli.flags.referenceUrl) {

    if (!validurl(cli.flags.referenceUrl)) {
        console.error(
            `> Error: "${cli.flags.referenceUrl}" isn't a valid reference URL`
        );
        process.exit(1);
    }
}

if (cli.input.length > 0) {
    if (validurl(cli.input[0])) {
        crawl(cli.input[0], cli.flags);
    } else {
        console.error(`> Error: "${cli.input[0]}" isn't a valid URL`);
        process.exit(1);
    }
} else {
    cli.showHelp();
github glennjones / text-autolinker / lib / autolinker.js View on Github external
words = [text];
		if (text.indexOf(' ') > -1) {
			words = text.split(' ');
		}

		// add html links
		i = words.length;
		while (x < i) {
			var cn = options.className,
				word = utils.trim(words[x]);

			// the . is not need for valid url, but is inforced here
			if (word.indexOf('http:') === 0 || word.indexOf('https:') === 0 && word.indexOf('.') > 0) {

				// check url is valid 
				if (validUrl.isUri(word)) {
					if (!out.url) {
						out.url = [];
					}
					expanded = getExpandedUrl(word, options);
					var address = word;
					if (expanded) {
						address = expanded;
						out.url.push({
							match: word,
							expanded: expanded
						});
					} else {
						out.url.push({
							match: word
						});
					}
github IBM / ipfs-social-proof / src / remote-proofs.js View on Github external
formatRedditUrl (url) {
    if (!validUrl.isUri(url)) {
      throw new Error('Valid url is required')
    }

    let parsed = parse(url)
    if (!parsed.hostname === 'www.reddit.com') {
      throw new Error('Url has to use www.reddit.com as host')
    }

    if (url.endsWith('.json')) {
      return url
    } else if (url.endsWith('/')) {
      let urlArr = url.split('/')
      urlArr.pop() // removes the enpty
      return `${urlArr.join('/')}.json`
    } else {
      throw new Error('Url is not correct format for a Reddit proof')
github wxajs / wxa / packages / wxa-cli / src / helpers / pathParser.js View on Github external
isPlugin: false,
            isWXALib: false,
            isDynamic: false,
            isBase64: false,
        };

        // judge path's kind;
        if (x[0] === '.') { // require('./') require('../')
            ret.isRelative = true;
        } else if (x[0] === '#') { // require('#') require plugin plugin require('plugin name')
            ret.isPlugin = true;
        } else if (this.pkgReg.test(x)) { // require('@scope/pkg') require('pkg')
            ret.isNodeModule = true;
        } else if (x[0] === '/') { // require('/abcd')
            ret.isAPPAbsolute = true;
        } else if (validUrl.is_uri(x)) { // components from plugin or uri
            if (x.indexOf('plugin://') === 0) ret.isPlugin = true;
            else if (x.indexOf('wxa://') === 0) (ret.isWXALib = true, ret.name = x.slice(6));
            else ret.isURI = true;
        } else if (this.base64Reg.test(x)) {
            ret.isURI = true;
            ret.isBase64 = true;
        } else if (this.dynamicReg.test(x)) {
            ret.isURI = true;
            ret.isDynamic = true;
        } else {
            throw new Error('Path Error', '无法解析的路径类型: '+x);
        }

        return ret;
    }
}
github fosslife / delta / core / urls / urlShortner.js View on Github external
const urlShortener = async (req, res) => {
    const URL = req.body.url;
    const API_KEY_HEADER = req.get('api-key');
    /* It's a workaround, it could be better */
    const [, , domain] = auth(API_KEY_HEADER);
    const responseStatus = isAuthorizedUser(API_KEY_HEADER);
    if (responseStatus === 200) {
        logger.info(`User is authorised`);
        const specialURL = req.body.custom;
        const customUrlExists = await db.hgetall(`short:${specialURL}`);
        if (Object.keys(customUrlExists).length) {
            return res.end(
                `URL with name ${specialURL} already exists. try different URL`
            );
        }
        const isURL = validURL.isWebUri(URL);
        if (isURL) {
            logger.info(`User has given valid URL`);
            // part of URL either custom or incremented-auto-url
            const customOrAuto = specialURL || (await db.spop('genurls'));
            await db.publish('removed', 'remove');
            const fullURL = specialURL
                ? `${domain}${customOrAuto}`
                : `${domain}${customOrAuto}`;
            logger.info(`Got shortUrl ${customOrAuto}. updating DB`);
            await db.hset(
                `short:${customOrAuto}`,
                'original',
                URL,
                'type',
                'url'
            );
github bcgov / devhub-app-web / app-web / plugins / gatsby-source-github-all / utils / plugins.js View on Github external
const markDownUnfurlImagePlugin = (extension, file) => {
  if (extension !== 'md' || !Object.prototype.hasOwnProperty.call(file.metadata, 'unfurl')) {
    return file;
  }

  const unfurl = file.metadata.unfurl;
  // if the image paramater is relative, it will be correctly mapped to an absolute path
  if (
    isString(unfurl.image) &&
    unfurl.image.trim().length > 0 &&
    !validUrl.isWebUri(unfurl.image)
  ) {
    if (path.isAbsolute(unfurl.image)) {
      // if the path is absolute we need to map the path based of the sourcePath to the repo
      // this plus the absolute path cannot just be joined as the github api follows a convention
      // for reaching a file
      const urlObject = new url.URL(file.url);
      const branch = urlObject.searchParams.get('ref');
      const path = `${file.metadata.owner}/${file.metadata.source}/blob/${branch}${unfurl.image}`;
      const absPath = url.resolve('https://github.com', path);

      const absPathObj = new url.URL(absPath);
      absPathObj.searchParams.set('raw', true);
      unfurl.image = absPathObj.toString();
    } else {
      // if path is relative
      const absPath = url.resolve(file.html_url, unfurl.image);
github lehoangduc / face-recognition-api / api / plugins / finder.js View on Github external
validateRequest(request) {
    let imageUrl = request.query.url;

    imageUrl = imageUrl ? imageUrl.trim() : '';

    // Require url
    if (!imageUrl) {
      return new Error(this.errors.url_missing);
    }

    // Check valid url
    if (!validUrl.isHttpUri(imageUrl) && !validUrl.isHttpsUri(imageUrl)) {
      return new Error(this.errors.url_invalid);
    }

    // Get extension
    let extension = this.getUrlExtension(imageUrl);

    if (this.validExtensions.indexOf(extension) === -1) {
      return new Error(this.errors.url_image_invalid);
    }

    return true;
  }
github AzureAD / passport-azure-ad / lib / validator.js View on Github external
validate: (value) => {
    return UrlValidator.isHttpUri(value) || UrlValidator.isHttpsUri(value);
  },
  error: 'The URL must be valid and be https:// or http://',
github pwa-builder / pwabuilder-lib / lib / manifestTools / manifestCreator / scrapers / start_url.js View on Github external
var start_url = function(opts, callback) {

  var $ = cheerio.load(opts.html);
  var url = opts.url;

  var startUrl = $('link[rel=start]').attr('href');

  if (!startUrl) {
    startUrl = $('[name=msapplication-starturl]').attr('content');
  }

  if (!startUrl) {
    if (url && !isUrl(url)) {
      // if the url exists and is not a valid wbe url (e.g. /foo), then
      // its probably the start_url we want to use
      startUrl = url;
    }
    else if (isUrl(url)) {
      // if we have a valid url, then its more likely that we were given the homepage
      // for the app. So the path is the most likely canidate for the start_url
      startUrl = _url.parse(url).path;
    }
    else {
      // I can't think of a better default
      startUrl = '/';
    }
  }

  if (callback) {
github patrickkettner / manifestation / lib / scrapers / start_url.js View on Github external
const start_url = (opts, callback) => {

  const $ = Cheerio.load(opts.html);
  const url = opts.url;

  let startUrl = $('link[rel=start]').attr('href');

  if (!startUrl) {
    startUrl = $('[name=msapplication-starturl]').attr('content');
  }

  if (!startUrl) {
    if (url && !IsURL(url)) {
      // if the url exists and is not a valid wbe url (e.g. /foo), then
      // its probably the start_url we want to use
      startUrl = url;
    }
    else if (IsURL(url)) {
      // if we have a valid url, then its more likely that we were given the homepage
      // for the app. So the path is the most likely canidate for the start_url
      startUrl = Url.parse(url).path;
    }
    else {
      // I can't think of a better default
      startUrl = '/';
    }
  }

  if (callback) {

valid-url

URI validation functions

Unrecognized
Latest version published 11 years ago

Package Health Score

71 / 100
Full package analysis

Similar packages