escape.js 998 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = escape;
  6. var _path = require('path');
  7. var _path2 = _interopRequireDefault(_path);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function escape(context, from) {
  10. if (from && _path2.default.isAbsolute(from)) {
  11. return from;
  12. } else {
  13. // Ensure context is escaped before globbing
  14. // Handles special characters in paths
  15. var absoluteContext = _path2.default.resolve(context).replace(/[\*|\?|\!|\(|\)|\[|\]|\{|\}]/g, function (substring) {
  16. return '[' + substring + ']';
  17. });
  18. if (!from) {
  19. return absoluteContext;
  20. }
  21. // Cannot use path.join/resolve as it "fixes" the path separators
  22. if (absoluteContext.endsWith('/')) {
  23. return '' + absoluteContext + from;
  24. } else {
  25. return absoluteContext + '/' + from;
  26. }
  27. }
  28. }