node-ipconfig 1.0.0 → 1.0.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 +21 -21
- package/README.md +146 -135
- package/docs/API.md +134 -134
- package/package.json +5 -2
- package/src/command.js +117 -117
- package/src/format.js +119 -119
- package/src/index.cjs +64 -64
- package/src/index.d.cts +92 -92
- package/src/index.d.ts +132 -132
- package/src/index.js +244 -244
- package/src/parser.cjs +3 -3
- package/src/parser.d.cts +6 -6
- package/src/parser.d.ts +2 -2
- package/src/parser.js +182 -182
package/src/command.js
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
|
|
3
|
-
export class IpconfigError extends Error {
|
|
4
|
-
constructor(
|
|
5
|
-
message,
|
|
6
|
-
{
|
|
7
|
-
code = "EIPCONFIG",
|
|
8
|
-
cause,
|
|
9
|
-
command,
|
|
10
|
-
stdout = "",
|
|
11
|
-
stderr = "",
|
|
12
|
-
exitCode,
|
|
13
|
-
} = {},
|
|
14
|
-
) {
|
|
15
|
-
super(message, { cause });
|
|
16
|
-
this.name = "IpconfigError";
|
|
17
|
-
this.code = code;
|
|
18
|
-
if (command) this.command = command;
|
|
19
|
-
this.stdout = stdout;
|
|
20
|
-
this.stderr = stderr;
|
|
21
|
-
if (exitCode !== undefined) this.exitCode = exitCode;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function createRunner({
|
|
26
|
-
platform = process.platform,
|
|
27
|
-
exec = execFile,
|
|
28
|
-
} = {}) {
|
|
29
|
-
return function run(args = [], options = {}) {
|
|
30
|
-
if (platform !== "win32")
|
|
31
|
-
return Promise.reject(
|
|
32
|
-
new IpconfigError("node-ipconfig is supported only on Windows.", {
|
|
33
|
-
code: "ENOTSUP",
|
|
34
|
-
}),
|
|
35
|
-
);
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
const command = ["ipconfig.exe", ...args];
|
|
38
|
-
const finish = (error, stdout = "", stderr = "") => {
|
|
39
|
-
const output =
|
|
40
|
-
typeof stdout === "string"
|
|
41
|
-
? stdout
|
|
42
|
-
: stdout?.toString(options.encoding ?? "utf8");
|
|
43
|
-
const errorOutput =
|
|
44
|
-
typeof stderr === "string"
|
|
45
|
-
? stderr
|
|
46
|
-
: stderr?.toString(options.encoding ?? "utf8");
|
|
47
|
-
const exitCode = Number.isInteger(error?.code)
|
|
48
|
-
? error.code
|
|
49
|
-
: error
|
|
50
|
-
? null
|
|
51
|
-
: 0;
|
|
52
|
-
// Some ipconfig commands emit useful localized diagnostics and a non-zero exit status.
|
|
53
|
-
if (
|
|
54
|
-
error &&
|
|
55
|
-
!output?.trim() &&
|
|
56
|
-
!(options.rawResult && Number.isInteger(error.code))
|
|
57
|
-
) {
|
|
58
|
-
const code =
|
|
59
|
-
error.code === "EACCES" || error.code === "EPERM"
|
|
60
|
-
? "EACCES"
|
|
61
|
-
: error.code === "ENOENT"
|
|
62
|
-
? "ENOENT"
|
|
63
|
-
: error.code === "ETIMEDOUT" ||
|
|
64
|
-
(error.killed && options.timeout)
|
|
65
|
-
? "ETIMEDOUT"
|
|
66
|
-
: error.name === "AbortError"
|
|
67
|
-
? "ABORT_ERR"
|
|
68
|
-
: (error.code ?? "EIPCONFIG");
|
|
69
|
-
const message =
|
|
70
|
-
code === "EACCES"
|
|
71
|
-
? "Permission denied while running ipconfig; retry from an appropriately authorized terminal."
|
|
72
|
-
: code === "ENOENT"
|
|
73
|
-
? "ipconfig.exe could not be found on PATH."
|
|
74
|
-
: code === "ETIMEDOUT"
|
|
75
|
-
? "ipconfig timed out; increase timeout or retry."
|
|
76
|
-
: code === "ABORT_ERR"
|
|
77
|
-
? "ipconfig was aborted."
|
|
78
|
-
: `ipconfig failed${error.message ? `: ${error.message}` : ""}`;
|
|
79
|
-
reject(
|
|
80
|
-
new IpconfigError(message, {
|
|
81
|
-
code,
|
|
82
|
-
cause: error,
|
|
83
|
-
command,
|
|
84
|
-
stdout: output ?? "",
|
|
85
|
-
stderr: errorOutput ?? "",
|
|
86
|
-
exitCode: exitCode ?? undefined,
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (options.rawResult)
|
|
92
|
-
resolve({
|
|
93
|
-
stdout: output ?? "",
|
|
94
|
-
stderr: errorOutput ?? "",
|
|
95
|
-
exitCode: exitCode ?? 0,
|
|
96
|
-
});
|
|
97
|
-
else resolve((output ?? "") || (errorOutput ?? ""));
|
|
98
|
-
};
|
|
99
|
-
try {
|
|
100
|
-
exec(
|
|
101
|
-
"ipconfig.exe",
|
|
102
|
-
args,
|
|
103
|
-
{
|
|
104
|
-
windowsHide: true,
|
|
105
|
-
encoding: options.encoding ?? "utf8",
|
|
106
|
-
timeout: options.timeout ?? 15000,
|
|
107
|
-
maxBuffer: 4 * 1024 * 1024,
|
|
108
|
-
...(options.signal ? { signal: options.signal } : {}),
|
|
109
|
-
},
|
|
110
|
-
finish,
|
|
111
|
-
);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
finish(error);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
}
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
export class IpconfigError extends Error {
|
|
4
|
+
constructor(
|
|
5
|
+
message,
|
|
6
|
+
{
|
|
7
|
+
code = "EIPCONFIG",
|
|
8
|
+
cause,
|
|
9
|
+
command,
|
|
10
|
+
stdout = "",
|
|
11
|
+
stderr = "",
|
|
12
|
+
exitCode,
|
|
13
|
+
} = {},
|
|
14
|
+
) {
|
|
15
|
+
super(message, { cause });
|
|
16
|
+
this.name = "IpconfigError";
|
|
17
|
+
this.code = code;
|
|
18
|
+
if (command) this.command = command;
|
|
19
|
+
this.stdout = stdout;
|
|
20
|
+
this.stderr = stderr;
|
|
21
|
+
if (exitCode !== undefined) this.exitCode = exitCode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createRunner({
|
|
26
|
+
platform = process.platform,
|
|
27
|
+
exec = execFile,
|
|
28
|
+
} = {}) {
|
|
29
|
+
return function run(args = [], options = {}) {
|
|
30
|
+
if (platform !== "win32")
|
|
31
|
+
return Promise.reject(
|
|
32
|
+
new IpconfigError("node-ipconfig is supported only on Windows.", {
|
|
33
|
+
code: "ENOTSUP",
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const command = ["ipconfig.exe", ...args];
|
|
38
|
+
const finish = (error, stdout = "", stderr = "") => {
|
|
39
|
+
const output =
|
|
40
|
+
typeof stdout === "string"
|
|
41
|
+
? stdout
|
|
42
|
+
: stdout?.toString(options.encoding ?? "utf8");
|
|
43
|
+
const errorOutput =
|
|
44
|
+
typeof stderr === "string"
|
|
45
|
+
? stderr
|
|
46
|
+
: stderr?.toString(options.encoding ?? "utf8");
|
|
47
|
+
const exitCode = Number.isInteger(error?.code)
|
|
48
|
+
? error.code
|
|
49
|
+
: error
|
|
50
|
+
? null
|
|
51
|
+
: 0;
|
|
52
|
+
// Some ipconfig commands emit useful localized diagnostics and a non-zero exit status.
|
|
53
|
+
if (
|
|
54
|
+
error &&
|
|
55
|
+
!output?.trim() &&
|
|
56
|
+
!(options.rawResult && Number.isInteger(error.code))
|
|
57
|
+
) {
|
|
58
|
+
const code =
|
|
59
|
+
error.code === "EACCES" || error.code === "EPERM"
|
|
60
|
+
? "EACCES"
|
|
61
|
+
: error.code === "ENOENT"
|
|
62
|
+
? "ENOENT"
|
|
63
|
+
: error.code === "ETIMEDOUT" ||
|
|
64
|
+
(error.killed && options.timeout)
|
|
65
|
+
? "ETIMEDOUT"
|
|
66
|
+
: error.name === "AbortError"
|
|
67
|
+
? "ABORT_ERR"
|
|
68
|
+
: (error.code ?? "EIPCONFIG");
|
|
69
|
+
const message =
|
|
70
|
+
code === "EACCES"
|
|
71
|
+
? "Permission denied while running ipconfig; retry from an appropriately authorized terminal."
|
|
72
|
+
: code === "ENOENT"
|
|
73
|
+
? "ipconfig.exe could not be found on PATH."
|
|
74
|
+
: code === "ETIMEDOUT"
|
|
75
|
+
? "ipconfig timed out; increase timeout or retry."
|
|
76
|
+
: code === "ABORT_ERR"
|
|
77
|
+
? "ipconfig was aborted."
|
|
78
|
+
: `ipconfig failed${error.message ? `: ${error.message}` : ""}`;
|
|
79
|
+
reject(
|
|
80
|
+
new IpconfigError(message, {
|
|
81
|
+
code,
|
|
82
|
+
cause: error,
|
|
83
|
+
command,
|
|
84
|
+
stdout: output ?? "",
|
|
85
|
+
stderr: errorOutput ?? "",
|
|
86
|
+
exitCode: exitCode ?? undefined,
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (options.rawResult)
|
|
92
|
+
resolve({
|
|
93
|
+
stdout: output ?? "",
|
|
94
|
+
stderr: errorOutput ?? "",
|
|
95
|
+
exitCode: exitCode ?? 0,
|
|
96
|
+
});
|
|
97
|
+
else resolve((output ?? "") || (errorOutput ?? ""));
|
|
98
|
+
};
|
|
99
|
+
try {
|
|
100
|
+
exec(
|
|
101
|
+
"ipconfig.exe",
|
|
102
|
+
args,
|
|
103
|
+
{
|
|
104
|
+
windowsHide: true,
|
|
105
|
+
encoding: options.encoding ?? "utf8",
|
|
106
|
+
timeout: options.timeout ?? 15000,
|
|
107
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
108
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
109
|
+
},
|
|
110
|
+
finish,
|
|
111
|
+
);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
finish(error);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
}
|
package/src/format.js
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
const FORMATS = new Set(["json", "xml", "yaml", "csv", "ndjson"]);
|
|
2
|
-
|
|
3
|
-
function escapeXml(value) {
|
|
4
|
-
return String(value).replace(
|
|
5
|
-
/[<>&"']/g,
|
|
6
|
-
(character) =>
|
|
7
|
-
({
|
|
8
|
-
"<": "<",
|
|
9
|
-
">": ">",
|
|
10
|
-
"&": "&",
|
|
11
|
-
'"': """,
|
|
12
|
-
"'": "'",
|
|
13
|
-
})[character],
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function xmlNode(name, value) {
|
|
18
|
-
if (Array.isArray(value))
|
|
19
|
-
return `<${name}>${value.map((item) => xmlNode("item", item)).join("")}</${name}>`;
|
|
20
|
-
if (value && typeof value === "object")
|
|
21
|
-
return `<${name}>${Object.entries(value)
|
|
22
|
-
.map(([key, item]) =>
|
|
23
|
-
xmlNode(key.replace(/[^A-Za-z0-9_.-]/g, "_") || "field", item),
|
|
24
|
-
)
|
|
25
|
-
.join("")}</${name}>`;
|
|
26
|
-
return `<${name}>${escapeXml(value ?? "")}</${name}>`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function yamlScalar(value) {
|
|
30
|
-
if (value === null) return "null";
|
|
31
|
-
if (typeof value === "string") return JSON.stringify(value);
|
|
32
|
-
return String(value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function yamlLines(value, indent = 0) {
|
|
36
|
-
const pad = " ".repeat(indent);
|
|
37
|
-
if (Array.isArray(value))
|
|
38
|
-
return value.length
|
|
39
|
-
? value.flatMap((item) => {
|
|
40
|
-
if (item && typeof item === "object") {
|
|
41
|
-
const lines = yamlLines(item, indent + 2);
|
|
42
|
-
return [
|
|
43
|
-
`${pad}- ${lines[0]?.trimStart() ?? "{}"}`,
|
|
44
|
-
...lines.slice(1),
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
return [`${pad}- ${yamlScalar(item)}`];
|
|
48
|
-
})
|
|
49
|
-
: [`${pad}[]`];
|
|
50
|
-
if (value && typeof value === "object") {
|
|
51
|
-
const entries = Object.entries(value);
|
|
52
|
-
return entries.length
|
|
53
|
-
? entries.flatMap(([key, item]) => {
|
|
54
|
-
const safeKey = /^[A-Za-z_][\w.-]*$/.test(key)
|
|
55
|
-
? key
|
|
56
|
-
: JSON.stringify(key);
|
|
57
|
-
if (item && typeof item === "object")
|
|
58
|
-
return [`${pad}${safeKey}:`, ...yamlLines(item, indent + 2)];
|
|
59
|
-
return [`${pad}${safeKey}: ${yamlScalar(item)}`];
|
|
60
|
-
})
|
|
61
|
-
: [`${pad}{}`];
|
|
62
|
-
}
|
|
63
|
-
return [`${pad}${yamlScalar(value)}`];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function csvCell(value) {
|
|
67
|
-
const text =
|
|
68
|
-
value == null
|
|
69
|
-
? ""
|
|
70
|
-
: typeof value === "object"
|
|
71
|
-
? JSON.stringify(value)
|
|
72
|
-
: String(value);
|
|
73
|
-
return /[",\r\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Format a parsed configuration as JSON data or a serialized JSON, XML, YAML, CSV, or NDJSON document. */
|
|
77
|
-
export function formatConfig(config, format = "json") {
|
|
78
|
-
if (!FORMATS.has(format))
|
|
79
|
-
throw new TypeError(
|
|
80
|
-
`Unsupported format: ${format}. Choose json, xml, yaml, csv, or ndjson.`,
|
|
81
|
-
);
|
|
82
|
-
if (format === "json") return config;
|
|
83
|
-
if (format === "xml")
|
|
84
|
-
return `<?xml version="1.0" encoding="UTF-8"?>\n${xmlNode("config", config)}`;
|
|
85
|
-
if (format === "yaml") return `${yamlLines(config).join("\n")}\n`;
|
|
86
|
-
if (format === "ndjson")
|
|
87
|
-
return `${config.adapters.map((adapter) => JSON.stringify({ ...(config.hostname ? { hostname: config.hostname } : {}), adapter })).join("\n")}${config.adapters.length ? "\n" : ""}`;
|
|
88
|
-
const columns = [
|
|
89
|
-
"name",
|
|
90
|
-
"type",
|
|
91
|
-
"description",
|
|
92
|
-
"macAddress",
|
|
93
|
-
"ipv4",
|
|
94
|
-
"ipv6",
|
|
95
|
-
"subnetMask",
|
|
96
|
-
"ipv4PrefixLength",
|
|
97
|
-
"defaultGateways",
|
|
98
|
-
"dnsServers",
|
|
99
|
-
"dhcpEnabled",
|
|
100
|
-
"autoconfigurationEnabled",
|
|
101
|
-
"dhcpServer",
|
|
102
|
-
"leaseObtained",
|
|
103
|
-
"leaseExpires",
|
|
104
|
-
"connectionSpecificDnsSuffix",
|
|
105
|
-
"mediaState",
|
|
106
|
-
"addresses",
|
|
107
|
-
"fields",
|
|
108
|
-
];
|
|
109
|
-
return (
|
|
110
|
-
[
|
|
111
|
-
columns.join(","),
|
|
112
|
-
...config.adapters.map((adapter) =>
|
|
113
|
-
columns.map((key) => csvCell(adapter[key])).join(","),
|
|
114
|
-
),
|
|
115
|
-
].join("\r\n") + "\r\n"
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export const CONFIG_FORMATS = Object.freeze([...FORMATS]);
|
|
1
|
+
const FORMATS = new Set(["json", "xml", "yaml", "csv", "ndjson"]);
|
|
2
|
+
|
|
3
|
+
function escapeXml(value) {
|
|
4
|
+
return String(value).replace(
|
|
5
|
+
/[<>&"']/g,
|
|
6
|
+
(character) =>
|
|
7
|
+
({
|
|
8
|
+
"<": "<",
|
|
9
|
+
">": ">",
|
|
10
|
+
"&": "&",
|
|
11
|
+
'"': """,
|
|
12
|
+
"'": "'",
|
|
13
|
+
})[character],
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function xmlNode(name, value) {
|
|
18
|
+
if (Array.isArray(value))
|
|
19
|
+
return `<${name}>${value.map((item) => xmlNode("item", item)).join("")}</${name}>`;
|
|
20
|
+
if (value && typeof value === "object")
|
|
21
|
+
return `<${name}>${Object.entries(value)
|
|
22
|
+
.map(([key, item]) =>
|
|
23
|
+
xmlNode(key.replace(/[^A-Za-z0-9_.-]/g, "_") || "field", item),
|
|
24
|
+
)
|
|
25
|
+
.join("")}</${name}>`;
|
|
26
|
+
return `<${name}>${escapeXml(value ?? "")}</${name}>`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function yamlScalar(value) {
|
|
30
|
+
if (value === null) return "null";
|
|
31
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
32
|
+
return String(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function yamlLines(value, indent = 0) {
|
|
36
|
+
const pad = " ".repeat(indent);
|
|
37
|
+
if (Array.isArray(value))
|
|
38
|
+
return value.length
|
|
39
|
+
? value.flatMap((item) => {
|
|
40
|
+
if (item && typeof item === "object") {
|
|
41
|
+
const lines = yamlLines(item, indent + 2);
|
|
42
|
+
return [
|
|
43
|
+
`${pad}- ${lines[0]?.trimStart() ?? "{}"}`,
|
|
44
|
+
...lines.slice(1),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
return [`${pad}- ${yamlScalar(item)}`];
|
|
48
|
+
})
|
|
49
|
+
: [`${pad}[]`];
|
|
50
|
+
if (value && typeof value === "object") {
|
|
51
|
+
const entries = Object.entries(value);
|
|
52
|
+
return entries.length
|
|
53
|
+
? entries.flatMap(([key, item]) => {
|
|
54
|
+
const safeKey = /^[A-Za-z_][\w.-]*$/.test(key)
|
|
55
|
+
? key
|
|
56
|
+
: JSON.stringify(key);
|
|
57
|
+
if (item && typeof item === "object")
|
|
58
|
+
return [`${pad}${safeKey}:`, ...yamlLines(item, indent + 2)];
|
|
59
|
+
return [`${pad}${safeKey}: ${yamlScalar(item)}`];
|
|
60
|
+
})
|
|
61
|
+
: [`${pad}{}`];
|
|
62
|
+
}
|
|
63
|
+
return [`${pad}${yamlScalar(value)}`];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function csvCell(value) {
|
|
67
|
+
const text =
|
|
68
|
+
value == null
|
|
69
|
+
? ""
|
|
70
|
+
: typeof value === "object"
|
|
71
|
+
? JSON.stringify(value)
|
|
72
|
+
: String(value);
|
|
73
|
+
return /[",\r\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Format a parsed configuration as JSON data or a serialized JSON, XML, YAML, CSV, or NDJSON document. */
|
|
77
|
+
export function formatConfig(config, format = "json") {
|
|
78
|
+
if (!FORMATS.has(format))
|
|
79
|
+
throw new TypeError(
|
|
80
|
+
`Unsupported format: ${format}. Choose json, xml, yaml, csv, or ndjson.`,
|
|
81
|
+
);
|
|
82
|
+
if (format === "json") return config;
|
|
83
|
+
if (format === "xml")
|
|
84
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n${xmlNode("config", config)}`;
|
|
85
|
+
if (format === "yaml") return `${yamlLines(config).join("\n")}\n`;
|
|
86
|
+
if (format === "ndjson")
|
|
87
|
+
return `${config.adapters.map((adapter) => JSON.stringify({ ...(config.hostname ? { hostname: config.hostname } : {}), adapter })).join("\n")}${config.adapters.length ? "\n" : ""}`;
|
|
88
|
+
const columns = [
|
|
89
|
+
"name",
|
|
90
|
+
"type",
|
|
91
|
+
"description",
|
|
92
|
+
"macAddress",
|
|
93
|
+
"ipv4",
|
|
94
|
+
"ipv6",
|
|
95
|
+
"subnetMask",
|
|
96
|
+
"ipv4PrefixLength",
|
|
97
|
+
"defaultGateways",
|
|
98
|
+
"dnsServers",
|
|
99
|
+
"dhcpEnabled",
|
|
100
|
+
"autoconfigurationEnabled",
|
|
101
|
+
"dhcpServer",
|
|
102
|
+
"leaseObtained",
|
|
103
|
+
"leaseExpires",
|
|
104
|
+
"connectionSpecificDnsSuffix",
|
|
105
|
+
"mediaState",
|
|
106
|
+
"addresses",
|
|
107
|
+
"fields",
|
|
108
|
+
];
|
|
109
|
+
return (
|
|
110
|
+
[
|
|
111
|
+
columns.join(","),
|
|
112
|
+
...config.adapters.map((adapter) =>
|
|
113
|
+
columns.map((key) => csvCell(adapter[key])).join(","),
|
|
114
|
+
),
|
|
115
|
+
].join("\r\n") + "\r\n"
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const CONFIG_FORMATS = Object.freeze([...FORMATS]);
|
package/src/index.cjs
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const load = () => import("./index.js");
|
|
3
|
-
const api = {};
|
|
4
|
-
for (const name of [
|
|
5
|
-
"execute",
|
|
6
|
-
"getRawOutput",
|
|
7
|
-
"getConfig",
|
|
8
|
-
"getAdapters",
|
|
9
|
-
"getAdapter",
|
|
10
|
-
"getIPv4",
|
|
11
|
-
"getIPv6",
|
|
12
|
-
"getDefaultGateway",
|
|
13
|
-
"getDnsServers",
|
|
14
|
-
"getMacAddresses",
|
|
15
|
-
"getHostname",
|
|
16
|
-
"release",
|
|
17
|
-
"renew",
|
|
18
|
-
"flushDns",
|
|
19
|
-
"getDnsCache",
|
|
20
|
-
"displayDns",
|
|
21
|
-
"registerDns",
|
|
22
|
-
"showClassId",
|
|
23
|
-
"setClassId",
|
|
24
|
-
"showClassId6",
|
|
25
|
-
"setClassId6",
|
|
26
|
-
]) {
|
|
27
|
-
api[name] = (...args) =>
|
|
28
|
-
load().then(({ ipconfig }) => ipconfig[name](...args));
|
|
29
|
-
}
|
|
30
|
-
api.parseIpconfig = (...args) =>
|
|
31
|
-
load().then(({ parseIpconfig }) => parseIpconfig(...args));
|
|
32
|
-
api.createIpconfig = (options) => {
|
|
33
|
-
const instance = {};
|
|
34
|
-
for (const name of [
|
|
35
|
-
"execute",
|
|
36
|
-
"getRawOutput",
|
|
37
|
-
"getConfig",
|
|
38
|
-
"getAdapters",
|
|
39
|
-
"getAdapter",
|
|
40
|
-
"getIPv4",
|
|
41
|
-
"getIPv6",
|
|
42
|
-
"getDefaultGateway",
|
|
43
|
-
"getDnsServers",
|
|
44
|
-
"getMacAddresses",
|
|
45
|
-
"getHostname",
|
|
46
|
-
"release",
|
|
47
|
-
"renew",
|
|
48
|
-
"flushDns",
|
|
49
|
-
"getDnsCache",
|
|
50
|
-
"displayDns",
|
|
51
|
-
"registerDns",
|
|
52
|
-
"showClassId",
|
|
53
|
-
"setClassId",
|
|
54
|
-
"showClassId6",
|
|
55
|
-
"setClassId6",
|
|
56
|
-
]) {
|
|
57
|
-
instance[name] = (...args) =>
|
|
58
|
-
load().then(({ createIpconfig }) =>
|
|
59
|
-
createIpconfig(options)[name](...args),
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return instance;
|
|
63
|
-
};
|
|
64
|
-
module.exports = api;
|
|
1
|
+
"use strict";
|
|
2
|
+
const load = () => import("./index.js");
|
|
3
|
+
const api = {};
|
|
4
|
+
for (const name of [
|
|
5
|
+
"execute",
|
|
6
|
+
"getRawOutput",
|
|
7
|
+
"getConfig",
|
|
8
|
+
"getAdapters",
|
|
9
|
+
"getAdapter",
|
|
10
|
+
"getIPv4",
|
|
11
|
+
"getIPv6",
|
|
12
|
+
"getDefaultGateway",
|
|
13
|
+
"getDnsServers",
|
|
14
|
+
"getMacAddresses",
|
|
15
|
+
"getHostname",
|
|
16
|
+
"release",
|
|
17
|
+
"renew",
|
|
18
|
+
"flushDns",
|
|
19
|
+
"getDnsCache",
|
|
20
|
+
"displayDns",
|
|
21
|
+
"registerDns",
|
|
22
|
+
"showClassId",
|
|
23
|
+
"setClassId",
|
|
24
|
+
"showClassId6",
|
|
25
|
+
"setClassId6",
|
|
26
|
+
]) {
|
|
27
|
+
api[name] = (...args) =>
|
|
28
|
+
load().then(({ ipconfig }) => ipconfig[name](...args));
|
|
29
|
+
}
|
|
30
|
+
api.parseIpconfig = (...args) =>
|
|
31
|
+
load().then(({ parseIpconfig }) => parseIpconfig(...args));
|
|
32
|
+
api.createIpconfig = (options) => {
|
|
33
|
+
const instance = {};
|
|
34
|
+
for (const name of [
|
|
35
|
+
"execute",
|
|
36
|
+
"getRawOutput",
|
|
37
|
+
"getConfig",
|
|
38
|
+
"getAdapters",
|
|
39
|
+
"getAdapter",
|
|
40
|
+
"getIPv4",
|
|
41
|
+
"getIPv6",
|
|
42
|
+
"getDefaultGateway",
|
|
43
|
+
"getDnsServers",
|
|
44
|
+
"getMacAddresses",
|
|
45
|
+
"getHostname",
|
|
46
|
+
"release",
|
|
47
|
+
"renew",
|
|
48
|
+
"flushDns",
|
|
49
|
+
"getDnsCache",
|
|
50
|
+
"displayDns",
|
|
51
|
+
"registerDns",
|
|
52
|
+
"showClassId",
|
|
53
|
+
"setClassId",
|
|
54
|
+
"showClassId6",
|
|
55
|
+
"setClassId6",
|
|
56
|
+
]) {
|
|
57
|
+
instance[name] = (...args) =>
|
|
58
|
+
load().then(({ createIpconfig }) =>
|
|
59
|
+
createIpconfig(options)[name](...args),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return instance;
|
|
63
|
+
};
|
|
64
|
+
module.exports = api;
|