default-browser
Advanced tools
Comparing version 5.1.0 to 5.2.0
23
index.js
@@ -0,11 +1,22 @@ | ||
import {promisify} from 'node:util'; | ||
import process from 'node:process'; | ||
import {execFile} from 'node:child_process'; | ||
import defaultBrowserId from 'default-browser-id'; | ||
import bundleName from 'bundle-name'; | ||
import titleize from 'titleize'; | ||
import {execa} from 'execa'; | ||
import windows from './windows.js'; | ||
const execFileAsync = promisify(execFile); | ||
// Inlined: https://github.com/sindresorhus/titleize/blob/main/index.js | ||
const titleize = string => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, x => x.toUpperCase()); | ||
export default async function defaultBrowser() { | ||
if (process.platform === 'darwin') { | ||
const id = await defaultBrowserId(); | ||
const name = await bundleName(id); | ||
return {name, id}; | ||
} | ||
if (process.platform === 'linux') { | ||
const {stdout} = await execa('xdg-mime', ['query', 'default', 'x-scheme-handler/http']); | ||
const {stdout} = await execFileAsync('xdg-mime', ['query', 'default', 'x-scheme-handler/http']); | ||
const name = titleize(stdout.trim().replace(/.desktop$/, '').replace('-', ' ')); | ||
@@ -19,8 +30,2 @@ | ||
if (process.platform === 'darwin') { | ||
const id = await defaultBrowserId(); | ||
const name = await bundleName(id); | ||
return {name, id}; | ||
} | ||
if (process.platform === 'win32') { | ||
@@ -27,0 +32,0 @@ return windows(); |
{ | ||
"name": "default-browser", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Get the default browser", | ||
@@ -18,2 +18,3 @@ "license": "MIT", | ||
}, | ||
"sideEffects": false, | ||
"engines": { | ||
@@ -46,12 +47,10 @@ "node": ">=18" | ||
"dependencies": { | ||
"bundle-name": "^4.0.0", | ||
"default-browser-id": "^4.0.0", | ||
"execa": "^8.0.1", | ||
"titleize": "^4.0.0" | ||
"bundle-name": "^4.1.0", | ||
"default-browser-id": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^5.3.1", | ||
"tsd": "^0.29.0", | ||
"ava": "^6.0.1", | ||
"tsd": "^0.30.0", | ||
"xo": "^0.56.0" | ||
} | ||
} |
@@ -1,3 +0,6 @@ | ||
import {execa} from 'execa'; | ||
import {promisify} from 'node:util'; | ||
import {execFile} from 'node:child_process'; | ||
const execFileAsync = promisify(execFile); | ||
// Windows doesn't have browser IDs in the same way macOS/Linux does so we give fake | ||
@@ -19,4 +22,4 @@ // ones that look real and match the macOS/Linux versions for cross-platform apps. | ||
export default async function defaultBrowser(_execa = execa) { | ||
const result = await _execa('reg', [ | ||
export default async function defaultBrowser(_execFileAsync = execFileAsync) { | ||
const {stdout} = await _execFileAsync('reg', [ | ||
'QUERY', | ||
@@ -28,5 +31,5 @@ ' HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice', | ||
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(result.stdout); | ||
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout); | ||
if (!match) { | ||
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(result.stdout)}`); | ||
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`); | ||
} | ||
@@ -33,0 +36,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5825
2
87
+ Addeddefault-browser-id@5.0.0(transitive)
- Removedexeca@^8.0.1
- Removedtitleize@^4.0.0
- Removedbig-integer@1.6.52(transitive)
- Removedbplist-parser@0.3.2(transitive)
- Removedcross-spawn@7.0.3(transitive)
- Removeddefault-browser-id@4.0.0(transitive)
- Removedexeca@8.0.1(transitive)
- Removedget-stream@8.0.1(transitive)
- Removedhuman-signals@5.0.0(transitive)
- Removedis-stream@3.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedmerge-stream@2.0.0(transitive)
- Removedmimic-fn@4.0.0(transitive)
- Removednpm-run-path@5.3.0(transitive)
- Removedonetime@6.0.0(transitive)
- Removedpath-key@3.1.14.0.0(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@4.1.0(transitive)
- Removedstrip-final-newline@3.0.0(transitive)
- Removedtitleize@4.0.0(transitive)
- Removeduntildify@5.0.0(transitive)
- Removedwhich@2.0.2(transitive)
Updatedbundle-name@^4.1.0
Updateddefault-browser-id@^5.0.0