Blame view

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