From f7751def5ceea7a294b0007aa8b4181784856cff Mon Sep 17 00:00:00 2001 From: Jon Schlinkert Date: Wed, 27 Mar 2024 23:22:20 -0400 Subject: [PATCH] move `isWindows` to utils --- index.js | 18 ++---------------- lib/utils.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index a281ffb..a753b1d 100644 --- a/index.js +++ b/index.js @@ -1,27 +1,13 @@ -/*global navigator*/ - 'use strict'; const pico = require('./lib/picomatch'); - -const 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; -}; +const utils = require('./lib/utils'); function picomatch(glob, options, returnState = false) { // default to os.platform() if (options && (options.windows === null || options.windows === undefined)) { // don't mutate the original options object - options = { ...options, windows: isWindows() }; + options = { ...options, windows: utils.isWindows() }; } return pico(glob, options, returnState); diff --git a/lib/utils.js b/lib/utils.js index b53c287..9c97cae 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,3 +1,4 @@ +/*global navigator*/ 'use strict'; const { @@ -13,6 +14,19 @@ 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;