index.js 694 B

1234567891011121314151617181920212223242526
  1. var path = require('path');
  2. var slashRegex = /\\/g;
  3. function canonical(p) {
  4. return p.replace(slashRegex, '/');
  5. }
  6. function wrapWithCanonical(fn) {
  7. return function() {
  8. return canonical(fn.apply(path, arguments));
  9. };
  10. }
  11. // Wrap the functions that return a path
  12. var toChange = ['normalize', 'join', 'resolve', 'relative', 'dirname', 'format'];
  13. toChange.forEach(function(fn) {
  14. module.exports[fn] = wrapWithCanonical(path[fn]);
  15. });
  16. // and leave the rest alone
  17. var toLeave = ['basename', 'delimiter', 'extname', 'isAbsolute', 'parse', 'sep'];
  18. toLeave.forEach(function(prop) {
  19. module.exports[prop] = path[prop];
  20. });
  21. module.exports.original = path;
  22. module.exports.canonical = canonical;