How to use the valid-url.isWebUri function in valid-url

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 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 MyCryptoHQ / MoneroVision / src / components / modals / add-node / index.tsx View on Github external
public validateURL = () => {
    const { nodes } = this.props;
    const { url } = this.state;
    if (url.length > 0) {
      if (!!nodes.filter(n => n.url === url).length) {
        this.setInputError('url', 'A node with that url already exists');
      } else {
        if (ValidUrl.isWebUri(url)) {
          this.setState({ pending: true });
          fetchAsync(`${url}/api/mempool?limit=${1}&page=${0}`)
            .then(() => {
              this.setState({ pending: false });
              this.setInputError('url', '');
            })
            .catch(error => {
              console.log(error);
              this.setState({ pending: false });
              this.setInputError(
                'url',
                'Unable to connect to node. Make sure the node is configured properly.'
              );
            });
        } else {
          this.setInputError('url', 'A valid url is required');
github broidHQ / integrations / broid-utils / src / index.ts View on Github external
function isUrl(url) {
  return validUrl.isWebUri(url);
}
github qdm12 / htmlspitter / src / server.ts View on Github external
static verifyURL(url: string | undefined): string {
        if (url === undefined || url === "") {
            throw new Error("url parameter not provided")
        } else if (validUrl.isWebUri(url) === undefined) {
            throw new Error("url parameter is not a valid URL")
        }
        return url;
    }
    close(callback?: () => void) {
github prestonvanloon / swagger-aggregator / lib / getSwagger.js View on Github external
function getSwagger(url) {
  if (validUrl.isWebUri(url)) {
    return request.get(url)
      .then(function (res) {
        return yaml.safeLoad(res);
      });
  } else {
    return new Promise(function (resolve, reject) {
      try {
        const doc = fs.readFileSync(url);
        resolve(yaml.safeLoad(doc));
      } catch (e) {
        reject(e);
      }
    });
  }

}
github matheuslc / shorts / src / url / shortUrlController.js View on Github external
createShortUrl(req, res) {
    if (!req.body.url) {
      throw new Error('URL is not defined. You must pass a URL. A valid URL should start with http(s) and ends with a .');
    }

    if (!validUrl.isWebUri(req.body.url)) {
      throw new Error('Please send a valid URL');
    }

    const ShortUrl = this.ShortUrlService.createShortUrl(req.body.url);

    this.ShortUrlRepository.persist(ShortUrl).then(response => {
      res.status(201);

      return res.json(this.ShortUrlRepository.dataTransferObject(response));
    }).catch(err => {
      if (err.code === 11000) {
        this.createShortUrl(req, res);

        return false;
      }
github brave / ethereum-remote-client / old-ui / app / config.js View on Github external
function rpcValidation (newRpc, state) {
  if (validUrl.isWebUri(newRpc)) {
    state.dispatch(actions.setRpcTarget(newRpc))
  } else {
    var appendedRpc = `http://${newRpc}`
    if (validUrl.isWebUri(appendedRpc)) {
      state.dispatch(actions.displayWarning('URIs require the appropriate HTTP/HTTPS prefix.'))
    } else {
      state.dispatch(actions.displayWarning('Invalid RPC URI'))
    }
  }
}
github zrrrzzt / html-validator / index.js View on Github external
module.exports = async options => {
  if (!options) {
    throw new Error('Missing required input: options object')
  }

  if (!options.url && !options.data) {
    throw new Error('Missing required params: url or data')
  }

  if (options.url && !validUrl.isWebUri(options.url)) {
    throw new Error('Invalid url')
  }

  return validate(options)
}
github MetaMask / metamask-mobile / app / components / Views / Settings / NetworksSettings / NetworkSettings / index.js View on Github external
validateRpcUrl = () => {
		const { rpcUrl } = this.state;
		if (!isWebUri(rpcUrl)) {
			const appendedRpc = `http://${rpcUrl}`;
			if (isWebUri(appendedRpc)) {
				this.setState({ warningRpcUrl: strings('app_settings.invalid_rpc_prefix') });
			} else {
				this.setState({ warningRpcUrl: strings('app_settings.invalid_rpc_url') });
			}
			return false;
		}
		const url = new URL(rpcUrl);
		const privateConnection = isprivateConnection(url.hostname);
		if (!privateConnection && url.protocol === 'http:') {
			this.setState({ warningRpcUrl: strings('app_settings.invalid_rpc_prefix') });
			return false;
		}
		this.setState({ validatedRpcURL: true, warningRpcUrl: undefined });
		return true;
	};

valid-url

URI validation functions

Unrecognized
Latest version published 11 years ago

Package Health Score

71 / 100
Full package analysis

Similar packages