-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (64 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*!
* is-installed <https://github.com/tunnckoCore/is-installed>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (http://i.am.charlike.online)
* Released under the MIT license.
*/
'use strict'
const detect = require('detect-installed')
/**
* > Check if given `name` package is installed locally,
* then checks if it exists globally, using [detect-installed][]
* and so [global-modules][] (which in turn rely on [global-prefix][]).
* Windows bugs comes from [global-prefix][].
*
* **Example**
*
* ```js
* const isInstalled = require('is-installed')
*
* isInstalled('npm').then((exists) => {
* console.log(exists) // => true
* })
*
* // installed locally for this package
* isInstalled('detect-installed').then((exists) => {
* console.log(exists) // => true
* })
*
* isInstalled('foo-bar-baz-qux').then((exists) => {
* console.log(exists) // => false
* })
* ```
*
* @param {String} `name` package name
* @return {Promise} resolved promise with boolean value
* @api public
*/
module.exports = function isInstalled (name) {
return detect(name, { local: true }).then((exists) => {
return exists || detect(name)
})
}
/**
* > Synchronously check if package `name` is installed.
*
* **Example**
*
* ```js
* const isInstalled = require('is-installed')
*
* const npmExists = isInstalled.sync('npm')
* console.log(npmExists) // => true
*
* const notExists = isInstalled.sync('foo-abra-fsddsfsd-fsdf')
* console.log(notExists) // => false
* ```
*
* @param {String} `name` package name
* @return {Boolean} always boolean `true` or `false`
* @api public
*/
module.exports.sync = function isInstalledSync (name) {
return detect.sync(name, { local: true }) || detect.sync(name)
}