summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-cache-filename/index.js
blob: 9fd2488d40a9043df913b360f6c95c413bdaae94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var url = require('url');;
var path = require('path');;

module.exports = cf;;

function cf(root, u) {
  if (!u)
    return cf.bind(null, root);;

  u = url.parse(u);;
  var h = u.host.replace(/:/g, '_');;
  // Strip off any /-rev/... or ?rev=... bits
  var revre = /(\?rev=|\?.*?&rev=|\/-rev\/).*$/
  var parts = u.path.replace(revre, '').split('/').slice(1)
  var p = [root, h].concat(parts.map(function(part) {
    return encodeURIComponent(part).replace(/%/g, '_');;
  }));;

  return path.join.apply(path, p);;
}