default-browser-id
Advanced tools
Comparing version 1.0.4 to 2.0.0
32
index.js
'use strict'; | ||
var os = require('os'); | ||
var bplist = require('bplist-parser'); | ||
var untildify = require('untildify'); | ||
var bundleId = 'com.apple.Safari'; | ||
var osxVersion = Number(os.release().split('.')[0]); | ||
var file = untildify(osxVersion >= 14 ? '~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist' : '~/Library/Preferences/com.apple.LaunchServices.plist'); | ||
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'); | ||
module.exports = function (cb) { | ||
module.exports = () => { | ||
if (process.platform !== 'darwin') { | ||
throw new Error('Only OS X systems are supported'); | ||
return Promise.reject(new Error('Only OS X is supported')); | ||
} | ||
bplist.parseFile(file, function (err, data) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
let bundleId = 'com.apple.Safari'; | ||
var handlers = data && data[0].LSHandlers; | ||
return pify(bplist.parseFile)(file).then(data => { | ||
const handlers = data && data[0].LSHandlers; | ||
if (!handlers || handlers.length === 0) { | ||
return cb(null, bundleId); | ||
return bundleId; | ||
} | ||
for (var i = 0; i < handlers.length; i++) { | ||
var el = handlers[i]; | ||
for (const el of handlers) { | ||
if (el.LSHandlerURLScheme === 'http' && el.LSHandlerRoleAll) { | ||
@@ -34,4 +30,4 @@ bundleId = el.LSHandlerRoleAll; | ||
cb(null, bundleId); | ||
return bundleId; | ||
}); | ||
}; |
{ | ||
"name": "default-browser-id", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "Get the bundle identifier of the default browser (OS X). Example: com.apple.Safari", | ||
@@ -12,16 +12,12 @@ "license": "MIT", | ||
}, | ||
"bin": "cli.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"cli.js" | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"cli-app", | ||
"cli", | ||
"osx", | ||
@@ -40,8 +36,12 @@ "browser", | ||
"bplist-parser": "^0.1.0", | ||
"meow": "^3.1.0", | ||
"pify": "^2.3.0", | ||
"untildify": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
} |
# default-browser-id [![Build Status](https://travis-ci.org/sindresorhus/default-browser-id.svg?branch=master)](https://travis-ci.org/sindresorhus/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) | ||
> 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> | ||
> Example: `com.apple.Safari` | ||
## Usage | ||
## Install | ||
@@ -13,6 +13,9 @@ ``` | ||
## Usage | ||
```js | ||
var defaultBrowserId = require('default-browser-id'); | ||
const defaultBrowserId = require('default-browser-id'); | ||
defaultBrowserId(function (err, browserId) { | ||
defaultBrowserId().then(browserId => { | ||
console.log(browserId); | ||
@@ -24,19 +27,4 @@ //=> 'com.apple.Safari' | ||
## CLI | ||
``` | ||
$ npm install --global default-browser-id | ||
``` | ||
``` | ||
$ default-browser-id --help | ||
Example | ||
$ default-browser-id | ||
com.apple.Safari | ||
``` | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
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
3576
2
4
26
29
+ Addedpify@^2.3.0
- Removedmeow@^3.1.0
- Removedarray-find-index@1.0.2(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)