kill-me-now 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +24 -20
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ /**
4
+ * @typedef {{ name: string, pid: number, command: string }} OpenFileType
5
+ */
6
+
3
7
  import debug from 'debug'
4
8
 
5
9
  import {
@@ -22,13 +26,13 @@ log('`kill-me-now` is awake')
22
26
 
23
27
  /**
24
28
  * @param {string} alpha
25
- * @returns {(openFile: Record<string, string>) => boolean}
29
+ * @returns {(openFile: OpenFileType) => boolean}
26
30
  */
27
31
  function getHasName (alpha) {
28
32
  info('getHasName')
29
33
 
30
34
  /**
31
- * @param {Record<string, string>} openFile
35
+ * @param {OpenFileType} openFile
32
36
  * @returns {boolean}
33
37
  */
34
38
  return function hasName ({ name: omega }) {
@@ -42,14 +46,14 @@ function getHasName (alpha) {
42
46
 
43
47
  /**
44
48
  * @param {number} alpha
45
- * @returns {(openFile: Record<string, string>) => boolean}
49
+ * @returns {(openFile: OpenFileType) => boolean}
46
50
  */
47
- function getHasPid (alpha) {
48
- info('getHasPid')
51
+ function getHasProcessId (alpha) {
52
+ info('getHasProcessId')
49
53
 
50
54
  if (alpha) {
51
- return function hasPid ({ pid: omega }) {
52
- info('hasPid')
55
+ return function hasProcessId ({ pid: omega }) {
56
+ info('hasProcessId')
53
57
 
54
58
  return (
55
59
  omega !== alpha
@@ -64,14 +68,14 @@ function getHasPid (alpha) {
64
68
 
65
69
  /**
66
70
  * @param {string} alpha
67
- * @returns {(openFile: Record<string, string>) => boolean}
71
+ * @returns {(openFile: OpenFileType) => boolean}
68
72
  */
69
- function getHasCmd (alpha) {
70
- info('getHasCmd')
73
+ function getHasCommand (alpha) {
74
+ info('getHasCommand')
71
75
 
72
76
  if (alpha) {
73
- return function hasCmd ({ cmd: omega }) {
74
- info('hasCmd')
77
+ return function hasCommand ({ command: omega }) {
78
+ info('hasCommand')
75
79
 
76
80
  return (
77
81
  omega === alpha
@@ -85,11 +89,11 @@ function getHasCmd (alpha) {
85
89
  }
86
90
 
87
91
  /**
88
- * @param {Record<string, string>} openFile
92
+ * @param {{ pid: number }} openFile
89
93
  * @returns {void}
90
94
  */
91
- function killProcess ({ pid }) {
92
- info('killProcess')
95
+ function killProcessById ({ pid }) {
96
+ info('killProcessById')
93
97
 
94
98
  try {
95
99
  log(`Killing process ${pid} ...`)
@@ -111,18 +115,18 @@ function killProcess ({ pid }) {
111
115
  /**
112
116
  * @param {string} name Name or File Path
113
117
  * @param {number} [pid] Process ID
114
- * @param {string} [cmd] Command
118
+ * @param {string} [command] Command
115
119
  * @returns {Promise<void>}
116
120
  */
117
- export default async function killMeNow (name, pid, cmd) {
121
+ export default async function killMeNow (name, pid, command) {
118
122
  const lsof = await getLsofArray()
119
123
  const hasName = getHasName(name)
120
124
 
121
125
  if (lsof.some(hasName)) {
122
126
  lsof
123
127
  .filter(hasName)
124
- .filter(getHasPid(pid))
125
- .filter(getHasCmd(cmd))
126
- .forEach(killProcess)
128
+ .filter(getHasProcessId(pid))
129
+ .filter(getHasCommand(command))
130
+ .forEach(killProcessById)
127
131
  }
128
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kill-me-now",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "main": "./index.mjs",
5
5
  "type": "module",
6
6
  "author": {