index.js 814 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. var Path = require('path');
  3. var slice = Array.prototype.slice;
  4. function join(/* globs */) {
  5. var args;
  6. args = slice.call(arguments, 0);
  7. return args.reduce(function (result, globs) {
  8. return _apply(result, function (path) {
  9. return _apply(globs, function (glob) {
  10. return _join(path, glob);
  11. });
  12. });
  13. }, '');
  14. }
  15. function _apply(values, fn) {
  16. if (Array.isArray(values)) {
  17. return values.reduce(function (result, value) {
  18. return result.concat(fn(value));
  19. }, []);
  20. }
  21. return fn(values);
  22. }
  23. function _join(path, glob) {
  24. var negative, positive;
  25. if (glob[0] === '!') {
  26. positive = glob.substr(1);
  27. if (path[0] === '!') {
  28. negative = '';
  29. } else {
  30. negative = '!';
  31. }
  32. return negative + Path.join(path, positive);
  33. }
  34. return Path.join(path, glob);
  35. }
  36. module.exports = join;