matterbridge 3.0.1 → 3.0.2-dev-20250508-7214e17
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/CHANGELOG.md +25 -0
- package/README.md +1 -1
- package/dist/cli.js +2 -37
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +15 -328
- package/dist/index.js +2 -28
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -2
- package/dist/matter/types.js +0 -2
- package/dist/matterbridge.js +80 -747
- package/dist/matterbridgeAccessoryPlatform.js +0 -34
- package/dist/matterbridgeBehaviors.js +109 -48
- package/dist/matterbridgeDeviceTypes.js +12 -431
- package/dist/matterbridgeDynamicPlatform.js +0 -34
- package/dist/matterbridgeEndpoint.js +13 -814
- package/dist/matterbridgeEndpointHelpers.js +29 -148
- package/dist/matterbridgePlatform.js +7 -225
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +3 -264
- package/dist/roboticVacuumCleaner.js +87 -0
- package/dist/shelly.js +6 -146
- package/dist/storage/export.js +0 -1
- package/dist/update.js +1 -53
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/{parameter.js → commandLine.js} +1 -54
- package/dist/utils/copyDirectory.js +1 -37
- package/dist/utils/createZip.js +2 -42
- package/dist/utils/deepCopy.js +8 -43
- package/dist/utils/deepEqual.js +7 -69
- package/dist/utils/export.js +2 -2
- package/dist/utils/hex.js +27 -0
- package/dist/utils/isvalid.js +3 -93
- package/dist/utils/network.js +7 -78
- package/dist/utils/wait.js +5 -48
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- package/dist/cli.d.ts +0 -29
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster/export.d.ts +0 -2
- package/dist/cluster/export.d.ts.map +0 -1
- package/dist/cluster/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -27
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -114
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/frontend.d.ts +0 -240
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/index.d.ts +0 -35
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -433
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -40
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1166
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -494
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -40
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -956
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2706
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -294
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -187
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -273
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -92
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -32
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -61
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -32
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -38
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -31
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -53
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/export.d.ts +0 -10
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -95
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -69
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/parameter.d.ts +0 -58
- package/dist/utils/parameter.d.ts.map +0 -1
- package/dist/utils/parameter.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -43
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
|
@@ -1,31 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* This file contains the deepEqual function.
|
|
3
|
-
*
|
|
4
|
-
* @file parameter.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* Checks if a command-line parameter is present.
|
|
25
|
-
*
|
|
26
|
-
* @param {string} name - The name of the parameter to check.
|
|
27
|
-
* @returns {boolean} True if the parameter is present, otherwise false.
|
|
28
|
-
*/
|
|
1
|
+
import { isValidNumber } from './export.js';
|
|
29
2
|
export function hasParameter(name) {
|
|
30
3
|
const commandArguments = process.argv.slice(2);
|
|
31
4
|
let markerIncluded = commandArguments.includes(`-${name}`);
|
|
@@ -33,13 +6,6 @@ export function hasParameter(name) {
|
|
|
33
6
|
markerIncluded = commandArguments.includes(`--${name}`);
|
|
34
7
|
return markerIncluded;
|
|
35
8
|
}
|
|
36
|
-
import { isValidNumber } from './export.js';
|
|
37
|
-
/**
|
|
38
|
-
* Retrieves the value of a command-line parameter.
|
|
39
|
-
*
|
|
40
|
-
* @param {string} name - The name of the parameter to retrieve.
|
|
41
|
-
* @returns {string | undefined} The value of the parameter, or undefined if not found.
|
|
42
|
-
*/
|
|
43
9
|
export function getParameter(name) {
|
|
44
10
|
const commandArguments = process.argv.slice(2);
|
|
45
11
|
let markerIndex = commandArguments.indexOf(`-${name}`);
|
|
@@ -49,12 +15,6 @@ export function getParameter(name) {
|
|
|
49
15
|
return undefined;
|
|
50
16
|
return commandArguments[markerIndex + 1];
|
|
51
17
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Retrieves the value of a command-line parameter as an integer.
|
|
54
|
-
*
|
|
55
|
-
* @param {string} name - The name of the parameter to retrieve.
|
|
56
|
-
* @returns {number | undefined} The integer value of the parameter, or undefined if not found or invalid.
|
|
57
|
-
*/
|
|
58
18
|
export function getIntParameter(name) {
|
|
59
19
|
const value = getParameter(name);
|
|
60
20
|
if (value === undefined)
|
|
@@ -64,12 +24,6 @@ export function getIntParameter(name) {
|
|
|
64
24
|
return undefined;
|
|
65
25
|
return intValue;
|
|
66
26
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Retrieves the value of a command-line parameter as a number array.
|
|
69
|
-
*
|
|
70
|
-
* @param {string} name - The name of the parameter to retrieve.
|
|
71
|
-
* @returns {number[] | undefined} An array of string values for the parameter, or undefined if not found.
|
|
72
|
-
*/
|
|
73
27
|
export function getIntArrayParameter(name) {
|
|
74
28
|
const commandArguments = process.argv.slice(2);
|
|
75
29
|
let markerIndex = commandArguments.indexOf(`--${name}`);
|
|
@@ -87,12 +41,6 @@ export function getIntArrayParameter(name) {
|
|
|
87
41
|
return undefined;
|
|
88
42
|
return intValues;
|
|
89
43
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Retrieves the value of a command-line parameter as a string array.
|
|
92
|
-
*
|
|
93
|
-
* @param {string} name - The name of the parameter to retrieve.
|
|
94
|
-
* @returns {string[] | undefined} An array of string values for the parameter, or undefined if not found.
|
|
95
|
-
*/
|
|
96
44
|
export function getStringArrayParameter(name) {
|
|
97
45
|
const commandArguments = process.argv.slice(2);
|
|
98
46
|
let markerIndex = commandArguments.indexOf(`--${name}`);
|
|
@@ -108,4 +56,3 @@ export function getStringArrayParameter(name) {
|
|
|
108
56
|
return undefined;
|
|
109
57
|
return values;
|
|
110
58
|
}
|
|
111
|
-
//# sourceMappingURL=parameter.js.map
|
|
@@ -1,54 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the copyDirectory function.
|
|
3
|
-
*
|
|
4
|
-
* @file copyDirectory.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
// AnsiLogger module
|
|
24
1
|
import { AnsiLogger } from '../logger/export.js';
|
|
25
|
-
/**
|
|
26
|
-
* Copies a directory and all its subdirectories and files to a new location.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} srcDir - The path to the source directory.
|
|
29
|
-
* @param {string} destDir - The path to the destination directory.
|
|
30
|
-
* @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
|
|
31
|
-
* @throws {Error} - Throws an error if the copy operation fails.
|
|
32
|
-
*/
|
|
33
2
|
export async function copyDirectory(srcDir, destDir) {
|
|
34
|
-
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4
|
|
3
|
+
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4, logLevel: "info" });
|
|
35
4
|
const fs = await import('node:fs').then((mod) => mod.promises);
|
|
36
5
|
const path = await import('node:path');
|
|
37
6
|
log.debug(`copyDirectory: copying directory from ${srcDir} to ${destDir}`);
|
|
38
7
|
try {
|
|
39
|
-
// Create destination directory if it doesn't exist
|
|
40
8
|
await fs.mkdir(destDir, { recursive: true });
|
|
41
|
-
// Read contents of the source directory
|
|
42
9
|
const entries = await fs.readdir(srcDir, { withFileTypes: true });
|
|
43
10
|
for (const entry of entries) {
|
|
44
11
|
const srcPath = path.join(srcDir, entry.name);
|
|
45
12
|
const destPath = path.join(destDir, entry.name);
|
|
46
13
|
if (entry.isDirectory()) {
|
|
47
|
-
// Recursive call if entry is a directory
|
|
48
14
|
await copyDirectory(srcPath, destPath);
|
|
49
15
|
}
|
|
50
16
|
else if (entry.isFile()) {
|
|
51
|
-
// Copy file if entry is a file
|
|
52
17
|
await fs.copyFile(srcPath, destPath);
|
|
53
18
|
}
|
|
54
19
|
}
|
|
@@ -59,4 +24,3 @@ export async function copyDirectory(srcDir, destDir) {
|
|
|
59
24
|
return false;
|
|
60
25
|
}
|
|
61
26
|
}
|
|
62
|
-
//# sourceMappingURL=copyDirectory.js.map
|
package/dist/utils/createZip.js
CHANGED
|
@@ -1,43 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the createZip function.
|
|
3
|
-
*
|
|
4
|
-
* @file createZip.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
// AnsiLogger module
|
|
24
1
|
import { AnsiLogger } from '../logger/export.js';
|
|
25
|
-
/**
|
|
26
|
-
* Creates a ZIP archive from the specified source pattern or directory and writes it to the specified output path.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} outputPath - The path where the output ZIP file will be written.
|
|
29
|
-
* @param {string[]} sourcePaths - The source pattern or directory to be zipped (use path.join for sourcePath).
|
|
30
|
-
* @returns {Promise<number>} - A promise that resolves to the total number of bytes written to the ZIP file.
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* This function uses the `archiver` library to create a ZIP archive. It sets the compression level to 9 (maximum compression).
|
|
34
|
-
* The function ensures that the output file is properly closed after the archiving process is complete.
|
|
35
|
-
* It logs the progress and the total number of bytes written to the console.
|
|
36
|
-
*
|
|
37
|
-
* This function uses the `glob` library to match files based on the source pattern (internally converted in posix).
|
|
38
|
-
*/
|
|
39
2
|
export async function createZip(outputPath, ...sourcePaths) {
|
|
40
|
-
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4
|
|
3
|
+
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4, logLevel: "info" });
|
|
41
4
|
const { default: archiver } = await import('archiver');
|
|
42
5
|
const { glob } = await import('glob');
|
|
43
6
|
const { createWriteStream, statSync } = await import('node:fs');
|
|
@@ -46,7 +9,7 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
46
9
|
return new Promise((resolve, reject) => {
|
|
47
10
|
const output = createWriteStream(outputPath);
|
|
48
11
|
const archive = archiver('zip', {
|
|
49
|
-
zlib: { level: 9 },
|
|
12
|
+
zlib: { level: 9 },
|
|
50
13
|
});
|
|
51
14
|
output.on('close', () => {
|
|
52
15
|
log.debug(`archive ${outputPath} closed with ${archive.pointer()} total bytes`);
|
|
@@ -73,7 +36,6 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
73
36
|
});
|
|
74
37
|
archive.pipe(output);
|
|
75
38
|
for (const sourcePath of sourcePaths) {
|
|
76
|
-
// Check if the sourcePath is a file or directory
|
|
77
39
|
let stats;
|
|
78
40
|
try {
|
|
79
41
|
stats = statSync(sourcePath);
|
|
@@ -101,9 +63,7 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
101
63
|
archive.directory(sourcePath, path.basename(sourcePath));
|
|
102
64
|
}
|
|
103
65
|
}
|
|
104
|
-
// Finalize the archive (i.e., we are done appending files but streams have to finish yet)
|
|
105
66
|
log.debug(`finalizing archive ${outputPath}...`);
|
|
106
67
|
archive.finalize().catch(reject);
|
|
107
68
|
});
|
|
108
69
|
}
|
|
109
|
-
//# sourceMappingURL=createZip.js.map
|
package/dist/utils/deepCopy.js
CHANGED
|
@@ -1,67 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the deepCopy function.
|
|
3
|
-
*
|
|
4
|
-
* @file deepCopy.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* Creates a deep copy of the given value.
|
|
25
|
-
*
|
|
26
|
-
* @template T - The type of the value being copied.
|
|
27
|
-
* @param {T} value - The value to be copied.
|
|
28
|
-
* @returns {T} - The deep copy of the value.
|
|
29
|
-
*/
|
|
30
1
|
export function deepCopy(value) {
|
|
31
2
|
if (typeof value !== 'object' || value === null) {
|
|
32
|
-
// Primitive value (string, number, boolean, bigint, undefined, symbol) or null
|
|
33
3
|
return value;
|
|
34
4
|
}
|
|
35
5
|
else if (Array.isArray(value)) {
|
|
36
|
-
// Array: Recursively copy each element
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
6
|
return value.map((item) => deepCopy(item));
|
|
39
7
|
}
|
|
40
8
|
else if (value instanceof Date) {
|
|
41
|
-
// Date objects
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
9
|
return new Date(value.getTime());
|
|
44
10
|
}
|
|
11
|
+
else if (value instanceof RegExp) {
|
|
12
|
+
return new RegExp(value.source, value.flags);
|
|
13
|
+
}
|
|
45
14
|
else if (value instanceof Map) {
|
|
46
|
-
// Maps
|
|
47
15
|
const mapCopy = new Map();
|
|
48
|
-
value.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
16
|
+
for (const [origKey, origVal] of value.entries()) {
|
|
17
|
+
const clonedKey = deepCopy(origKey);
|
|
18
|
+
const clonedVal = deepCopy(origVal);
|
|
19
|
+
mapCopy.set(clonedKey, clonedVal);
|
|
20
|
+
}
|
|
52
21
|
return mapCopy;
|
|
53
22
|
}
|
|
54
23
|
else if (value instanceof Set) {
|
|
55
|
-
// Sets
|
|
56
24
|
const setCopy = new Set();
|
|
57
25
|
value.forEach((item) => {
|
|
58
26
|
setCopy.add(deepCopy(item));
|
|
59
27
|
});
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
28
|
return setCopy;
|
|
62
29
|
}
|
|
63
30
|
else {
|
|
64
|
-
// Objects: Create a copy with the same prototype as the original
|
|
65
31
|
const proto = Object.getPrototypeOf(value);
|
|
66
32
|
const copy = Object.create(proto);
|
|
67
33
|
for (const key in value) {
|
|
@@ -72,4 +38,3 @@ export function deepCopy(value) {
|
|
|
72
38
|
return copy;
|
|
73
39
|
}
|
|
74
40
|
}
|
|
75
|
-
//# sourceMappingURL=deepCopy.js.map
|
package/dist/utils/deepEqual.js
CHANGED
|
@@ -1,80 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the deepEqual function.
|
|
3
|
-
*
|
|
4
|
-
* @file deepEqual.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
24
|
-
/**
|
|
25
|
-
* Performs a deep comparison between two values to determine if they are equivalent.
|
|
26
|
-
* This comparison includes primitive types, arrays, and objects, allowing for optional
|
|
27
|
-
* exclusion of specific properties from the comparison in objects.
|
|
28
|
-
*
|
|
29
|
-
* @param {any} a The first value to compare.
|
|
30
|
-
* @param {any} b The second value to compare.
|
|
31
|
-
* @param {string[]} [excludeProperties=[]] An array of property names to exclude from the comparison in objects.
|
|
32
|
-
* @returns {boolean} True if the values are deeply equal, excluding any specified properties; otherwise, false.
|
|
33
|
-
*
|
|
34
|
-
* Note: This function utilizes recursion for deep comparison of nested structures and includes a debugging
|
|
35
|
-
* mechanism that can be toggled on or off for detailed comparison logging. It is important to ensure that
|
|
36
|
-
* objects do not contain circular references when enabling debug logging to avoid infinite loops.
|
|
37
|
-
*
|
|
38
|
-
* Example usage:
|
|
39
|
-
* ```
|
|
40
|
-
* const obj1 = { a: 1, b: { c: 2 } };
|
|
41
|
-
* const obj2 = { a: 1, b: { c: 2 } };
|
|
42
|
-
* console.log(deepEqual(obj1, obj2)); // true
|
|
43
|
-
*
|
|
44
|
-
* const arr1 = [1, 2, [3, 4]];
|
|
45
|
-
* const arr2 = [1, 2, [3, 4]];
|
|
46
|
-
* console.log(deepEqual(arr1, arr2)); // true
|
|
47
|
-
*
|
|
48
|
-
* const obj3 = { a: 1, b: { c: 2, d: 3 } };
|
|
49
|
-
* const obj4 = { a: 1, b: { c: 2 } };
|
|
50
|
-
* console.log(deepEqual(obj3, obj4, ['d'])); // true, excluding property 'd' from comparison
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
1
|
export function deepEqual(a, b, excludeProperties = []) {
|
|
54
|
-
// Toggle debugging on or off easily
|
|
55
|
-
const debug = false;
|
|
56
|
-
// Helper function for conditional logging
|
|
57
2
|
const debugLog = (...messages) => {
|
|
58
|
-
if (debug) {
|
|
59
|
-
// eslint-disable-next-line no-console
|
|
60
|
-
console.log(...messages);
|
|
61
|
-
}
|
|
62
3
|
};
|
|
63
|
-
// If both are the same instance, return true (handles primitives and same object references)
|
|
64
4
|
if (a === b) {
|
|
65
5
|
return true;
|
|
66
6
|
}
|
|
67
|
-
// If types are different, return false
|
|
68
7
|
if (typeof a !== typeof b) {
|
|
69
8
|
debugLog(`deepEqual false for typeof a: ${typeof a} typeof b: ${typeof b}`);
|
|
70
9
|
return false;
|
|
71
10
|
}
|
|
72
|
-
// If one of them is null (and we know they are not equal from the first check), return false
|
|
73
11
|
if (a == null || b == null) {
|
|
74
12
|
debugLog('deepEqual false for == null');
|
|
75
13
|
return false;
|
|
76
14
|
}
|
|
77
|
-
|
|
15
|
+
if (a instanceof Date && b instanceof Date) {
|
|
16
|
+
return a.getTime() === b.getTime();
|
|
17
|
+
}
|
|
18
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
19
|
+
return a.source === b.source && a.flags === b.flags;
|
|
20
|
+
}
|
|
78
21
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
79
22
|
if (a.length !== b.length) {
|
|
80
23
|
debugLog(`deepEqual false for array a.length(${a.length}) !== b.length(${b.length})`);
|
|
@@ -90,31 +33,26 @@ export function deepEqual(a, b, excludeProperties = []) {
|
|
|
90
33
|
}
|
|
91
34
|
return true;
|
|
92
35
|
}
|
|
93
|
-
// Handle Objects (and exclude null, functions, and arrays)
|
|
94
36
|
if (typeof a === 'object' && typeof b === 'object') {
|
|
95
37
|
const aProps = Object.getOwnPropertyNames(a).filter((prop) => !excludeProperties.includes(prop));
|
|
96
38
|
const bProps = Object.getOwnPropertyNames(b).filter((prop) => !excludeProperties.includes(prop));
|
|
97
|
-
// If their property lengths are different, they're different objects
|
|
98
39
|
if (aProps.length !== bProps.length) {
|
|
99
40
|
debugLog(`deepEqual false for aProps.length(${aProps.length}) !== bProps.length(${bProps.length})`);
|
|
100
41
|
debugLog(`- aProps.length(${aProps.length}):`, aProps);
|
|
101
42
|
debugLog(`- bProps.length(${bProps.length}):`, bProps);
|
|
102
43
|
return false;
|
|
103
44
|
}
|
|
104
|
-
// Check each property in 'a' to see if it's in 'b' and if it's equal (deep check)
|
|
105
45
|
for (const prop of aProps) {
|
|
106
46
|
if (!Object.prototype.hasOwnProperty.call(b, prop)) {
|
|
107
47
|
debugLog(`deepEqual false for !b.hasOwnProperty(${prop})`);
|
|
108
48
|
return false;
|
|
109
49
|
}
|
|
110
50
|
if (!deepEqual(a[prop], b[prop], excludeProperties)) {
|
|
111
|
-
debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`
|
|
51
|
+
debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`);
|
|
112
52
|
return false;
|
|
113
53
|
}
|
|
114
54
|
}
|
|
115
55
|
return true;
|
|
116
56
|
}
|
|
117
|
-
// If none of the above, the objects are not equal
|
|
118
57
|
return false;
|
|
119
58
|
}
|
|
120
|
-
//# sourceMappingURL=deepEqual.js.map
|
package/dist/utils/export.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './network.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './commandLine.js';
|
|
3
3
|
export * from './isvalid.js';
|
|
4
4
|
export * from './colorUtils.js';
|
|
5
5
|
export * from './deepCopy.js';
|
|
@@ -7,4 +7,4 @@ export * from './deepEqual.js';
|
|
|
7
7
|
export * from './copyDirectory.js';
|
|
8
8
|
export * from './createZip.js';
|
|
9
9
|
export * from './wait.js';
|
|
10
|
-
|
|
10
|
+
export * from './hex.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function bufferToHex(buffer) {
|
|
2
|
+
if (!(buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer))) {
|
|
3
|
+
throw new TypeError('Expected input to be an ArrayBuffer or ArrayBufferView');
|
|
4
|
+
}
|
|
5
|
+
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
6
|
+
return Array.from(bytes)
|
|
7
|
+
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
8
|
+
.join('');
|
|
9
|
+
}
|
|
10
|
+
export function hexToBuffer(hex) {
|
|
11
|
+
if (typeof hex !== 'string') {
|
|
12
|
+
throw new TypeError('Expected a string for hex input');
|
|
13
|
+
}
|
|
14
|
+
const cleaned = hex.trim();
|
|
15
|
+
if (cleaned.length % 2 !== 0) {
|
|
16
|
+
throw new Error('Invalid hex string length, must be even');
|
|
17
|
+
}
|
|
18
|
+
if (!/^[0-9a-fA-F]*$/.test(cleaned)) {
|
|
19
|
+
throw new Error('Invalid hex string, contains non-hex characters');
|
|
20
|
+
}
|
|
21
|
+
const length = cleaned.length / 2;
|
|
22
|
+
const result = new Uint8Array(length);
|
|
23
|
+
for (let i = 0; i < length; i++) {
|
|
24
|
+
result[i] = parseInt(cleaned.substr(i * 2, 2), 16);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
package/dist/utils/isvalid.js
CHANGED
|
@@ -1,44 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the deepEqual function.
|
|
3
|
-
*
|
|
4
|
-
* @file isvalid.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* Checks if a given string is a valid IPv4 address.
|
|
25
|
-
*
|
|
26
|
-
* @param {string} ipv4Address - The string to be checked.
|
|
27
|
-
* @returns {boolean} - Returns true if the string is a valid IPv4 address, otherwise returns false.
|
|
28
|
-
*/
|
|
29
1
|
export function isValidIpv4Address(ipv4Address) {
|
|
30
2
|
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
31
3
|
return ipv4Regex.test(ipv4Address);
|
|
32
4
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Checks if a value is a valid number within the specified range.
|
|
35
|
-
*
|
|
36
|
-
* @param {any} value - The value to be checked.
|
|
37
|
-
* @param {number} min - The minimum value allowed (optional).
|
|
38
|
-
* @param {number} max - The maximum value allowed (optional).
|
|
39
|
-
* @returns {boolean} Returns true if the value is a valid number within the specified range, otherwise false.
|
|
40
|
-
*/
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
5
|
export function isValidNumber(value, min, max) {
|
|
43
6
|
if (value === undefined || value === null || typeof value !== 'number' || Number.isNaN(value) || !Number.isFinite(value))
|
|
44
7
|
return false;
|
|
@@ -48,25 +11,9 @@ export function isValidNumber(value, min, max) {
|
|
|
48
11
|
return false;
|
|
49
12
|
return true;
|
|
50
13
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Checks if a value is a valid boolean.
|
|
53
|
-
*
|
|
54
|
-
* @param {any} value - The value to be checked.
|
|
55
|
-
* @returns {boolean} `true` if the value is a valid boolean, `false` otherwise.
|
|
56
|
-
*/
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
14
|
export function isValidBoolean(value) {
|
|
59
15
|
return value !== undefined && value !== null && typeof value === 'boolean';
|
|
60
16
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Checks if a value is a valid string.
|
|
63
|
-
*
|
|
64
|
-
* @param {any} value - The value to be checked.
|
|
65
|
-
* @param {number} minLength - The min string length (optional).
|
|
66
|
-
* @param {number} maxLength - The max string length (optional).
|
|
67
|
-
* @returns {boolean} A boolean indicating whether the value is a valid string.
|
|
68
|
-
*/
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
17
|
export function isValidString(value, minLength, maxLength) {
|
|
71
18
|
if (value === undefined || value === null || typeof value !== 'string')
|
|
72
19
|
return false;
|
|
@@ -76,15 +23,9 @@ export function isValidString(value, minLength, maxLength) {
|
|
|
76
23
|
return false;
|
|
77
24
|
return true;
|
|
78
25
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* @param {any} value - The value to be checked.
|
|
83
|
-
* @param {number} minLength - The min number of keys (optional).
|
|
84
|
-
* @param {number} maxLength - The max number of keys (optional).
|
|
85
|
-
* @returns {boolean} A boolean indicating whether the value is a valid object.
|
|
86
|
-
*/
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
export function isValidRegExp(value) {
|
|
27
|
+
return value !== undefined && value !== null && value instanceof RegExp;
|
|
28
|
+
}
|
|
88
29
|
export function isValidObject(value, minLength, maxLength) {
|
|
89
30
|
if (value === undefined || value === null || typeof value !== 'object' || Array.isArray(value))
|
|
90
31
|
return false;
|
|
@@ -95,15 +36,6 @@ export function isValidObject(value, minLength, maxLength) {
|
|
|
95
36
|
return false;
|
|
96
37
|
return true;
|
|
97
38
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Checks if a value is a valid array.
|
|
100
|
-
*
|
|
101
|
-
* @param {any} value - The value to be checked.
|
|
102
|
-
* @param {number} minLength - The min number of elements (optional).
|
|
103
|
-
* @param {number} maxLength - The max number of elements (optional).
|
|
104
|
-
* @returns {boolean} A boolean indicating whether the value is a valid array.
|
|
105
|
-
*/
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
39
|
export function isValidArray(value, minLength, maxLength) {
|
|
108
40
|
if (value === undefined || value === null || !Array.isArray(value))
|
|
109
41
|
return false;
|
|
@@ -113,33 +45,12 @@ export function isValidArray(value, minLength, maxLength) {
|
|
|
113
45
|
return false;
|
|
114
46
|
return true;
|
|
115
47
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Checks if the given value is null.
|
|
118
|
-
*
|
|
119
|
-
* @param {any} value - The value to check.
|
|
120
|
-
* @returns {boolean} `true` if the value is null, `false` otherwise.
|
|
121
|
-
*/
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
48
|
export function isValidNull(value) {
|
|
124
49
|
return value === null;
|
|
125
50
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Checks if a value is undefined.
|
|
128
|
-
*
|
|
129
|
-
* @param {any} value - The value to check.
|
|
130
|
-
* @returns {boolean} `true` if the value is undefined, `false` otherwise.
|
|
131
|
-
*/
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
133
51
|
export function isValidUndefined(value) {
|
|
134
52
|
return value === undefined;
|
|
135
53
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Converts a semantic version string like "6.11.0-1011-raspi" to a numeric version code.
|
|
138
|
-
* Format: major * 10000 + minor * 100 + patch
|
|
139
|
-
*
|
|
140
|
-
* @param {string} versionString The version string to parse
|
|
141
|
-
* @returns {number | undefined} A numeric version code or undefined if parsing fails
|
|
142
|
-
*/
|
|
143
54
|
export function parseVersionString(versionString) {
|
|
144
55
|
if (!isValidString(versionString))
|
|
145
56
|
return undefined;
|
|
@@ -156,4 +67,3 @@ export function parseVersionString(versionString) {
|
|
|
156
67
|
}
|
|
157
68
|
return major * 10000 + minor * 100 + patch;
|
|
158
69
|
}
|
|
159
|
-
//# sourceMappingURL=isvalid.js.map
|