default-browser-id
Advanced tools
Comparing version 2.0.0 to 3.0.0
52
index.js
@@ -1,12 +0,12 @@ | ||
'use strict'; | ||
const os = require('os'); | ||
const bplist = require('bplist-parser'); | ||
const untildify = require('untildify'); | ||
const pify = require('pify'); | ||
const osxVersion = Number(os.release().split('.')[0]); | ||
const file = untildify(osxVersion >= 14 ? '~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist' : '~/Library/Preferences/com.apple.LaunchServices.plist'); | ||
import os from 'os'; | ||
import {promises as fs} from 'fs'; | ||
import bplist from 'bplist-parser'; | ||
import untildify from 'untildify'; | ||
module.exports = () => { | ||
const macOsVersion = Number(os.release().split('.')[0]); | ||
const filePath = untildify(macOsVersion >= 14 ? '~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist' : '~/Library/Preferences/com.apple.LaunchServices.plist'); | ||
export default async function defaultBrowserId() { | ||
if (process.platform !== 'darwin') { | ||
return Promise.reject(new Error('Only OS X is supported')); | ||
throw new Error('macOS only'); | ||
} | ||
@@ -16,18 +16,28 @@ | ||
return pify(bplist.parseFile)(file).then(data => { | ||
const handlers = data && data[0].LSHandlers; | ||
if (!handlers || handlers.length === 0) { | ||
let buffer; | ||
try { | ||
buffer = await fs.readFile(filePath); | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
return bundleId; | ||
} | ||
for (const el of handlers) { | ||
if (el.LSHandlerURLScheme === 'http' && el.LSHandlerRoleAll) { | ||
bundleId = el.LSHandlerRoleAll; | ||
break; | ||
} | ||
throw error; | ||
} | ||
const data = bplist.parseBuffer(buffer); | ||
const handlers = data && data[0].LSHandlers; | ||
if (!handlers || handlers.length === 0) { | ||
return bundleId; | ||
} | ||
for (const handler of handlers) { | ||
if (handler.LSHandlerURLScheme === 'http' && handler.LSHandlerRoleAll) { | ||
bundleId = handler.LSHandlerRoleAll; | ||
break; | ||
} | ||
} | ||
return bundleId; | ||
}); | ||
}; | ||
return bundleId; | ||
} |
{ | ||
"name": "default-browser-id", | ||
"version": "2.0.0", | ||
"description": "Get the bundle identifier of the default browser (OS X). Example: com.apple.Safari", | ||
"license": "MIT", | ||
"repository": "sindresorhus/default-browser-id", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"osx", | ||
"browser", | ||
"default", | ||
"plist", | ||
"web", | ||
"bundle", | ||
"bundleid", | ||
"id", | ||
"identifier", | ||
"uti" | ||
], | ||
"dependencies": { | ||
"bplist-parser": "^0.1.0", | ||
"pify": "^2.3.0", | ||
"untildify": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "default-browser-id", | ||
"version": "3.0.0", | ||
"description": "Get the bundle identifier of the default browser (macOS). Example: com.apple.Safari", | ||
"license": "MIT", | ||
"repository": "sindresorhus/default-browser-id", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"macos", | ||
"browser", | ||
"default", | ||
"plist", | ||
"web", | ||
"bundle", | ||
"bundleid", | ||
"id", | ||
"identifier", | ||
"uti" | ||
], | ||
"dependencies": { | ||
"bplist-parser": "^0.2.0", | ||
"untildify": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -1,28 +0,19 @@ | ||
# default-browser-id [![Build Status](https://travis-ci.org/sindresorhus/default-browser-id.svg?branch=master)](https://travis-ci.org/sindresorhus/default-browser-id) | ||
# default-browser-id | ||
> Get the [bundle identifier](https://developer.apple.com/library/Mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/plist/info/CFBundleIdentifier) of the default browser (OS X)<br> | ||
> Get the [bundle identifier](https://developer.apple.com/library/Mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/plist/info/CFBundleIdentifier) of the default browser *(macOS)*\ | ||
> Example: `com.apple.Safari` | ||
## Install | ||
``` | ||
$ npm install --save default-browser-id | ||
$ npm install default-browser-id | ||
``` | ||
## Usage | ||
```js | ||
const defaultBrowserId = require('default-browser-id'); | ||
import defaultBrowserId from 'default-browser-id'; | ||
defaultBrowserId().then(browserId => { | ||
console.log(browserId); | ||
//=> 'com.apple.Safari' | ||
}); | ||
console.log(await defaultBrowserId()); | ||
//=> 'com.apple.Safari' | ||
``` | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
33
Yes
3462
20
2
+ Addedbplist-parser@0.2.0(transitive)
+ Addeduntildify@4.0.0(transitive)
- Removedpify@^2.3.0
- Removedbplist-parser@0.1.1(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedpify@2.3.0(transitive)
- Removeduntildify@2.1.0(transitive)
Updatedbplist-parser@^0.2.0
Updateduntildify@^4.0.0