New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@foxglove/message-definition

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@foxglove/message-definition - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

25

dist/compare.js

@@ -5,2 +5,25 @@ "use strict";

/**
* Deep equality comparison of two DefaultValue values. Two default values are considered equal
* if they are both arrays and all their elements are equal, or if they are both primitives and
* equal.
*
* @param lhs Left-hand side of the comparison.
* @param rhs Right-hand side of the comparison.
* @returns True if the two default values are equal, false otherwise.
*/
function defaultValuesEqual(lhs, rhs) {
if (Array.isArray(lhs) && Array.isArray(rhs)) {
if (lhs.length !== rhs.length) {
return false;
}
for (let i = 0; i < lhs.length; i++) {
if (lhs[i] !== rhs[i]) {
return false;
}
}
return true;
}
return lhs === rhs;
}
/**
* Compares two MessageDefinitionField objects for equality. Two fields are considered equal if all

@@ -24,3 +47,3 @@ * their properties are equal. Assumes default values (False) for boolean properties that are undefined.

lhs.arrayUpperBound === rhs.arrayUpperBound &&
lhs.defaultValue === rhs.defaultValue);
defaultValuesEqual(lhs.defaultValue, rhs.defaultValue));
}

@@ -27,0 +50,0 @@ exports.isMsgDefFieldEqual = isMsgDefFieldEqual;

2

package.json
{
"name": "@foxglove/message-definition",
"version": "0.3.0",
"version": "0.3.1",
"description": "Defines common types for message definition schemas (ROS .msg, Protobuf, FlatBuffers, IDL, PX4 ULog, JSON Schema, etc)",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -63,2 +63,38 @@ import { isMsgDefEqual } from "./compare";

});
it("should return true for matching array default values", () => {
const definition1: MessageDefinition = {
name: "definition",
definitions: [
{ type: "string", isArray: true, name: "field1", defaultValue: ["a", "b"] },
{ type: "number", isArray: true, name: "field2", defaultValue: [1, 2] },
],
};
const definition2: MessageDefinition = {
name: "definition",
definitions: [
{ type: "string", isArray: true, name: "field1", defaultValue: ["a", "b"] },
{ type: "number", isArray: true, name: "field2", defaultValue: [1, 2] },
],
};
expect(isMsgDefEqual(definition1, definition2)).toBe(true);
});
it("should return false for different array default values", () => {
const definition1: MessageDefinition = {
name: "definition",
definitions: [
{ type: "string", isArray: true, name: "field1", defaultValue: ["a", "b"] },
{ type: "number", isArray: true, name: "field2", defaultValue: [1, 2] },
],
};
const definition2: MessageDefinition = {
name: "definition",
definitions: [
{ type: "string", isArray: true, name: "field1", defaultValue: ["a", "b"] },
{ type: "number", isArray: true, name: "field2", defaultValue: [1, 3] },
],
};
expect(isMsgDefEqual(definition1, definition2)).toBe(false);
});
});

@@ -1,4 +0,28 @@

import { MessageDefinition, MessageDefinitionField } from "./types";
import { DefaultValue, MessageDefinition, MessageDefinitionField } from "./types";
/**
* Deep equality comparison of two DefaultValue values. Two default values are considered equal
* if they are both arrays and all their elements are equal, or if they are both primitives and
* equal.
*
* @param lhs Left-hand side of the comparison.
* @param rhs Right-hand side of the comparison.
* @returns True if the two default values are equal, false otherwise.
*/
function defaultValuesEqual(lhs: DefaultValue, rhs: DefaultValue): boolean {
if (Array.isArray(lhs) && Array.isArray(rhs)) {
if (lhs.length !== rhs.length) {
return false;
}
for (let i = 0; i < lhs.length; i++) {
if (lhs[i] !== rhs[i]) {
return false;
}
}
return true;
}
return lhs === rhs;
}
/**
* Compares two MessageDefinitionField objects for equality. Two fields are considered equal if all

@@ -26,3 +50,3 @@ * their properties are equal. Assumes default values (False) for boolean properties that are undefined.

lhs.arrayUpperBound === rhs.arrayUpperBound &&
lhs.defaultValue === rhs.defaultValue
defaultValuesEqual(lhs.defaultValue, rhs.defaultValue)
);

@@ -29,0 +53,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc