Gathering detailed insights and metrics for @rbxts/deep-equal
Gathering detailed insights and metrics for @rbxts/deep-equal
npm install @rbxts/deep-equal
Typescript
Module System
Node Version
NPM Version
72.4
Supply Chain
91.4
Quality
77.1
Maintenance
100
Vulnerability
98.9
License
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
593
Last Day
7
Last Week
39
Last Month
110
Last Year
593
6 Commits
1 Watching
2 Branches
1 Contributors
Latest Version
0.8.1
Package Id
@rbxts/deep-equal@0.8.1
Unpacked Size
89.99 kB
Size
18.94 kB
File Count
29
NPM Version
10.1.0
Node Version
20.9.0
Publised On
05 Oct 2024
Cumulative downloads
Total Downloads
Last day
-41.7%
7
Compared to previous day
Last week
30%
39
Compared to previous week
Last month
-35.7%
110
Compared to previous month
Last year
0%
593
Compared to previous year
18
Recursive comparator for ROBLOX projects.
1import { deepEqual } from "@rbxts/deep-equal"; 2 3const result = deepEqual([1,2,3], [1,2,4]); 4warn(result);
Install deep-equal
with your preferred package manager.
1npm install @rbxts/deep-equal
1pnpm add @rbxts/deep-equal
1yarn add @rbxts/deep-equal
deep-equal is an implementation of the common recrusive comparator, but for roblox projects.
Since roblox tables
are typically compared by reference, utilizing deep-equal allows you
to compare them by nested values, and get specific failure data on where the comparison failed.
deep-equal is also able to differentiate between arrays and non-array tables, so your comparisons on two arrays can be more array specific.
[!NOTE] deep-equal is built to primarily be used as an implementor of deep equal algorithms for other assertion libraries, or more complex validation systems.
That's why failures return an object of specific failure data, instead of throwing an error.
1deepEqual("daymon", "michael"); 2/** 3 * { 4 * failType: FailureType.DIFFERENT_VALUES, 5 * leftValue: "daymon", 6 * rightValue: "michael" 7 * } 8 */
1deepEqual(5, 10); 2/** 3 * { 4 * failType: FailureType.DIFFERENT_VALUES, 5 * leftValue: 5, 6 * rightValue: 10 7 * } 8 */
1deepEqual(true, false); 2/** 3 * { 4 * failType: FailureType.DIFFERENT_VALUES, 5 * leftValue: true, 6 * rightValue: false 7 * } 8 */
1deepEqual(5, "5"); 2/** 3 * { 4 * failType: FailureType.DIFFERENT_TYPES, 5 * leftValue: 5, 6 * leftType: "number", 7 * rightValue: "5", 8 * rightType: "string" 9 * } 10 */
1deepEqual([1,2,3], [1,2,4]); 2/** 3 * { 4 * failType: FailureType.MISSING_ARRAY_VALUE, 5 * leftValue: [1,2,3], 6 * rightValue: [1,2,4], 7 * leftMissing: [4], 8 * rightMissing: [3] 9 * } 10 */
1deepEqual({ 2 name: "daymon", 3 age: 100 4}, { 5 name: "daymon", 6 age: 200 7}); 8/** 9 * { 10 * failType: FailureType.DIFFERENT_VALUES, 11 * leftValue: 100, 12 * rightValue: 200, 13 * path: "age" 14 * } 15 */
1deepEqual({ 2 name: "daymon", 3 cars: ["Tesla", "Civic"] 4}, { 5 name: "daymon", 6 cars: ["Tesla"] 7}); 8/** 9 * { 10 * failType: FailureType.MISSING_ARRAY_VALUE, 11 * leftValue: ["Tesla", "Civic"], 12 * rightValue: ["Tesla"], 13 * rightMissing: ["Civic"], 14 * path: "cars" 15 * } 16 */
1deepEqual({ 2 name: "daymon", 3 age: 100 4}, { 5 name: "daymon", 6}); 7/** 8 * { 9 * failType: FailureType.MISSING, 10 * leftValue: 100, 11 * rightValue: undefined, 12 * path: "age" 13 * } 14 */
1deepEqual({ 2 name: "daymon", 3 details: { 4 origin: { 5 city: "Kansas City", 6 state: "MO" 7 } 8 } 9}, { 10 name: "daymon", 11 details: { 12 origin: { 13 city: "Kansas City", 14 state: "KS" 15 } 16 } 17}); 18/** 19 * { 20 * failType: FailureType.DIFFERENT_VALUES, 21 * leftValue: "MO", 22 * rightValue: "KS", 23 * path: "details.origin.state" 24 * } 25 */
Roblox types can be split into two categories: ones that are compared by value and ones that are compared by reference.
1deepEqual(new Vector3(1,2,3), new Vector3(1,2,3)); // pass 2 3deepEqual(new Vector3(1,2,3), new Vector3(2,4,6)); 4/** 5 * { 6 * failType: FailureType.DIFFERENT_VALUES, 7 * leftValue: (1, 2, 3), 8 * rightValue: (2, 4, 6) 9 * } 10 */
[!TIP] You can provide custom comparators for comparing reference types.
1deepEqual(new OverlapParams(), new OverlapParams()); 2/** 3 * { 4 * failType: FailureType.DIFFERENT_REFERENCE, 5 * leftValue: "OverlapParams{...}", 6 * rightValue: "OverlapParams{...}" 7 * } 8 */
You can optionally provide some configuration in your calls to deep-equal, or set them at the global level.
An array of types to ignore.
1deepEqual({ 2 name: "daymon", 3 position: new Vector3(1,2,3), 4 cars: ["Tesla", "Civic"] 5}, { 6 name: "daymon", 7 position: new Vector3(2,4,6), 8 cars: ["Tesla"] 9}, { ignore: ["Vector3"] }); 10/** 11 * { 12 * failType: FailureType.MISSING_ARRAY_VALUE, 13 * leftValue: ["Tesla", "Civic"], 14 * rightValue: ["Tesla"], 15 * rightMissing: ["Civic"], 16 * path: "cars" 17 * } 18 */
When the left
or right
is any of these types,
it will be skipped; effectively "ignoring" it for the
purposes of checking if two objects are equal.
An array of types to only compare by reference.
1deepEqual(new Vector3(1,2,3), new Vector3(2,4,6), { referenceOnly: ["Vector3"] }); 2/** 3 * { 4 * failType: FailureType.DIFFERENT_REFERENCE, 5 * leftValue: (1, 2, 3), 6 * rightValue: (2, 4, 6) 7 * } 8 */
Some roblox types are compared by value instead of reference. Adding
said types to this array will instead force them to be compared by reference instead, with a FailureType.DIFFERENT_REFERENCE
failure type attached.
Check for missing values from the right in comparison to the left.
1deepEqual({ 2 name: "daymon", 3 cars: ["Tesla", "Civic"] 4}, { 5 name: "daymon", 6 cars: ["Tesla", "Mustang"] 7}, { rightMissing: true }); 8/** 9 * { 10 * failType: FailureType.MISSING_ARRAY_VALUE, 11 * leftValue: ["Tesla", "Civic"], 12 * rightValue: ["Tesla", "Mustang"], 13 * leftMissing: ["Mustang"] 14 * rightMissing: ["Civic"], 15 * path: "cars" 16 * } 17 */
Since this setting is enabled by default, its usage is primarily for disabling it when you only want to check certain values- while ignoring others.
1deepEqual({ 2 name: "daymon", 3 details: { 4 origin: { 5 city: "Kansas City", 6 state: "MO" 7 } 8 } 9}, { 10 details: { 11 origin: { 12 state: "KS" 13 } 14 } 15}, { rightMissing: false }); 16/** 17 * { 18 * failType: FailureType.DIFFERENT_VALUES, 19 * leftValue: "MO", 20 * rightValue: "KS", 21 * path: "details.origin.state" 22 * } 23 */
Compares arrays in order instead of by missing.
1deepEqual({ 2 name: "daymon", 3 cars: ["Tesla", "Civic"] 4}, { 5 name: "daymon", 6 cars: ["Tesla"] 7}); 8/** 9 * { 10 * failType: FailureType.DIFFERENT_VALUES, 11 * leftValue: "Civic", 12 * rightValue: undefined, 13 * path: "cars.[1]" 14 * } 15 */
By default, arrays are looked at in their entirety and a
list of elements missing from either (depending on if
checkRightMissing
is enabled) is provided.
You can enable inOrder
to instead throw at the first failure,
with data pertaining to where the failure occurred.
Useful when working with arrays of complex types, or when you want to assert that an array is "exactly in order".
If you want to provide your own behavior for certain types (like reference types) or override existing behavior, you can provide your own methods for certain types.
1const checkInstance: CustomChecker<"Instance"> = (config, left, right) => { 2 if(left.Name === right.Name) return Option.none(); 3 return return Option.some({ 4 failType: FailureType.DIFFERENT_VALUES, 5 leftValue: left.Name, 6 rightValue: right.Name, 7 leftMissing: [], 8 rightMissing: [], 9 leftType: "Instance", 10 rightType: "Instance", 11 path: "", 12 }); 13}; 14 15deepEqual(Workspace.Part1, Workspace.Part2, { 16 customCheckers: { 17 Instance: checkInstance 18 } 19});
![TIP] By default, deep-equal provides some checkers for certain reference types out of the box that are already attached to the default config!
Take a look at the checkers directory to see which types, and further examples of custom comparators.
If you have configurations you want to apply to all usages of deep-equal, you can set a global configuration.
1setDefaultDeepEqualConfig({ 2 customCheckers: { 3 Instance: checkInstance 4 } 5}); 6 7deepEqual(Workspace.Part1, Workspace.Part2); // inherits the default config
[!WARNING]
setDefaultDeepEqualConfig
replaces any previously set default config- it does not merge them.You can use the provided
getDefaultDeepEqualConfig
andmergeConfigs
functions to add this behavior on your own, but the default config is not intended to be used in such a way- which is why this behavior is not provided out of the box.
Instance
comparators.If you're interested in contributing to deep-equal, give the CONTRIBUTING doc a read.
No vulnerabilities found.
No security vulnerabilities found.