Sha256: 809fc29cf35ab0aa76b99cad29182f62c0ae598902481d10f9868eaef71981ee

Contents?: true

Size: 1.84 KB

Versions: 151

Compression:

Stored size: 1.84 KB

Contents

'use strict';

const path = require('path');
const win32 = process.platform === 'win32';
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.removeBackslashes = str => {
  return str.replace(REGEX_REMOVE_BACKSLASH, match => {
    return match === '\\' ? '' : match;
  });
};

exports.supportsLookbehinds = () => {
  const segs = process.version.slice(1).split('.').map(Number);
  if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
    return true;
  }
  return false;
};

exports.isWindows = options => {
  if (options && typeof options.windows === 'boolean') {
    return options.windows;
  }
  return win32 === true || path.sep === '\\';
};

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

Version data entries

151 entries across 124 versions & 11 rubygems

Version Path
immosquare-cleaner-0.1.62 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.61 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.60 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.59 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.58 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.57 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.56 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.55 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.54 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.53 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.52 node_modules/picomatch/lib/utils.js
trusty-cms-6.3.1 node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.51 node_modules/picomatch/lib/utils.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/@rollup/pluginutils/node_modules/picomatch/lib/utils.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/@rollup/plugin-commonjs/node_modules/picomatch/lib/utils.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/@rollup/pluginutils/node_modules/picomatch/lib/utils.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/@rollup/plugin-commonjs/node_modules/picomatch/lib/utils.js
immosquare-cleaner-0.1.50 node_modules/picomatch/lib/utils.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/@rollup/plugin-commonjs/node_modules/picomatch/lib/utils.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/@rollup/pluginutils/node_modules/picomatch/lib/utils.js