web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
658 B

  1. 'use strict';
  2. var path = require('path');
  3. function containsPath(fp, segment) {
  4. if (typeof fp !== 'string' || typeof segment !== 'string') {
  5. throw new TypeError('contains-path expects file paths to be a string.');
  6. }
  7. var prefix = '(^|\\/)';
  8. if (segment.indexOf('./') === 0 || segment.charAt(0) === '/') {
  9. prefix = '^';
  10. }
  11. var re = new RegExp(prefix + normalize(segment).join('\\/') + '($|\\/)');
  12. fp = normalize(fp).join('/');
  13. return re.test(fp);
  14. }
  15. /**
  16. * Normalize slashes
  17. */
  18. function normalize(str) {
  19. str = path.normalize(str);
  20. return str.split(/[\\\/]+/);
  21. }
  22. /**
  23. * Expose `containsPath`
  24. */
  25. module.exports = containsPath;