@camjn/getargv 0.0.31 → 0.1.1
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/LICENSE.txt +1 -1
- package/dist/binding.d.ts +8 -2
- package/dist/binding.js +33 -41
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +3 -3
- package/dist/global.d.ts +4 -0
- package/dist/native.d.ts +4 -0
- package/dist/types.d.ts +53 -47
- package/package.json +16 -8
- package/dist/types.js +0 -2
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
BSD 3-Clause License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022, 2023, 2024 Camden Narzt <getargv@narzt.cam>. All rights reserved.
|
|
3
|
+
Copyright (c) 2022, 2023, 2024, 2025 Camden Narzt <getargv@narzt.cam>. All rights reserved.
|
|
4
4
|
|
|
5
5
|
Redistribution and use in source and binary forms, with or without
|
|
6
6
|
modification, are permitted provided that the following conditions are met:
|
package/dist/binding.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import { GetArgv } from './types';
|
|
1
|
+
import type { TextEncoding, TextDecoderOptions, GetArgv } from './types';
|
|
2
2
|
declare const addon: GetArgv;
|
|
3
|
-
export
|
|
3
|
+
export declare const PID_MAX: number;
|
|
4
|
+
export declare const ARG_MAX: number;
|
|
5
|
+
export declare const get_argv_of_pid: (pid: number, nuls: boolean, skip: number) => ArrayBuffer;
|
|
6
|
+
export declare const as_string: (pid: number, encoding: TextEncoding, nuls?: boolean, skip?: number, options?: TextDecoderOptions) => string;
|
|
7
|
+
export declare const get_argv_and_argc_of_pid: (pid: number) => Array<ArrayBuffer>;
|
|
8
|
+
export declare const as_array: (pid: number, encoding: TextEncoding, options?: TextDecoderOptions) => Array<string>;
|
|
9
|
+
export default addon;
|
package/dist/binding.js
CHANGED
|
@@ -1,47 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
// Node 23+ can experimentally import native .node modules with NODE_OPTIONS=--experimental-addon-modules
|
|
2
|
+
// import native_addon from '../build/Release/getargv_native.node';
|
|
3
|
+
// const addon: GetArgv = native_addon;
|
|
4
|
+
import { createRequire } from 'module';
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
2
6
|
const addon = require('../build/Release/getargv_native.node');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
function validate_args(target) {
|
|
8
|
+
return function (...args) {
|
|
9
|
+
if (arguments.length == 0)
|
|
10
|
+
throw new TypeError('The "pid" argument must be specified');
|
|
11
|
+
if (arguments.length == 1)
|
|
12
|
+
throw new TypeError('The "encoding" argument must be specified');
|
|
13
|
+
const [pid, encoding] = arguments;
|
|
14
|
+
if (typeof pid !== "number") {
|
|
15
|
+
throw new TypeError('The "pid" argument must be a number');
|
|
16
|
+
}
|
|
17
|
+
if (typeof encoding !== "string") {
|
|
18
|
+
throw new TypeError(`The "encoding" argument must be a string, is a: ${typeof encoding}`);
|
|
19
|
+
}
|
|
20
|
+
return target.apply(this, args);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
addon.as_string = validate_args(function (pid, encoding, nuls = false, skip = 0, options) {
|
|
19
24
|
const decoder = new TextDecoder(encoding, options);
|
|
20
|
-
const array = addon.get_argv_of_pid(pid, nuls
|
|
25
|
+
const array = addon.get_argv_of_pid(pid, nuls, skip);
|
|
21
26
|
return decoder.decode(array);
|
|
22
|
-
};
|
|
23
|
-
addon.as_array = function
|
|
24
|
-
switch (arguments.length) {
|
|
25
|
-
case 0: throw new TypeError('The "pid" argument must be specified');
|
|
26
|
-
case 1: throw new TypeError('The "encoding" argument must be specified');
|
|
27
|
-
case 2:
|
|
28
|
-
case 3: break;
|
|
29
|
-
default: throw new TypeError('Too many arguments were specified');
|
|
30
|
-
}
|
|
31
|
-
if (typeof pid !== "number") {
|
|
32
|
-
throw new TypeError('The "pid" argument must be a number');
|
|
33
|
-
}
|
|
34
|
-
if (typeof encoding !== "string") {
|
|
35
|
-
throw new TypeError(`The "encoding" argument must be a string, is a: ${typeof encoding}`);
|
|
36
|
-
}
|
|
27
|
+
});
|
|
28
|
+
addon.as_array = validate_args(function (pid, encoding, options) {
|
|
37
29
|
const decoder = new TextDecoder(encoding, options);
|
|
38
30
|
const array = addon.get_argv_and_argc_of_pid(pid);
|
|
39
31
|
return array.map(b => decoder.decode(b));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
});
|
|
33
|
+
export const PID_MAX = addon.PID_MAX;
|
|
34
|
+
export const ARG_MAX = addon.ARG_MAX;
|
|
35
|
+
export const get_argv_of_pid = addon.get_argv_of_pid;
|
|
36
|
+
export const as_string = addon.as_string;
|
|
37
|
+
export const get_argv_and_argc_of_pid = addon.get_argv_and_argc_of_pid;
|
|
38
|
+
export const as_array = addon.as_array;
|
|
39
|
+
export default addon;
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
declare function exit(msg: string): void;
|
|
1
|
+
export {};
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const { get_argv_of_pid } = require('./binding');
|
|
1
|
+
import { get_argv_of_pid } from './binding';
|
|
3
2
|
function exit(msg) {
|
|
4
3
|
console.error(msg);
|
|
5
4
|
process.exitCode = -1;
|
|
@@ -27,7 +26,8 @@ else {
|
|
|
27
26
|
}
|
|
28
27
|
if (process.exitCode == undefined) {
|
|
29
28
|
const args = get_argv_of_pid(pid, !keep_nuls, skip);
|
|
30
|
-
|
|
29
|
+
const u8a = new Uint8Array(args);
|
|
30
|
+
process.stdout.write(u8a);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
package/dist/global.d.ts
ADDED
package/dist/native.d.ts
ADDED
package/dist/types.d.ts
CHANGED
|
@@ -1,57 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
type
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
type
|
|
11
|
-
type
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
type
|
|
16
|
-
type
|
|
17
|
-
type
|
|
18
|
-
type
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
type
|
|
22
|
-
type
|
|
23
|
-
type
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
type
|
|
27
|
-
type
|
|
28
|
-
type
|
|
29
|
-
type windows_1258 = "cp1258" | "windows-1258" | "x-cp1258";
|
|
1
|
+
type utf_8 = "unicode-1-1-utf-8" | "unicode11utf8" | "unicode20utf8" | "utf-8" | "utf8" | "x-unicode20utf8";
|
|
2
|
+
type ibm866 = "866" | "cp866" | "csibm866" | "ibm866";
|
|
3
|
+
type iso_8859_2 = "csisolatin2" | "iso-8859-2" | "iso-ir-101" | "iso8859-2" | "iso88592" | "iso_8859-2" | "iso_8859-2:1987" | "l2"| "latin2";
|
|
4
|
+
type iso_8859_3 = "csisolatin3" | "iso-8859-3" | "iso-ir-109" | "iso8859-3" | "iso88593" | "iso_8859-3" | "iso_8859-3:1988" | "l3" | "latin3";
|
|
5
|
+
type iso_8859_4 = "csisolatin4" | "iso-8859-4" | "iso-ir-110" | "iso8859-4" | "iso88594" | "iso_8859-4" | "iso_8859-4:1988" | "l4" | "latin4";
|
|
6
|
+
type iso_8859_5 = "csisolatincyrillic" | "cyrillic" | "iso-8859-5" | "iso-ir-144" | "iso8859-5" | "iso88595" | "iso_8859-5" | "iso_8859-5:1988";
|
|
7
|
+
type iso_8859_6 = "arabic" | "asmo-708" | "csiso88596e" | "csiso88596i" | "csisolatinarabic" | "ecma-114" | "iso-8859-6" | "iso-8859-6-e" | "iso-8859-6-i" | "iso-ir-127" | "iso8859-6" | "iso88596" | "iso_8859-6" | "iso_8859-6:1987";
|
|
8
|
+
type iso_8859_7 = "csisolatingreek" | "ecma-118" | "elot_928" | "greek" | "greek8" | "iso-8859-7" | "iso-ir-126" | "iso8859-7" | "iso88597" | "iso_8859-7" | "iso_8859-7:1987" | "sun_eu_greek";
|
|
9
|
+
type iso_8859_8 = "csiso88598e" | "csisolatinhebrew" | "hebrew" | "iso-8859-8" | "iso-8859-8-e" | "iso-ir-138" | "iso8859-8" | "iso88598" | "iso_8859-8" | "iso_8859-8:1988" | "visual";
|
|
10
|
+
type iso_8859_8_i = "csiso88598i" | "iso-8859-8-i" | "logical";
|
|
11
|
+
type iso_8859_10 = "csisolatin6" | "iso-8859-10" | "iso-ir-157" | "iso8859-10" | "iso885910" | "l6" | "latin6";
|
|
12
|
+
type iso_8859_13 = "iso-8859-13" | "iso8859-13" | "iso885913";
|
|
13
|
+
type iso_8859_14 = "iso-8859-14" | "iso8859-14" | "iso885914";
|
|
14
|
+
type iso_8859_15 = "csisolatin9" | "iso-8859-15" | "iso8859-15" | "iso885915" | "iso_8859-15" | "latin9" | "l9"; // latin9 only in mdn
|
|
15
|
+
type iso_8859_16 = "iso-8859-16";
|
|
16
|
+
type koi8_r = "cskoi8r" | "koi" | "koi8" | "koi8-r" | "koi8_r";
|
|
17
|
+
type koi8_u = "koi8-ru" | "koi8-u";
|
|
18
|
+
type macintosh = "csmacintosh" | "mac" | "macintosh" | "x-mac-roman";
|
|
19
|
+
type windows_874 = "dos-874" | "iso-8859-11" | "iso8859-11" | "iso885911" | "tis-620" | "windows-874";
|
|
20
|
+
type windows_1250 = "cp1250" | "windows-1250" | "x-cp1250";
|
|
21
|
+
type windows_1251 = "cp1251" | "windows-1251" | "x-cp1251";
|
|
22
|
+
type windows_1252 = "ansi_x3.4-1968" | "ascii" | "cp1252" | "cp819" | "csisolatin1" | "ibm819" | "iso-8859-1" | "iso-ir-100" | "iso8859-1" | "iso88591" | "iso_8859-1" | "iso_8859-1:1987" | "l1" | "latin1" | "us-ascii" | "windows-1252" | "x-cp1252";
|
|
23
|
+
type windows_1253 = "cp1253" | "windows-1253" | "x-cp1253";
|
|
24
|
+
type windows_1254 = "cp1254" | "csisolatin5" | "iso-8859-9" | "iso-ir-148" | "iso8859-9" | "iso88599" | "iso_8859-9" | "iso_8859-9:1989" | "l5" | "latin5" | "windows-1254" | "x-cp1254";
|
|
25
|
+
type windows_1255 = "cp1255" | "windows-1255" | "x-cp1255";
|
|
26
|
+
type windows_1256 = "cp1256" | "windows-1256" | "x-cp1256";
|
|
27
|
+
type windows_1257 = "cp1257" | "windows-1257" | "x-cp1257";
|
|
28
|
+
type windows_1258 = "cp1258" | "windows-1258" | "x-cp1258";
|
|
30
29
|
type x_mac_cyrillic = "x-mac-cyrillic" | "x-mac-ukrainian";
|
|
31
|
-
type gbk
|
|
32
|
-
type gb18030
|
|
33
|
-
type
|
|
34
|
-
type
|
|
35
|
-
type
|
|
36
|
-
type
|
|
37
|
-
type
|
|
38
|
-
type
|
|
39
|
-
type
|
|
40
|
-
type
|
|
41
|
-
type utf_16le = "utf-16" | "utf-16le";
|
|
30
|
+
type gbk = "chinese" | "csgb2312" | "csiso58gb231280" | "gb2312" | "gb_2312" | "gb_2312-80" | "gbk" | "iso-ir-58" | "x-gbk";
|
|
31
|
+
type gb18030 = "gb18030";
|
|
32
|
+
type big5 = "big5" | "big5-hkscs" | "cn-big5" | "csbig5" | "x-x-big5";
|
|
33
|
+
type euc_jp = "cseucpkdfmtjapanese" | "euc-jp" | "x-euc-jp";
|
|
34
|
+
type iso_2022_jp = "csiso2022jp" | "iso-2022-jp";
|
|
35
|
+
type shift_jis = "csshiftjis" | "ms932" | "ms_kanji" | "shift-jis" | "shift_jis" | "sjis" | "windows-31j" | "x-sjis";
|
|
36
|
+
type euc_kr = "cseuckr" | "csksc56011987" | "euc-kr" | "iso-ir-149" | "korean" | "ks_c_5601-1987" | "ks_c_5601-1989" | "ksc5601" | "ksc_5601" | "windows-949";
|
|
37
|
+
type replacement = "csiso2022kr" | "hz-gb-2312" | "iso-2022-cn" | "iso-2022-cn-ext" | "iso-2022-kr" | "replacement";
|
|
38
|
+
type utf_16be = "unicodefffe" | "utf-16be";
|
|
39
|
+
type utf_16le = "csunicode" | "iso-10646-ucs-2" | "ucs-2" | "unicode" | "unicodefeff" | "utf-16" | "utf-16le";
|
|
42
40
|
type x_user_defined = "x-user-defined";
|
|
43
|
-
|
|
44
|
-
export type TextEncoding = utf_8 | ibm866 | iso_8859_2 | iso_8859_3 | iso_8859_4 | iso_8859_5 | iso_8859_6 | iso_8859_7 | iso_8859_8 |
|
|
41
|
+
|
|
42
|
+
export type TextEncoding = utf_8 | ibm866 | iso_8859_2 | iso_8859_3 | iso_8859_4 | iso_8859_5 | iso_8859_6 | iso_8859_7 | iso_8859_8 | iso_8859_8_i | iso_8859_10 | iso_8859_13 | iso_8859_14 | iso_8859_15 | iso_8859_16 | koi8_r | koi8_u | macintosh | windows_874 | windows_1250 | windows_1251 | windows_1252 | windows_1253 | windows_1254 | windows_1255 | windows_1256 | windows_1257 | windows_1258 | x_mac_cyrillic | gbk | gb18030 | big5 | euc_jp | iso_2022_jp | shift_jis | euc_kr | utf_16be | utf_16le | x_user_defined | replacement;
|
|
43
|
+
|
|
44
|
+
//export type TextEncoding = ConstructorParameters<typeof TextDecoder>[0];
|
|
45
45
|
export type TextDecoderOptions = ConstructorParameters<typeof TextDecoder>[1];
|
|
46
|
+
|
|
46
47
|
export interface GetArgv {
|
|
48
|
+
|
|
47
49
|
/** @constant
|
|
48
50
|
* @description the maximum value a pid may have on the system
|
|
49
51
|
*/
|
|
50
52
|
readonly PID_MAX: number;
|
|
53
|
+
|
|
51
54
|
/** @constant
|
|
52
55
|
* @description the maximum number of bytes that can be passed as args to a process (including env vars, etc)
|
|
53
56
|
*/
|
|
54
57
|
readonly ARG_MAX: number;
|
|
58
|
+
|
|
55
59
|
/**
|
|
56
60
|
* Gets the arguments of a process as an ArrayBuffer
|
|
57
61
|
* @param pid - The pid of the process whose arguments you want, must be between 0..{@link PID_MAX} inclusive.
|
|
@@ -62,7 +66,8 @@ export interface GetArgv {
|
|
|
62
66
|
* @throws {@link RangeError} if called with pid outside valid range: 0..{@link PID_MAX} inclusive.
|
|
63
67
|
* @throws {@link SystemError} if the underlying sysctl or parsing fails.
|
|
64
68
|
*/
|
|
65
|
-
get_argv_of_pid(pid: number, nuls: boolean, skip: number): ArrayBuffer
|
|
69
|
+
get_argv_of_pid(pid: number, nuls: boolean, skip: number): ArrayBuffer
|
|
70
|
+
|
|
66
71
|
/**
|
|
67
72
|
* Gets the arguments of a process as a string
|
|
68
73
|
* @param pid - The pid of the process whose arguments you want, must be between 0..{@link PID_MAX} inclusive.
|
|
@@ -75,7 +80,8 @@ export interface GetArgv {
|
|
|
75
80
|
* @throws {@link RangeError} if called with invalid encoding argument or pid outside valid range: 0..{@link PID_MAX} inclusive.
|
|
76
81
|
* @throws {@link SystemError} if the underlying sysctl or parsing fails.
|
|
77
82
|
*/
|
|
78
|
-
as_string(pid: number, encoding: TextEncoding, nuls?: boolean, skip?: number, options?: TextDecoderOptions): string
|
|
83
|
+
as_string(pid: number, encoding: TextEncoding, nuls?: boolean, skip?: number, options?: TextDecoderOptions): string
|
|
84
|
+
|
|
79
85
|
/**
|
|
80
86
|
* Gets the arguments of a process as an array of ArrayBuffers
|
|
81
87
|
* @param pid - The pid of the process whose arguments you want, must be between 0..{@link PID_MAX} inclusive.
|
|
@@ -84,7 +90,8 @@ export interface GetArgv {
|
|
|
84
90
|
* @throws {@link RangeError} if called with pid outside valid range: 0..{@link PID_MAX} inclusive.
|
|
85
91
|
* @throws {@link SystemError} if the underlying sysctl or parsing fails.
|
|
86
92
|
*/
|
|
87
|
-
get_argv_and_argc_of_pid(pid: number): Array<ArrayBuffer
|
|
93
|
+
get_argv_and_argc_of_pid(pid: number): Array<ArrayBuffer>
|
|
94
|
+
|
|
88
95
|
/**
|
|
89
96
|
* Gets the arguments of a process as an array of strings
|
|
90
97
|
* @param pid - The pid of the process whose arguments you want, must be between 0..{@link PID_MAX} inclusive.
|
|
@@ -95,6 +102,5 @@ export interface GetArgv {
|
|
|
95
102
|
* @throws {@link RangeError} if called with: invalid encoding argument, pid outside valid range: 0..{@link PID_MAX} inclusive.
|
|
96
103
|
* @throws {@link SystemError} if the underlying sysctl or parsing fails.
|
|
97
104
|
*/
|
|
98
|
-
as_array(pid: number, encoding: TextEncoding, options?: TextDecoderOptions): Array<string
|
|
105
|
+
as_array(pid: number, encoding: TextEncoding, options?: TextDecoderOptions): Array<string>
|
|
99
106
|
}
|
|
100
|
-
export {};
|
package/package.json
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
"bin": {
|
|
3
3
|
"getargv": "lib/cli.js"
|
|
4
4
|
},
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"node-gyp": "^11.2.0"
|
|
7
|
+
},
|
|
5
8
|
"devDependencies": {
|
|
6
|
-
"@
|
|
7
|
-
"
|
|
8
|
-
"typedoc
|
|
9
|
-
"
|
|
9
|
+
"@tsconfig/node20": "^20.0",
|
|
10
|
+
"@types/node": "^20.0",
|
|
11
|
+
"typedoc": "^0.28.0",
|
|
12
|
+
"typedoc-plugin-missing-exports": "^4.0.0",
|
|
13
|
+
"typescript": "^5.7"
|
|
10
14
|
},
|
|
11
15
|
"os": [
|
|
12
16
|
"darwin"
|
|
@@ -18,20 +22,24 @@
|
|
|
18
22
|
"name": "@camjn/getargv",
|
|
19
23
|
"homepage": "https://getargv.narzt.cam/",
|
|
20
24
|
"author": "Camden Narzt <getargv@narzt.cam>",
|
|
21
|
-
"version": "0.
|
|
25
|
+
"version": "0.1.1",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">20.0.0"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
22
30
|
"description": "This library allows you to query the arguments of other processes on macOS.",
|
|
23
31
|
"main": "dist/binding.js",
|
|
24
32
|
"scripts": {
|
|
25
|
-
"prebuild": "tsc",
|
|
33
|
+
"prebuild": "tsc && cp lib/*.d.ts dist/",
|
|
26
34
|
"build": "node-gyp configure build",
|
|
27
35
|
"rebuild": "node-gyp rebuild",
|
|
28
36
|
"pretest": "npm run build",
|
|
29
|
-
"test": "node --
|
|
37
|
+
"test": "node --test",
|
|
30
38
|
"prepack": "npm run build",
|
|
31
39
|
"precli": "npm run build",
|
|
32
40
|
"cli": "node dist/cli.js",
|
|
33
41
|
"preconsole": "npm run build",
|
|
34
|
-
"console": "node --
|
|
42
|
+
"console": "node --eval 'await import(\"./dist/binding.js\").then(e => global.GetArgv = e.default);' --interactive",
|
|
35
43
|
"docs": "typedoc --tsconfig $PWD/tsconfig.json lib/types.ts",
|
|
36
44
|
"start": "npm run console"
|
|
37
45
|
},
|
package/dist/types.js
DELETED