@sequencemedia/lsof 0.0.8 → 0.0.10
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.
- package/package.json +2 -2
- package/src/1/common.mjs +86 -46
- package/src/1/to-array.mjs +9 -3
- package/src/1/to-set.mjs +9 -9
- package/src/2/common.mjs +20 -18
- package/src/2/to-array.mjs +2 -2
- package/src/2/to-set.mjs +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/lsof",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"lsof",
|
|
6
6
|
"list open files"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@sequencemedia/eslint-config-standard": "^0.2.54",
|
|
30
30
|
"@sequencemedia/eslint-config-typescript": "^0.1.85",
|
|
31
|
-
"@types/node": "^22.15.
|
|
31
|
+
"@types/node": "^22.15.14",
|
|
32
32
|
"eslint": "^9.26.0",
|
|
33
33
|
"globals": "^16.0.0"
|
|
34
34
|
},
|
package/src/1/common.mjs
CHANGED
|
@@ -2,6 +2,28 @@ import {
|
|
|
2
2
|
execFile
|
|
3
3
|
} from 'node:child_process'
|
|
4
4
|
|
|
5
|
+
/*
|
|
6
|
+
p: will prefix the PID or (Process ID) column
|
|
7
|
+
c: will prefix the Command or (Process Name) column
|
|
8
|
+
u: will prefix the User column
|
|
9
|
+
f: will prefix the File Descriptor column
|
|
10
|
+
t: will prefix the Type column
|
|
11
|
+
D: will prefix the Device column
|
|
12
|
+
s: will prefix the SizeOff column
|
|
13
|
+
i: will prefix the Node column
|
|
14
|
+
n: will prefix the Name or (File Path)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const PID_FLAG = 'p'
|
|
18
|
+
const COMMAND_FLAG = 'c'
|
|
19
|
+
const USER_FLAG = 'u'
|
|
20
|
+
const FD_FLAG = 'f'
|
|
21
|
+
const TYPE_FLAG = 't'
|
|
22
|
+
const DEVICE_FLAG = 'D'
|
|
23
|
+
const SIZEOFF_FLAG = 's'
|
|
24
|
+
const NODE_FLAG = 'i'
|
|
25
|
+
const NAME_FLAG = 'n'
|
|
26
|
+
|
|
5
27
|
export const PID = 'pid'
|
|
6
28
|
export const COMMAND = 'command'
|
|
7
29
|
export const USER = 'user'
|
|
@@ -14,6 +36,10 @@ export const NAME = 'name'
|
|
|
14
36
|
|
|
15
37
|
const LF = '\n'
|
|
16
38
|
|
|
39
|
+
const OPTIONS = {
|
|
40
|
+
maxBuffer: Infinity
|
|
41
|
+
}
|
|
42
|
+
|
|
17
43
|
/*
|
|
18
44
|
export function toCamelCase (value) {
|
|
19
45
|
return value.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, v) => v.toUpperCase())
|
|
@@ -28,97 +54,87 @@ export function fromTsv (string) {
|
|
|
28
54
|
}
|
|
29
55
|
*/
|
|
30
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} s
|
|
59
|
+
* @returns {number | string}
|
|
60
|
+
*/
|
|
61
|
+
function transform (s) {
|
|
62
|
+
if (!s) return s
|
|
63
|
+
|
|
64
|
+
const n = Number(s)
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
isNaN(n)
|
|
68
|
+
? s
|
|
69
|
+
: n
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
31
73
|
/**
|
|
32
74
|
* @param {string} s
|
|
33
75
|
* @returns {Record<string, number>}
|
|
34
76
|
*/
|
|
35
77
|
function getPid (s) {
|
|
78
|
+
const pid = s.slice(1).trim()
|
|
79
|
+
|
|
36
80
|
return {
|
|
37
|
-
|
|
81
|
+
[PID]: Number(pid)
|
|
38
82
|
}
|
|
39
83
|
}
|
|
40
84
|
|
|
41
|
-
/*
|
|
42
|
-
p: will prefix the PID or (Process ID) column
|
|
43
|
-
c: will prefix the COMMAND or (Process Name) column
|
|
44
|
-
u: will prefix the User column that the process is running under
|
|
45
|
-
f: will prefix the File Descriptor column
|
|
46
|
-
t: will prefix the type column
|
|
47
|
-
D: will prefix the Device column
|
|
48
|
-
s: will prefix the SizeOff column
|
|
49
|
-
i: will prefix the Node column
|
|
50
|
-
n: will prefix the Name or (File Path)
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
85
|
/**
|
|
54
86
|
* @param {string} s
|
|
55
87
|
* @returns {Record<string, string | number>}
|
|
56
88
|
*/
|
|
57
89
|
function getCol (s) {
|
|
58
90
|
const key = s.charAt(0)
|
|
59
|
-
const value = s.slice(1)
|
|
91
|
+
const value = s.slice(1).trim()
|
|
60
92
|
|
|
61
93
|
switch (key) {
|
|
62
|
-
case
|
|
94
|
+
case COMMAND_FLAG: // will prefix the Command or (Process Name) column
|
|
63
95
|
return {
|
|
64
96
|
[COMMAND]: value
|
|
65
97
|
}
|
|
66
98
|
|
|
67
|
-
case
|
|
99
|
+
case USER_FLAG: // will prefix the User column
|
|
68
100
|
return {
|
|
69
101
|
[USER]: value
|
|
70
102
|
}
|
|
71
103
|
|
|
72
|
-
case
|
|
73
|
-
{
|
|
74
|
-
const fd = Number(value)
|
|
75
|
-
|
|
104
|
+
case FD_FLAG: // will prefix the File Descriptor column
|
|
76
105
|
return {
|
|
77
|
-
[FD]:
|
|
106
|
+
[FD]: transform(value)
|
|
78
107
|
}
|
|
79
|
-
}
|
|
80
108
|
|
|
81
|
-
case
|
|
109
|
+
case TYPE_FLAG: // will prefix the Type column
|
|
82
110
|
return {
|
|
83
111
|
[TYPE]: value
|
|
84
112
|
}
|
|
85
113
|
|
|
86
|
-
case
|
|
114
|
+
case DEVICE_FLAG: // will prefix the Device column
|
|
87
115
|
return {
|
|
88
116
|
[DEVICE]: value
|
|
89
117
|
}
|
|
90
118
|
|
|
91
|
-
case
|
|
92
|
-
{
|
|
93
|
-
const sizeOff = Number(value)
|
|
94
|
-
|
|
119
|
+
case SIZEOFF_FLAG: // will prefix the SizeOff column
|
|
95
120
|
return {
|
|
96
|
-
[SIZEOFF]:
|
|
121
|
+
[SIZEOFF]: transform(value)
|
|
97
122
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
case 'i': // will prefix the Node column
|
|
101
|
-
{
|
|
102
|
-
const node = Number(value)
|
|
103
123
|
|
|
124
|
+
case NODE_FLAG: // will prefix the Node column
|
|
104
125
|
return {
|
|
105
|
-
[NODE]:
|
|
126
|
+
[NODE]: transform(value)
|
|
106
127
|
}
|
|
107
|
-
}
|
|
108
128
|
|
|
109
|
-
case
|
|
129
|
+
case NAME_FLAG: // will prefix the Name or (File Path)
|
|
110
130
|
return {
|
|
111
131
|
[NAME]: value
|
|
112
132
|
}
|
|
113
133
|
|
|
114
134
|
default:
|
|
115
|
-
{
|
|
116
|
-
const number = Number(value)
|
|
117
|
-
|
|
118
135
|
return {
|
|
119
|
-
[key]:
|
|
136
|
+
[key]: transform(value)
|
|
120
137
|
}
|
|
121
|
-
}
|
|
122
138
|
}
|
|
123
139
|
}
|
|
124
140
|
|
|
@@ -140,7 +156,7 @@ export function getSet (value = '') {
|
|
|
140
156
|
|
|
141
157
|
array
|
|
142
158
|
.forEach((s) => {
|
|
143
|
-
if (s.
|
|
159
|
+
if (s.startsWith(PID_FLAG)) {
|
|
144
160
|
OUTER.add((INNER = new Set([getPid(s)])))
|
|
145
161
|
} else {
|
|
146
162
|
INNER.add(getCol(s))
|
|
@@ -168,7 +184,7 @@ export function getArray (value = '') {
|
|
|
168
184
|
|
|
169
185
|
array
|
|
170
186
|
.forEach((s) => {
|
|
171
|
-
if (s.
|
|
187
|
+
if (s.startsWith(PID_FLAG)) {
|
|
172
188
|
OUTER.push((INNER = [getPid(s)]))
|
|
173
189
|
} else {
|
|
174
190
|
INNER.push(getCol(s))
|
|
@@ -178,8 +194,32 @@ export function getArray (value = '') {
|
|
|
178
194
|
return OUTER
|
|
179
195
|
}
|
|
180
196
|
|
|
181
|
-
|
|
182
|
-
|
|
197
|
+
/**
|
|
198
|
+
* @param {string} [value]
|
|
199
|
+
* @returns {Array<Array<Record<string, string | number>>>}
|
|
200
|
+
*/
|
|
201
|
+
export function getRows (value = '') {
|
|
202
|
+
const array = value.split(LF)
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @type {Array<Array<Record<string, string | number>>>}
|
|
206
|
+
*/
|
|
207
|
+
const OUTER = []
|
|
208
|
+
/**
|
|
209
|
+
* @type {Array<Record<string, string | number>>}
|
|
210
|
+
*/
|
|
211
|
+
let INNER
|
|
212
|
+
|
|
213
|
+
array
|
|
214
|
+
.forEach((s) => {
|
|
215
|
+
if (s.startsWith(PID_FLAG)) {
|
|
216
|
+
OUTER.push((INNER = [getPid(s)]))
|
|
217
|
+
} else {
|
|
218
|
+
INNER.push(getCol(s))
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
return OUTER
|
|
183
223
|
}
|
|
184
224
|
|
|
185
225
|
/**
|
package/src/1/to-array.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
PID,
|
|
3
3
|
COMMAND,
|
|
4
4
|
USER,
|
|
5
|
-
|
|
5
|
+
getRows
|
|
6
6
|
} from './common.mjs'
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -10,7 +10,13 @@ import {
|
|
|
10
10
|
* @param {...Array<string | number>} args
|
|
11
11
|
* @returns {Array<Array<string | number>>}
|
|
12
12
|
*/
|
|
13
|
-
function toEntries (
|
|
13
|
+
function toEntries (previous, ...args) {
|
|
14
|
+
const {
|
|
15
|
+
[PID]: pid,
|
|
16
|
+
[COMMAND]: command,
|
|
17
|
+
[USER]: user
|
|
18
|
+
} = previous
|
|
19
|
+
|
|
14
20
|
return [
|
|
15
21
|
[
|
|
16
22
|
PID,
|
|
@@ -67,7 +73,7 @@ function reduce (accumulator, current) {
|
|
|
67
73
|
* @returns {Array<Array<Record<string, string | number>>>}
|
|
68
74
|
*/
|
|
69
75
|
export default function toArray (value) {
|
|
70
|
-
const outer =
|
|
76
|
+
const outer = getRows(value)
|
|
71
77
|
|
|
72
78
|
return (
|
|
73
79
|
outer.map(map)
|
package/src/1/to-set.mjs
CHANGED
|
@@ -2,18 +2,18 @@ import {
|
|
|
2
2
|
PID,
|
|
3
3
|
COMMAND,
|
|
4
4
|
USER,
|
|
5
|
-
|
|
5
|
+
getRows
|
|
6
6
|
} from './common.mjs'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @param {Map<string, string | number>}
|
|
9
|
+
* @param {Map<string, string | number>} previous
|
|
10
10
|
* @param {...Array<string | number>} args
|
|
11
11
|
* @returns {Array<Array<string | number>>}
|
|
12
12
|
*/
|
|
13
|
-
function toEntries (
|
|
14
|
-
const pid =
|
|
15
|
-
const command =
|
|
16
|
-
const user =
|
|
13
|
+
function toEntries (previous, ...args) {
|
|
14
|
+
const pid = previous.get(PID)
|
|
15
|
+
const command = previous.get(COMMAND)
|
|
16
|
+
const user = previous.get(USER)
|
|
17
17
|
|
|
18
18
|
return [
|
|
19
19
|
[
|
|
@@ -38,7 +38,7 @@ function toEntries (map, ...args) {
|
|
|
38
38
|
*/
|
|
39
39
|
function map (inner) {
|
|
40
40
|
return (
|
|
41
|
-
new Set(
|
|
41
|
+
new Set(inner.reduce(reduce, [new Map()]))
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -71,9 +71,9 @@ function reduce (accumulator, current) {
|
|
|
71
71
|
* @returns {Set<Set<Map<string, string | number>>>}
|
|
72
72
|
*/
|
|
73
73
|
export default function toSet (value) {
|
|
74
|
-
const outer =
|
|
74
|
+
const outer = getRows(value)
|
|
75
75
|
|
|
76
76
|
return (
|
|
77
|
-
new Set(
|
|
77
|
+
new Set(outer.map(map))
|
|
78
78
|
)
|
|
79
79
|
}
|
package/src/2/common.mjs
CHANGED
|
@@ -30,28 +30,34 @@ const PATTERN = /^\s*(?<command>[!-~]+)\s+(?<pid>\d+)\s+(?<user>\w+)\s+(?<fd>\s+
|
|
|
30
30
|
|
|
31
31
|
const LF = '\n'
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* @returns {string[]}
|
|
36
|
-
*/
|
|
37
|
-
export function getArray (v) {
|
|
38
|
-
return v.trim().split(LF).slice(1)
|
|
33
|
+
const OPTIONS = {
|
|
34
|
+
maxBuffer: Infinity
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
38
|
+
* @param {string} string
|
|
39
|
+
* @returns {number | string}
|
|
44
40
|
*/
|
|
45
41
|
function transform (string) {
|
|
46
|
-
const
|
|
42
|
+
const s = string.trim()
|
|
43
|
+
if (!s) return s
|
|
47
44
|
|
|
45
|
+
const n = Number(s)
|
|
48
46
|
return (
|
|
49
|
-
isNaN(
|
|
50
|
-
?
|
|
51
|
-
:
|
|
47
|
+
isNaN(n)
|
|
48
|
+
? s
|
|
49
|
+
: n
|
|
52
50
|
)
|
|
53
51
|
}
|
|
54
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @param {string} v
|
|
55
|
+
* @returns {string[]}
|
|
56
|
+
*/
|
|
57
|
+
export function getRows (v) {
|
|
58
|
+
return v.trim().split(LF).slice(1)
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
/**
|
|
56
62
|
* @param {string} v
|
|
57
63
|
* @returns {Record<string, string | number>}
|
|
@@ -67,9 +73,9 @@ export function toObject (v) {
|
|
|
67
73
|
} = {}
|
|
68
74
|
} = match
|
|
69
75
|
|
|
70
|
-
const pid =
|
|
76
|
+
const pid = transform(PID)
|
|
71
77
|
|
|
72
|
-
if (
|
|
78
|
+
if (typeof pid === 'string') throw new Error('Invalid pid.')
|
|
73
79
|
|
|
74
80
|
const {
|
|
75
81
|
groups: {
|
|
@@ -97,10 +103,6 @@ export function toObject (v) {
|
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
|
|
100
|
-
const OPTIONS = {
|
|
101
|
-
maxBuffer: Infinity
|
|
102
|
-
}
|
|
103
|
-
|
|
104
106
|
/**
|
|
105
107
|
* @returns {Promise<string>}
|
|
106
108
|
*/
|
package/src/2/to-array.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
getRows,
|
|
3
3
|
toObject
|
|
4
4
|
} from './common.mjs'
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
* @returns {Array<Record<string, string | number>>}
|
|
9
9
|
*/
|
|
10
10
|
export default function toArray (value) {
|
|
11
|
-
const array =
|
|
11
|
+
const array = getRows(value)
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
14
|
array.map(toObject)
|
package/src/2/to-set.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
getRows,
|
|
3
3
|
toObject
|
|
4
4
|
} from './common.mjs'
|
|
5
5
|
|
|
@@ -20,7 +20,7 @@ function toMap (value) {
|
|
|
20
20
|
* @returns {Set<Map<string, string | number>>}
|
|
21
21
|
*/
|
|
22
22
|
export default function toSet (value) {
|
|
23
|
-
const array =
|
|
23
|
+
const array = getRows(value)
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
26
|
new Set(array.map(toMap))
|