3 var win32 = process && process.platform === 'win32';
4 var path = require('path');
5 var fileRe = require('filename-regex');
6 var utils = module.exports;
12 utils.diff = require('arr-diff');
13 utils.unique = require('array-unique');
14 utils.braces = require('braces');
15 utils.brackets = require('expand-brackets');
16 utils.extglob = require('extglob');
17 utils.isExtglob = require('is-extglob');
18 utils.isGlob = require('is-glob');
19 utils.typeOf = require('kind-of');
20 utils.normalize = require('normalize-path');
21 utils.omit = require('object.omit');
22 utils.parseGlob = require('parse-glob');
23 utils.cache = require('regex-cache');
26 * Get the filename of a filepath
28 * @param {String} `string`
32 utils.filename = function filename(fp) {
33 var seg = fp.match(fileRe());
38 * Returns a function that returns true if the given
39 * pattern is the same as a given `filepath`
41 * @param {String} `pattern`
45 utils.isPath = function isPath(pattern, opts) {
48 var unixified = utils.unixify(fp, opts);
50 return pattern.toLowerCase() === unixified.toLowerCase();
52 return pattern === unixified;
57 * Returns a function that returns true if the given
58 * pattern contains a `filepath`
60 * @param {String} `pattern`
64 utils.hasPath = function hasPath(pattern, opts) {
66 return utils.unixify(pattern, opts).indexOf(fp) !== -1;
71 * Returns a function that returns true if the given
72 * pattern matches or contains a `filepath`
74 * @param {String} `pattern`
78 utils.matchPath = function matchPath(pattern, opts) {
79 var fn = (opts && opts.contains)
80 ? utils.hasPath(pattern, opts)
81 : utils.isPath(pattern, opts);
86 * Returns a function that returns true if the given
87 * regex matches the `filename` of a file path.
89 * @param {RegExp} `re`
93 utils.hasFilename = function hasFilename(re) {
95 var name = utils.filename(fp);
96 return name && re.test(name);
101 * Coerce `val` to an array
107 utils.arrayify = function arrayify(val) {
108 return !Array.isArray(val)
114 * Normalize all slashes in a file path or glob pattern to
118 utils.unixify = function unixify(fp, opts) {
119 if (opts && opts.unixify === false) return fp;
120 if (opts && opts.unixify === true || win32 || path.sep === '\\') {
121 return utils.normalize(fp, false);
123 if (opts && opts.unescape === true) {
124 return fp ? fp.toString().replace(/\\(\w)/g, '$1') : '';
130 * Escape/unescape utils
133 utils.escapePath = function escapePath(fp) {
134 return fp.replace(/[\\.]/g, '\\$&');
137 utils.unescapeGlob = function unescapeGlob(fp) {
138 return fp.replace(/[\\"']/g, '');
141 utils.escapeRe = function escapeRe(str) {
142 return str.replace(/[-[\\$*+?.#^\s{}(|)\]]/g, '\\$&');
149 module.exports = utils;