process-exists
Advanced tools
Comparing version 3.0.0 to 3.1.0
12
index.js
'use strict'; | ||
const psList = require('ps-list'); | ||
module.exports = proc => { | ||
let fn = x => x.pid === proc; | ||
const fn = (proc, x) => { | ||
if (typeof proc === 'string') { | ||
fn = x => x.name === proc; | ||
return x.name === proc; | ||
} | ||
return psList().then(list => list.some(x => fn(x))); | ||
return x.pid === proc; | ||
}; | ||
module.exports = proc => psList().then(list => list.some(x => fn(proc, x))); | ||
module.exports.all = procs => psList().then(list => new Map(procs.map(x => [x, list.some(y => fn(x, y))]))); | ||
module.exports.filterExists = procs => psList().then(list => procs.filter(x => list.some(y => fn(x, y)))); |
{ | ||
"name": "process-exists", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Check if a process is running", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -22,2 +22,11 @@ # process-exists [![Build Status](https://travis-ci.org/sindresorhus/process-exists.svg?branch=master)](https://travis-ci.org/sindresorhus/process-exists) | ||
}); | ||
processExists.all([process.pid, 'foo']).then(exists => { | ||
console.log(exists.get(process.pid)); | ||
//=> true | ||
console.log(exists.get('foo')); | ||
//=> false | ||
console.log(processExists.filterExists(exists)); | ||
//=> [process.pid] | ||
}); | ||
``` | ||
@@ -38,5 +47,25 @@ | ||
### processExists.all(input) | ||
Returns a `Promise<Map>` with the process name/ID as key and the status as a boolean value. | ||
#### input | ||
Type: `Array<number|string>` | ||
Process IDs or names to check. | ||
### processExists.filterExists(input) | ||
Returns an `Array<number|string>` with the processes that exist. | ||
#### input | ||
Type: `Array<number|string>` | ||
Process IDs or names to check. | ||
## License | ||
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3394
11
70
0