process-exists
Advanced tools
Comparing version 4.1.0 to 5.0.0
@@ -1,29 +0,25 @@ | ||
declare const processExists: { | ||
/** | ||
Check if a process exists. | ||
/** | ||
Check if a process exists. | ||
@param input - Process ID or name to check. | ||
@returns Whether the process exists. | ||
*/ | ||
(input: number | string): Promise<boolean>; | ||
@param input - The process ID or name to check. | ||
@returns Whether the process exists. | ||
*/ | ||
export function processExists(input: number | string): Promise<boolean>; | ||
/** | ||
Check multiple processes if they exist. | ||
/** | ||
Check multiple processes if they exist. | ||
@param input - Process IDs or names to check. | ||
@returns A map with the process name/ID as key and the status as a boolean value. | ||
*/ | ||
all( | ||
input: readonly (number | string)[], | ||
): Promise<Map<number | string, boolean>>; | ||
@param input - The process IDs or names to check. | ||
@returns A map with the process name/ID as key and the status as a boolean value. | ||
*/ | ||
export function processExistsMultiple<T extends (number | string)>( | ||
input: readonly T[], | ||
): Promise<Map<T, boolean>>; | ||
/** | ||
Filter for processes that exist. | ||
/** | ||
Filter processes that exist. | ||
@param input - Process IDs or names to check. | ||
@returns The processes that exist. | ||
*/ | ||
filterExists(input: readonly (number | string)[]): (number | string)[]; | ||
}; | ||
export = processExists; | ||
@param input - The process IDs or names to check. | ||
@returns The processes that exist. | ||
*/ | ||
export function filterExistingProcesses<T extends ReadonlyArray<number | string>>(input: T): T; |
22
index.js
@@ -1,3 +0,3 @@ | ||
'use strict'; | ||
const psList = require('ps-list'); | ||
import process from 'node:process'; | ||
import psList from 'ps-list'; | ||
@@ -22,15 +22,15 @@ const linuxProcessMatchesName = (wantedProcessName, process) => { | ||
module.exports = async processName => { | ||
export async function processExists(processName) { | ||
const processes = await psList(); | ||
return processes.some(x => processMatchesName(processName, x)); | ||
}; | ||
return processes.some(process_ => processMatchesName(processName, process_)); | ||
} | ||
module.exports.all = async processName => { | ||
export async function processExistsMultiple(processNames) { | ||
const processes = await psList(); | ||
return new Map(processName.map(x => [x, processes.some(y => processMatchesName(x, y))])); | ||
}; | ||
return new Map(processNames.map(processName => [processName, processes.some(y => processMatchesName(processName, y))])); | ||
} | ||
module.exports.filterExists = async processNames => { | ||
export async function filterExistingProcesses(processNames) { | ||
const processes = await psList(); | ||
return processNames.filter(x => processes.some(y => processMatchesName(x, y))); | ||
}; | ||
return processNames.filter(processName => processes.some(process_ => processMatchesName(processName, process_))); | ||
} |
{ | ||
"name": "process-exists", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"description": "Check if a process is running", | ||
@@ -11,6 +11,8 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -37,10 +39,10 @@ "scripts": { | ||
"dependencies": { | ||
"ps-list": "^6.3.0" | ||
"ps-list": "^8.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"noop-process": "^4.0.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.25.0" | ||
"ava": "^3.15.0", | ||
"noop-process": "^5.0.0", | ||
"tsd": "^0.18.0", | ||
"xo": "^0.46.4" | ||
} | ||
} |
@@ -7,5 +7,5 @@ # process-exists | ||
```sh | ||
npm install process-exists | ||
``` | ||
$ npm install process-exists | ||
``` | ||
@@ -15,19 +15,17 @@ ## Usage | ||
```js | ||
const processExists = require('process-exists'); | ||
import {processExists, processExistsMultiple, filterExistingProcesses} from 'process-exists'; | ||
(async () => { | ||
console.log(await processExists(process.pid)); | ||
//=> true | ||
console.log(await processExists(process.pid)); | ||
//=> true | ||
const exists = await processExists.all([process.pid, 'foo']); | ||
const exists = await processExistsMultiple([process.pid, 'foo']); | ||
console.log(exists.get(process.pid)); | ||
//=> true | ||
console.log(exists.get(process.pid)); | ||
//=> true | ||
console.log(exists.get('foo')); | ||
//=> false | ||
console.log(exists.get('foo')); | ||
//=> false | ||
console.log(processExists.filterExists(exists)); | ||
//=> [process.pid] | ||
})(); | ||
console.log(filterExistingProcesses(exists)); | ||
//=> [process.pid] | ||
``` | ||
@@ -39,2 +37,4 @@ | ||
Check if a process exists. | ||
Returns a `Promise<boolean>`. | ||
@@ -46,6 +46,8 @@ | ||
Process ID or name to check. | ||
The process ID or name to check. | ||
### processExists.all(input) | ||
### processExistsMultiple(input) | ||
Check multiple processes if they exist. | ||
Returns a `Promise<Map>` with the process name/ID as key and the status as a boolean value. | ||
@@ -57,6 +59,8 @@ | ||
Process IDs or names to check. | ||
The process IDs or names to check. | ||
### processExists.filterExists(input) | ||
### filterExistingProcesses(input) | ||
Filter processes that exist. | ||
Returns an `Array<number | string>` with the processes that exist. | ||
@@ -68,2 +72,2 @@ | ||
Process IDs or names to check. | ||
The process IDs or names to check. |
Sorry, the diff of this file is not supported yet
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
5033
68
Yes
47
+ Addedps-list@8.1.1(transitive)
- Removedps-list@6.3.0(transitive)
Updatedps-list@^8.0.0