1var url = require('url');; 2var path = require('path');; 3 4module.exports = cf;; 5 6function cf(root, u) { 7 if (!u) 8 return cf.bind(null, root);; 9 10 u = url.parse(u);; 11 var h = u.host.replace(/:/g, '_');; 12 // Strip off any /-rev/... or ?rev=... bits 13 var revre = /(\?rev=|\?.*?&rev=|\/-rev\/).*$/;; 14 var parts = u.path.replace(revre, '').split('/').slice(1);; 15 // Make sure different git references get different folders 16 if (u.hash && u.hash.length > 1) { 17 parts.push(u.hash.slice(1));; 18 };; 19 var p = [root, h].concat(parts.map(function(part) { 20 return encodeURIComponent(part).replace(/%/g, '_');; 21 }));; 22 23 return path.join.apply(path, p);; 24} 25