Skip to content

Commit

Permalink
Improve Deno compatibility (#142)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
idranme and sindresorhus authored Dec 7, 2022
1 parent 600e5dc commit b3d6534
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
/* eslint-env browser */

const isBlinkBasedBrowser = navigator.userAgentData
? navigator.userAgentData.brands.some(({brand}) => brand === 'Chromium')
: /\b(Chrome|Chromium)\//.test(navigator.userAgent);
const level = (() => {
if (navigator.userAgentData) {
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
if (brand?.version > 93) {
return 3;
}
}

const colorSupport = isBlinkBasedBrowser ? {
level: 1,
if (/\b(Chrome|Chromium)\//.test(navigator.userAgent)) {
return 1;
}

return 0;
})();

const colorSupport = level !== 0 && {
level,
hasBasic: true,
has256: false,
has16m: false,
} : false;
has256: level >= 2,
has16m: level >= 3,
};

const supportsColor = {
stdout: colorSupport,
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from 'node:os';
import tty from 'node:tty';

// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
function hasFlag(flag, argv = process.argv) {
function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
const position = argv.indexOf(prefix + flag);
const terminatorPosition = argv.indexOf('--');
Expand Down

0 comments on commit b3d6534

Please sign in to comment.