Sha256: f04604f70cd1a3f6ace80b84766468674ff38b4bb83818d2ef1d81fc6355f935

Contents?: true

Size: 1.95 KB

Versions: 26

Compression:

Stored size: 1.95 KB

Contents

/*global navigator*/
'use strict';

const {
  REGEX_BACKSLASH,
  REGEX_REMOVE_BACKSLASH,
  REGEX_SPECIAL_CHARS,
  REGEX_SPECIAL_CHARS_GLOBAL
} = require('./constants');

exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');

exports.isWindows = () => {
  if (typeof navigator !== 'undefined' && navigator.platform) {
    const platform = navigator.platform.toLowerCase();
    return platform === 'win32' || platform === 'windows';
  }

  if (typeof process !== 'undefined' && process.platform) {
    return process.platform === 'win32';
  }

  return false;
};

exports.removeBackslashes = str => {
  return str.replace(REGEX_REMOVE_BACKSLASH, match => {
    return match === '\\' ? '' : match;
  });
};

exports.escapeLast = (input, char, lastIdx) => {
  const idx = input.lastIndexOf(char, lastIdx);
  if (idx === -1) return input;
  if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
  return `${input.slice(0, idx)}\\${input.slice(idx)}`;
};

exports.removePrefix = (input, state = {}) => {
  let output = input;
  if (output.startsWith('./')) {
    output = output.slice(2);
    state.prefix = './';
  }
  return output;
};

exports.wrapOutput = (input, state = {}, options = {}) => {
  const prepend = options.contains ? '' : '^';
  const append = options.contains ? '' : '$';

  let output = `${prepend}(?:${input})${append}`;
  if (state.negated === true) {
    output = `(?:^(?!${output}).*$)`;
  }
  return output;
};

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

  if (last === '') {
    return segs[segs.length - 2];
  }

  return last;
};

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/picomatch/lib/utils.js