index.js 703 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var path = require('path');
  3. var extend = require('extend-shallow');
  4. module.exports = function(glob, options) {
  5. var opts = extend({}, options);
  6. opts.cwd = opts.cwd ? path.resolve(opts.cwd) : process.cwd();
  7. // store first and last characters before glob is modified
  8. var prefix = glob.charAt(0);
  9. var suffix = glob.slice(-1);
  10. var isNegative = prefix === '!';
  11. if (isNegative) glob = glob.slice(1);
  12. if (opts.root && glob.charAt(0) === '/') {
  13. glob = path.join(path.resolve(opts.root), '.' + glob);
  14. } else {
  15. glob = path.resolve(opts.cwd, glob);
  16. }
  17. if (suffix === '/' && glob.slice(-1) !== '/') {
  18. glob += '/';
  19. }
  20. return isNegative ? '!' + glob : glob;
  21. };