How to use the valid-url.is_uri 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 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 auth0 / node-saml / lib / saml20.js View on Github external
function getNameFormat(name){
  if (is_uri(name)){
    return 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri';
  }

  //  Check that the name is a valid xs:Name -> https://www.w3.org/TR/xmlschema-2/#Name
  //  xmlNameValidate.name takes a string and will return an object of the form { success, error }, 
  //  where success is a boolean 
  //  if it is false, then error is a string containing some hint as to where the match went wrong.
  if (xmlNameValidator.name(name).success){
    return 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic';
  }

  // Default value
  return 'urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified';
}
github kalamuna / kalastatic / bin / kalastatic-pa11y.js View on Github external
// Retrieve the current working directory.
var cwd = process.cwd()

// Begin the index template, sharing the CSS style from the pa11y report.
var output = ''
output += '<style> html, body { margin: 0; padding: 0; background-color: #fff; font-family: Arial, Helvetica, sans-serif; font-size: 16px; line-height: 22px; color: #333; } li { margin-bottom: 15px; } h1, h2, p, pre, ul { margin-top: 0; margin-bottom: 0; } h1 { margin-bottom: 10px; font-size: 24px; line-height: 24px; } h2 { font-size: 16px; } pre { white-space: pre-wrap; overflow: auto; } .page { max-width: 800px; margin: 0 auto; padding: 25px; } .counts { margin-top: 30px; font-size: 20px; } .count { display: inline-block; padding: 5px; border-radius: 5px; border: 1px solid #eee; } .clean-list { margin-left: 0; padding-left: 0; list-style: none; } .results-list { margin-top: 30px; } .result { padding: 10px; border-radius: 5px; border: 1px solid #eee; } .error { background-color: #fdd; border-color: #ff9696; } .warning { background-color: #ffd; border-color: #e7c12b; } .notice { background-color: #eef4ff; border-color: #b6d0ff; } </style>'
output += '<div class="page"><h1>Accessibility Reports</h1><ul>'

// Run the accessibility report for each page.
for (var i in pages) {
  // Construct the executable to run pa11y.
  var args = ['pa11y']
  args.push('-c', './pa11y.json')
  args.push('-r', 'html')
  args.push('-l', 'none')
  if (validUrl(pages[i])) {
    args.push(pages[i])
  }
  else {
    args.push('file://' + cwd + '/build/' + pages[i])
  }
  var cmd = shellEscape(args) + ' &gt; build/a11y/' + i + '.html'

  // Run the command.
  childProcess.execSync(cmd)

  // Add the report to the index.
  output += '<li><a href="' + i + '.html">' + pages[i] + '</a></li>'
}

// Finish and save the template.
output += '</ul></div>'
github PeerJ / slamscan / src / slamscan.js View on Github external
downloadUrlToFile: function(downloadUrl, file, callback) {
    /*jscs:disable*/
    if (!validUrl.is_uri(downloadUrl)) {
      /*jscs:enable*/
      return callback(util.format('Error: Invalid uri %s', downloadUrl));
    }

    var urlPath = url.parse(downloadUrl);
    console.info('Downloading %s -> %s', urlPath.pathname, file);
    var fileStream = fs.createWriteStream(file);

    function closeStream() {
      console.log('Finished downloading %s (stream closed)', file);
      callback(null, file);
    }

    fileStream.on('finish', closeStream);

    request.get(downloadUrl).on('error', function(err) {
github PeerJ / slamscan / src / util / downloadFileFromUrl.js View on Github external
module.exports = function(downloadUrl, file, callback) {
  /*jscs:disable*/
  if (!validUrl.is_uri(downloadUrl)) {
    /*jscs:enable*/
    return callback(new Error(util.format('Error: Invalid uri %s', downloadUrl)));
  }

  console.log('Downloading %s to %s', downloadUrl, file);

  var parsedUrl = url.parse(downloadUrl);

  switch (parsedUrl.protocol) {
    case 's3:': {
      return downloadFileFromBucket(
        parsedUrl.hostname,
        parsedUrl.pathname.slice(1),
        file,
        callback
      );
github vincentriemer / react-native-dom / packages / rnpm-plugin-dom / src / dom.js View on Github external
const REACT_NATIVE_DOM_GENERATE_PATH = function() {
  return path.resolve(
    process.cwd(),
    "node_modules",
    "react-native-dom",
    "local-cli",
    "generate-dom.js"
  );
};

let npmConfReg = execSync("npm config get registry")
  .toString()
  .trim();

let NPM_REGISTRY_URL = validUrl.is_uri(npmConfReg)
  ? npmConfReg
  : "http://registry.npmjs.org";

const npm = new Registry({ registry: NPM_REGISTRY_URL });

function getLatestVersion() {
  return new Promise(function(resolve, reject) {
    npm.packages.release("react-native-dom", "latest", (err, releases) => {
      if (err) {
        reject(err);
      } else if (!releases || releases.length === 0) {
        reject(new Error("Could not find react-native-dom@latest."));
      } else {
        resolve(releases[0].version);
      }
    });
github microsoft / react-native-windows / local-cli / rnpm / windows / src / common.js View on Github external
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
'use strict';

const fs = require('fs');
const path = require('path');
const semver = require('semver');
const Registry = require('npm-registry');
const child_process = require('child_process');
const validUrl = require('valid-url');

let npmConfReg = child_process.execSync('npm config get registry').toString().trim();
let NPM_REGISTRY_URL = validUrl.is_uri(npmConfReg) ? npmConfReg : 'http://registry.npmjs.org';

const REACT_NATIVE_PACKAGE_JSON_PATH = function() {
  return path.resolve(
    process.cwd(),
    'node_modules',
    'react-native',
    'package.json'
  );
};

const npm = new Registry({registry: NPM_REGISTRY_URL});

function getLatestVersion() {
  return new Promise(function (resolve, reject) {
    npm.packages.release('react-native-windows', 'latest', (err, releases) => {
      if (err) {
github microsoft / react-native-windows / current / local-cli / rnpm / windows / src / common.js View on Github external
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
'use strict';

const fs = require('fs');
const path = require('path');
const semver = require('semver');
const Registry = require('npm-registry');
const child_process = require('child_process');
const validUrl = require('valid-url');

let npmConfReg = child_process.execSync('npm config get registry').toString().trim();
let NPM_REGISTRY_URL = validUrl.is_uri(npmConfReg) ? npmConfReg : 'http://registry.npmjs.org';

const REACT_NATIVE_PACKAGE_JSON_PATH = function() {
  return path.resolve(
    process.cwd(),
    'node_modules',
    'react-native',
    'package.json'
  );
};

const npm = new Registry({registry: NPM_REGISTRY_URL});

function getLatestVersion() {
  return new Promise(function (resolve, reject) {
    npm.packages.release('react-native-windows', 'latest', (err, releases) => {
      if (err) {

valid-url

URI validation functions

Unrecognized
Latest version published 11 years ago

Package Health Score

71 / 100
Full package analysis

Similar packages