makePath.js 486 B

123456789101112131415
  1. var join = require('../array/join');
  2. var slice = require('../array/slice');
  3. /**
  4. * Group arguments as path segments, if any of the args is `null` or an
  5. * empty string it will be ignored from resulting path.
  6. */
  7. function makePath(var_args){
  8. var result = join(slice(arguments), '/');
  9. // need to disconsider duplicate '/' after protocol (eg: 'http://')
  10. return result.replace(/([^:\/]|^)\/{2,}/g, '$1/');
  11. }
  12. module.exports = makePath;