webhook/node_modules/contains-path/index.js
Joel Male 1ada95e04a
v2.0.0 (#12)
- Convert project to Javascript/Typescript
- Allow custom headers to be passed in (optional)
- Allow body to be optional
2020-08-26 10:52:47 +10:00

33 lines
658 B
JavaScript

'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;