/*
uri of folder structure

proxyName is the name in the array
762302
function findProxyObject(uri, proxyName, callback) {
    var proxyObject = {},
        folderUri = path.join(uri, proxyName)

    iterateFiles(folderUri, function (fileName) {
        var relativePropertyName = path.relative(folderUri, fileName),
            relativeValue = path.relative(uri, fileName)

        relativePropertyName = relativePropertyName.replace(isFile, "")
        var props = relativePropertyName.split("/")

        props.reduce(function (memo, value, index) {
            if (index === props.length - 1) {
                memo[value] = relativeValue
            } else {
                return (memo[value] = memo[value] || {})
            }
        }, proxyObject)

    }, function (err) {
        callback(err, proxyObject)
    })

    //fs.readdir(folderUri, mapIntoProxyObject)

    function mapIntoProxyObject(err, files) {
        if (err) {
            return callback(err)
        }
        files.filter(isFileFunction).forEach(addToProxyObject)
        callback(null, proxyObject)
    }

    function addToProxyObject(fileName) {
        var propertyName = fileName.replace(isFile, "")

        proxyObject[propertyName] = 
            path.join(proxyName, fileName)
    }
}
1239811
function mayProxy (pathname) {
    const maybePublicPath = path.resolve(appPublicFolder, pathname.slice(1))
    return !fs.existsSync(maybePublicPath)
  }
1070234
function urlAlias()
    {
        $useURLAlias =& $GLOBALS['eZContentObjectTreeNodeUseURLAlias'];
        $ini = eZINI::instance();
        $cleanURL = '';
        if ( !isset( $useURLAlias ) )
        {
            $useURLAlias = $ini->variable( 'URLTranslator', 'Translation' ) == 'enabled';
        }
        if ( $useURLAlias )
        {
            $path = $this->pathWithNames();
            if ( $ini->hasVariable( 'SiteAccessSettings', 'PathPrefix' ) &&
                 $ini->variable( 'SiteAccessSettings', 'PathPrefix' ) != '' )
            {
                $prepend = $ini->variable( 'SiteAccessSettings', 'PathPrefix' );
                $pathIdenStr = substr( $prepend, strlen( $prepend ) -1 ) == '/'
                                ? $path . '/'
                                : $path;
                if ( strncasecmp( $pathIdenStr, $prepend, strlen( $prepend ) ) == 0 )
                    $cleanURL = eZURLAliasML::cleanURL( substr( $path, strlen( $prepend ) ) );
                else
                    $cleanURL = eZURLAliasML::cleanURL( $path );
            }
            else
            {
                $cleanURL = eZURLAliasML::cleanURL( $path );
            }
        }
        else
        {
            $cleanURL = eZURLAliasML::cleanURL( 'content/view/full/' . $this->NodeID );
        }

        return $cleanURL;
    }
700347
function getRouteFiles (pathName) {
    var items = fs.readdirSync(pathName);
    var files = [];

    items.forEach(function(itemName) {
        var fullName = path.join(pathName, itemName);
        var fsStat = fs.statSync(fullName);

        // If directory, then scan for "routes.js"
        if (fsStat.isDirectory()) {
            getRouteFiles(fullName).forEach(function(a) {
                files.push(a);
            });
        } else if (fsStat.isFile() && itemName === 'routes.js') {
            // routes.js found, append to list
            files.push(fullName);
        }
    });

    return files;
}
1114667
function systemListing($mask, $directory, $key = 'name', $min_depth = 1) {
    $files = drupal_system_listing($mask, $directory, $key, $min_depth);

    // This one is actually only for Drupal 6.
    // The file object is:
    //    D6         D7         what it actually is
    //  - filename | uri      | full path and name
    //  - basename | filename | name with the extension
    //  - name     | name     | name without the extension
    // So we copy filename to uri, and then the caller can handle the returned
    // array as if it were Drupal 7 style.
    foreach ($files as $file) {
      $file->uri = $file->filename;
    }

    return $files;
  }
1253199
function _mapOutDNs(&$root, $path, $asn1)
    {
        $dns = &$this->_subArray($root, $path);

        if (is_array($dns)) {
            $size = count($dns);
            for ($i = 0; $i < $size; $i++) {
                for ($j = 0; $j < count($dns[$i]); $j++) {
                    $type = $dns[$i][$j]['type'];
                    $value = &$dns[$i][$j]['value'];
                    if (is_object($value) && strtolower(get_class($value)) == 'file_asn1_element') {
                        continue;
                    }

                    $map = $this->_getMapping($type);
                    if (!is_bool($map)) {
                        $value = new File_ASN1_Element($asn1->encodeDER($value, $map));
                    }
                }
            }
        }
    }
640883
function urlToUri(url) {
  let parts;

  if (!isUrl(url)) {
    throw new Error('Invalid url ' + url);
  }
  parts = urlParse.parse(url);

  return `${parts.hostname}${decodeURIComponent(parts.path)}`;
}
1007136
function getProxyMiddleware(context, uri) {
  const pathRewrite = {};
  pathRewrite[`^${context}`] = url.parse(uri).pathname;

  return proxy({
    target: getHost(uri),
    changeOrigin: true,
    logLevel: 'warn',
    pathRewrite: pathRewrite,
  });
}
1075803
function pathParser(root, extname, subPath, paths) {
  var dirPath = path.resolve(subPath || root);
  var files;
  paths = paths || {};

  try {
    files = fs.readdirSync(dirPath);
  } catch(e) {
    files = [];
  }
  files.forEach(function(file) {
    file = path.join(dirPath, '/', file);
    if (fs.statSync(file).isFile()) {
      if (~extname.split('|').indexOf(path.extname(file).substr(1))) {
        var rootPath = '^' + path.join(path.resolve(root), '/');
        rootPath = rootPath.replace(/\\/g, '\\\\') + '(.*)\.(' + extname + ')$';
        paths[file.match(new RegExp(rootPath))[1].toLowerCase()] = file;
      }
    } else if (fs.statSync(file).isDirectory()) {
      pathParser(root, extname, file, paths);
    }
  });
  return paths;
}
258560
function ls(uri, callback) {
  if (!uri) {
    callback(new Error('uri is required'))
  }
  util.getAll(uri, function(err, val) {
    var res = {}
    for (var i=0; i<val.length; i++) {
      if (val[i].predicate.uri === 'http://www.w3.org/ns/ldp#contains') {
        if (! res[val[i].object.uri]) res[val[i].object.uri] = {}
        res[val[i].object.uri].contains = val[i].object.uri
      }
      if (val[i].predicate.uri === 'http://www.w3.org/ns/posix/stat#mtime') {
        if (! res[val[i].subject.uri]) res[val[i].subject.uri] = {}
        res[val[i].subject.uri].mtime = val[i].object.value
      }

    }

    var arr =[]
    for( var k in res ) {
      if (res.hasOwnProperty(k)) {
        if (k && res[k] && res[k].mtime && res[k].contains) {
          arr.push({ file : res[k].contains, mtime : res[k].mtime })
        }
      }
    }

    arr = arr.sort(function(a, b){
      if (a.mtime < b.mtime) return -1
      if (a.mtime > b.mtime) return 1
      return 0
    })

    var ret = []
    for (i=0; i<arr.length; i++) {
      ret.push(arr[i].file)
    }

    callback(null, ret)
  })
}
579096
function() {
      var base = _.result(this, 'urlRoot') || _.result(this.collection, 'url') || urlError();
      if (this.isNew()) return base;
      return base + (base.charAt(base.length - 1) === '/' ? '' : '/') + encodeURIComponent(this.id);
    }
1240940
function buildHttpURL(uri) {
    var port     = weinre_port
    var pathname = weinre_pathname

    if (pathname == "/index.html") pathname = "/"

    if (weinre_protocol == "file:") {
        return uri
    }

    else if (weinre_protocol == "http:") {
        if (port != "") port = ":" + port

        return weinre_protocol + "//" + weinre_host + port + pathname + uri
    }

    else if (weinre_protocol == "https:") {
        if (port != "") port = ":" + port

        return weinre_protocol + "//" + weinre_host + port + pathname + uri
    }
}
1178972
function(/**Array*/ path) {
		if (path.constructor != Array) path = path.split(/[\\\/]/);
		var make = "";
		for (var i = 0, l = path.length; i < l; i++) {
			make += path[i] + SYS.slash;
			if (! IO.exists(make)) {
				IO.makeDir(make);
			}
		}
	}
