index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*!
  2. * /**
  3. * * Copyright (c) Meta Platforms, Inc. and affiliates.
  4. * *
  5. * * This source code is licensed under the MIT license found in the
  6. * * LICENSE file in the root directory of this source tree.
  7. * * /
  8. */
  9. /******/ (() => { // webpackBootstrap
  10. /******/ "use strict";
  11. var __webpack_exports__ = {};
  12. // This entry needs to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
  13. (() => {
  14. var exports = __webpack_exports__;
  15. Object.defineProperty(exports, "__esModule", ({
  16. value: true
  17. }));
  18. exports.replacePathSepForRegex = exports.escapeStrForRegex = exports.escapePathForRegex = void 0;
  19. var _path = require("path");
  20. /**
  21. * Copyright (c) Meta Platforms, Inc. and affiliates.
  22. *
  23. * This source code is licensed under the MIT license found in the
  24. * LICENSE file in the root directory of this source tree.
  25. *
  26. */
  27. const escapePathForRegex = dir => {
  28. if (_path.sep === '\\') {
  29. // Replace "\" with "/" so it's not escaped by escapeStrForRegex.
  30. // replacePathSepForRegex will convert it back.
  31. dir = dir.replaceAll('\\', '/');
  32. }
  33. return replacePathSepForRegex(escapeStrForRegex(dir));
  34. };
  35. exports.escapePathForRegex = escapePathForRegex;
  36. const escapeStrForRegex = string => string.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&');
  37. exports.escapeStrForRegex = escapeStrForRegex;
  38. const replacePathSepForRegex = string => {
  39. if (_path.sep === '\\') {
  40. return string.replaceAll(/(\/|(.)?\\(?![$()*+.?[\\\]^{|}]))/g, (_match, _, p2) => p2 && p2 !== '\\' ? `${p2}\\\\` : '\\\\');
  41. }
  42. return string;
  43. };
  44. exports.replacePathSepForRegex = replacePathSepForRegex;
  45. })();
  46. module.exports = __webpack_exports__;
  47. /******/ })()
  48. ;