Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « contains-path « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 24285f6d1cbe67840a116be870b7730b13088a47 (plain)
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;