Sha256: 6b8f8aa95fac9d8ba7fcb1393d7e271d81fb8aa86a641fbd805c87bd53a0cba4

Contents?: true

Size: 1.63 KB

Versions: 10

Compression:

Stored size: 1.63 KB

Contents

'use strict';

var path = require('path');
var fileRe = require('filename-regex');
var win32 = process && process.platform === 'win32';
var win;

var utils = {};

utils.filename = function filename(fp) {
  var seg = fp.match(fileRe());
  return seg && seg[0];
};

utils.isPath = function isPath(pattern, opts) {
  return function (fp) {
    return utils.unixify(fp, opts) === pattern;
  };
};

utils.hasPath = function hasPath(pattern, opts) {
  return function (fp) {
    return utils.unixify(fp, opts).indexOf(pattern) !== -1;
  };
};

utils.matchPath = function matchPath(pattern, opts) {
  var fn = (opts && opts.contains)
    ? utils.hasPath(pattern, opts)
    : utils.isPath(pattern, opts);
  return fn;
};

utils.hasFilename = function hasFilename(re) {
  return function (fp) {
    var name = utils.filename(fp);
    return name && re.test(name);
  };
};

/**
 * Coerce `val` to an array
 *
 * @param  {*} val
 * @return {Array}
 */

utils.arrayify = function arrayify(val) {
  return !Array.isArray(val)
    ? [val]
    : val;
};

/**
 * Convert a file path to a unix path.
 */

utils.unixify = function unixify(fp, opts) {
  if (opts && opts.unixify === false) return fp;
  if (opts && opts.unixify === true || win32 || path.sep === '\\') {
    return fp.split('\\').join('/');
  }
  return fp;
};

/**
 * Escape/unescape utils
 */

utils.escapePath = function escapePath(fp) {
  return fp.replace(/[\\.]/g, '\\$&');
};

utils.unescapeGlob = function unescapeGlob(fp) {
  return fp.replace(/[\\"']/g, '');
};

utils.escapeRe = function escapeRe(str) {
  return str.replace(/[-[\\$*+?.#^\s{}(|)\]]/g, '\\$&');
};

/**
 * Expose `utils`
 */

module.exports = utils;

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/lib/utils.js