1055824
function onDirectory() {
      var this_SendStream = this;
      if (!/\/$/.test(reqUrl.pathname)) {
        // No trailing slash? Redirect to add one
        res.writeHead(301, {
          'Location': reqUrl.pathname + '/' + (reqUrl.search || '')
        });
        res.end();
        deferred.resolve(true);
        return;
      }

      var indexPath = path.normalize(path.join(
        self.$root, unescape(this.path), 'index.html'));

      fs.exists(indexPath, function(exists) {
        if (exists) {
          // index.html exists, just serve that. This is the same as
          // the below call except without onDirectory and without
          // .index(false)
          send(req, suffix, {root: self.$root})
            .on('error', onError)
            .on('stream', onStream)
            .pipe(res);
          deferred.resolve(true);
        } else {
          // Either serve up 404, or the directory auto-index
          if (!self.$dirIndex) {
            deferred.resolve(null);
          } else {
            deferred.resolve(
              self.$autoindex_p(req, res, this_SendStream.path, self.$blacklist)
            );
          }
        }
      });
    }
253607
function (baseURL, params) {

            var encodedArgs = [];

            if (params){

                var key, urlarg;
                var urlize = encodeURIComponent;

                for (key in params){
                    if (params.hasOwnProperty(key)) {
                        urlarg = urlize(key)+'='+urlize(params[key]);
                        encodedArgs.push(urlarg);
                    }
                }
            }

            if (encodedArgs.length > 0){

                if (baseURL.indexOf('?') == -1)
                    return baseURL + '?' + encodedArgs.join('&');
                return baseURL + '&' + encodedArgs.join('&');
            }
            return baseURL;
        }
1241040
function _mapInDNs(&$root, $path, $asn1)
    {
        $dns = &$this->_subArray($root, $path);

        if (is_array($dns)) {
            for ($i = 0; $i < count($dns); $i++) {
                for ($j = 0; $j < count($dns[$i]); $j++) {
                    $type = $dns[$i][$j]['type'];
                    $value = &$dns[$i][$j]['value'];
                    if (is_object($value) && $value instanceof Element) {
                        $map = $this->_getMapping($type);
                        if (!is_bool($map)) {
                            $decoded = $asn1->decodeBER($value);
                            $value = $asn1->asn1map($decoded[0], $map);
                        }
                    }
                }
            }
        }
    }
614059
String getClassnameFromProxyname(String proxyname) {
		Pattern pattern = Pattern.compile("[@$]");
		Matcher matcher = pattern.matcher(proxyname);
		matcher.find();
		matcher.start();
		return proxyname.substring(0, matcher.start());
	}