• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

micromatch / picomatch / 8461973899

28 Mar 2024 03:23AM UTC coverage: 91.968% (+0.004%) from 91.964%
8461973899

push

github

jonschlinkert
4.0.2

752 of 837 branches covered (89.84%)

Branch coverage included in aggregate %.

874 of 931 relevant lines covered (93.88%)

3440.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.03
/lib/utils.js
1
/*global navigator*/
2
'use strict';
3

4
const {
5
  REGEX_BACKSLASH,
6
  REGEX_REMOVE_BACKSLASH,
7
  REGEX_SPECIAL_CHARS,
8
  REGEX_SPECIAL_CHARS_GLOBAL
9
} = require('./constants');
1✔
10

11
exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
1!
12
exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
1,150✔
13
exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
1!
14
exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
417✔
15
exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
2,729✔
16

17
exports.isWindows = () => {
1✔
18
  if (typeof navigator !== 'undefined' && navigator.platform) {
227!
19
    const platform = navigator.platform.toLowerCase();
×
20
    return platform === 'win32' || platform === 'windows';
×
21
  }
22

23
  if (typeof process !== 'undefined' && process.platform) {
227!
24
    return process.platform === 'win32';
227✔
25
  }
26

27
  return false;
×
28
};
29

30
exports.removeBackslashes = str => {
1✔
31
  return str.replace(REGEX_REMOVE_BACKSLASH, match => {
24✔
32
    return match === '\\' ? '' : match;
30✔
33
  });
34
};
35

36
exports.escapeLast = (input, char, lastIdx) => {
1✔
37
  const idx = input.lastIndexOf(char, lastIdx);
40✔
38
  if (idx === -1) return input;
40✔
39
  if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
36✔
40
  return `${input.slice(0, idx)}\\${input.slice(idx)}`;
32✔
41
};
42

43
exports.removePrefix = (input, state = {}) => {
1!
44
  let output = input;
12,067✔
45
  if (output.startsWith('./')) {
12,067✔
46
    output = output.slice(2);
92✔
47
    state.prefix = './';
92✔
48
  }
49
  return output;
12,067✔
50
};
51

52
exports.wrapOutput = (input, state = {}, options = {}) => {
1!
53
  const prepend = options.contains ? '' : '^';
781!
54
  const append = options.contains ? '' : '$';
781!
55

56
  let output = `${prepend}(?:${input})${append}`;
781✔
57
  if (state.negated === true) {
781!
58
    output = `(?:^(?!${output}).*$)`;
×
59
  }
60
  return output;
781✔
61
};
62

63
exports.basename = (path, { windows } = {}) => {
1✔
64
  const segs = path.split(windows ? /[\\/]/ : '/');
16✔
65
  const last = segs[segs.length - 1];
16✔
66

67
  if (last === '') {
16✔
68
    return segs[segs.length - 2];
4✔
69
  }
70

71
  return last;
12✔
72
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc