Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

match-json

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

match-json - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

15

lib/match.js

@@ -31,7 +31,7 @@ "use strict";

case "array":
return compareArrays(value, expected);
return compareArrays(value, expected, partialMode);
case "map":
return compareObjects(value, mapToObject(expected));
return compareObjects(value, mapToObject(expected), partialMode);
case "set":
return compareArrays(value, Array.from(expected));
return compareArrays(value, Array.from(expected), partialMode);
default:

@@ -51,3 +51,3 @@ return false;

function compareArrays(array, expected, partialMode) {
if (!partialMode && array.length !== expected.length) return false;
if (array.length !== expected.length) return false;
return expected.every((item, index) =>

@@ -68,7 +68,4 @@ matchCore(array[index], expected[index], partialMode)

if (
!compareArrays(
Object.keys(object).sort(),
Object.keys(expected).sort(),
partialMode
)
!partialMode &&
Object.keys(object).length !== Object.keys(expected).length
)

@@ -75,0 +72,0 @@ return false;

3

package.json
{
"name": "match-json",
"version": "1.3.2",
"version": "1.3.3",
"description": "A light assertion library built with JSON APIs in mind.",

@@ -22,2 +22,3 @@ "keywords": [

"@hapi/lab": "^22.0.4",
"@hapi/code": "^5.2.4",
"eslint": "^7.0.0",

@@ -24,0 +25,0 @@ "eslint-config-prettier": "^6.11.0",

@@ -6,2 +6,3 @@ "use strict";

const { expect } = require("@hapi/code");
const { it } = (exports.lab = Lab.script());

@@ -12,7 +13,7 @@

*/
it("match:null", (t) => match(null, null));
it("match:null", (t) => expect(match(null, null)).to.equal(true));
it("match:null_vs_not_null", (t) => match(null, 0));
it("match:null_vs_not_null", (t) => expect(match(null, 0)).to.equal(false));
it("match:not_null_vs_null", (t) => match(0, null));
it("match:not_null_vs_null", (t) => expect(match(0, null)).to.equal(false));

@@ -23,11 +24,11 @@ /**

it("match:string", (t) =>
match("This is a string!", "This is a string!"));
expect(match("This is a string!", "This is a string!")).to.equal(true));
it("match:number", (t) => match(3.141592, 3.141592));
it("match:number", (t) => expect(match(3.141592, 3.141592)).to.equal(true));
it("match:boolean_false", (t) => match(false, false));
it("match:boolean_false", (t) => expect(match(false, false)).to.equal(true));
it("match:boolean_true", (t) => match(false, false));
it("match:boolean_true", (t) => expect(match(false, false)).to.equal(true));
it("match:undefined", (t) => match(undefined, undefined));
it("match:undefined", (t) => expect(match(undefined, undefined)).to.equal(true));

@@ -37,6 +38,6 @@ /**

*/
it("match:regexp", (t) => match("hola k ase?", /k ase/));
it("match:regexp", (t) => expect(match("hola k ase?", /k ase/)).to.equal(true));
it("match:regexp_no_match", (t) =>
match("hola k ase?", /hello world/));
expect(match("hola k ase?", /hello world/)).to.equal(false));

@@ -47,11 +48,11 @@ /**

it("match:function", (t) =>
(
expect(
match(18, function (x) {
return x > 5;
})
));
).to.equal(true));
it("match:function_arrow", (t) => match(18, (x) => x > 5));
it("match:function_arrow", (t) => expect(match(18, (x) => x > 5)).to.equal(true));
it("match:function_false", (t) => match(18, (x) => x < 5));
it("match:function_false", (t) => expect(match(18, (x) => x < 5)).to.equal(false));

@@ -61,30 +62,30 @@ /**

*/
it("match:object_empty", (t) => match({}, {}));
it("match:object_empty", (t) => expect(match({}, {})).to.equal(true));
it("match:object_equal", (t) =>
match({ name: "oscar" }, { name: "oscar" }));
expect(match({ name: "oscar" }, { name: "oscar" })).to.equal(true));
it("match:object_different", (t) =>
match({ name: "pedro" }, { name: "oscar" }));
expect(match({ name: "pedro" }, { name: "oscar" })).to.equal(false));
it("match:object_more_keys_value", (t) =>
match({ name: "oscar", number: 18 }, { name: "oscar" }));
expect(match({ name: "oscar", number: 18 }, { name: "oscar" })).to.equal(false));
it("match:object_more_keys_expected", (t) =>
match({ name: "oscar" }, { name: "", number: 18 }));
expect(match({ name: "oscar" }, { name: "", number: 18 })).to.equal(false));
it("match:object_with_regex_and_functions", (t) =>
(
expect(
match({ name: "oscar", age: 23 }, { name: /os/, age: (x) => x > 18 })
));
).to.equal(true));
it("match:object_with_regex_and_functions_fails", (t) =>
(
expect(
match({ name: "oscar", age: 23 }, { name: /ped/, age: (x) => x > 18 })
));
).to.equal(false));
it("match:object_with_regex_and_functions_fails_all", (t) =>
(
expect(
match({ name: "oscar", age: 23 }, { name: /ped/, age: (x) => x < 18 })
));
).to.equal(false));

@@ -94,28 +95,57 @@ /**

*/
it("match:array_empty", (t) => match([], []));
it("match:array_empty", (t) => expect(match([], [])).to.equal(true));
it("match:array", (t) => match([1, 2, "hola"], [1, 2, "hola"]));
it("match:array", (t) => expect(match([1, 2, "hola"], [1, 2, "hola"])).to.equal(true));
it("match:array_different", (t) =>
match([1, false, "hola"], [1, true, "adios"]));
expect(match([1, false, "hola"], [1, true, "adios"])).to.equal(false));
it("match:array_left_more_values", (t) =>
match([1, 2, "hola"], [1, 2]));
expect(match([1, 2, "hola"], [1, 2])).to.equal(false));
it("match:array_right_more_values", (t) =>
match([1, 2], [1, 2, "hola"]));
expect(match([1, 2], [1, 2, "hola"])).to.equal(false));
it("match:array_with_objects_missing", (t) =>
expect(match([1, { test: "aaa" }], [1, {}])).to.equal(false));
it("match:array_with_objects_different_value", (t) =>
expect(match([1, { test: "aaa" }], [1, { test: "b" }])).to.equal(false));
it("match:array_with_objects_same", (t) =>
expect(match([333, { test: "aaa" }], [333, { test: "aaa" }])).to.equal(true));
it("match:object_with_array_same", (t) =>
expect(
match({ a: [333, { test: "aaa" }] }, { a: [333, { test: "aaa" }] })
).to.equal(true));
it("match:array_same", (t) => expect(match([333, 222], [333, 222])).to.equal(true));
it("match:array_with_objects_different_key", (t) =>
expect(match([1, { test: "aaa" }], [1, { test2: "aaa" }])).to.equal(false));
it("match:array_with_objects_missing_string", (t) =>
expect(match([1, { test: "aaa", key2: 33 }], [1, { key2: 33 }])).to.equal(
false
));
it("match:array_with_objects_missing_int", (t) =>
expect(match([1, { test: "aaa", key2: 33 }], [1, { test: "aaa" }])).to.equal(
false
));
/**
* Maps
*/
it("match:map_empty", (t) => match({}, new Map()));
it("match:map_empty", (t) => expect(match({}, new Map())).to.equal(true));
it("match:map_equal", (t) =>
match({ name: "oscar" }, new Map([["name", "oscar"]])));
expect(match({ name: "oscar" }, new Map([["name", "oscar"]]))).to.equal(true));
it("match:map_different", (t) =>
match({ name: "oscar" }, new Map([["name", "pedro"]])));
expect(match({ name: "oscar" }, new Map([["name", "pedro"]]))).to.equal(false));
it("match:map_with_mote_keys", (t) =>
(
expect(
match(

@@ -128,9 +158,11 @@ { name: "oscar" },

)
));
).to.equal(false));
it("match:map_with_less_keys", (t) =>
match({ name: "", number: 18 }, new Map([["name", "oscar"]])));
expect(
match({ name: "", number: 18 }, new Map([["name", "oscar"]]))
).to.equal(false));
it("match:map_with_regex_and_functions", (t) =>
(
expect(
match(

@@ -143,6 +175,6 @@ { name: "oscar", age: 23 },

)
));
).to.equal(true));
it("match:map_with_regex_and_functions_fails", (t) =>
(
expect(
match(

@@ -155,6 +187,6 @@ { name: "oscar", age: 23 },

)
));
).to.equal(false));
it("match:map_with_regex_and_functions_fails_all", (t) =>
(
expect(
match(

@@ -167,3 +199,3 @@ { name: "oscar", age: 23 },

)
));
).to.equal(false));

@@ -173,14 +205,14 @@ /**

*/
it("match:set_empty", (t) => match([], new Set()));
it("match:set_empty", (t) => expect(match([], new Set())).to.equal(true));
it("match:set", (t) => match([1, 2, "hola"], new Set([1, 2, "hola"])));
it("match:set", (t) => expect(match([1, 2, "hola"], new Set([1, 2, "hola"]))).to.equal(true));
it("match:set_different", (t) =>
match([1, true, "adios"], new Set([1, false, "hola"])));
expect(match([1, true, "adios"], new Set([1, false, "hola"]))).to.equal(false));
it("match:set_with_more_values", (t) =>
match([1, 2], new Set([1, 2, "hola"])));
expect(match([1, 2], new Set([1, 2, "hola"]))).to.equal(false));
it("match:set_with_less_values", (t) =>
match([1, 2, "hola"], new Set([1, 2])));
expect(match([1, 2, "hola"], new Set([1, 2]))).to.equal(false));

@@ -190,9 +222,9 @@ /**

*/
it("match:types_number", (t) => match(3.1415, Number));
it("match:types_number_wrong", (t) => match(3.1415, String));
it("match:types_string", (t) => match("a boring string", String));
it("match:types_number", (t) => expect(match(3.1415, Number)).to.equal(true));
it("match:types_number_wrong", (t) => expect(match(3.1415, String)).to.equal(false));
it("match:types_string", (t) => expect(match("a boring string", String)).to.equal(true));
it("match:types_string_wrong", (t) =>
match("a boring string", Boolean));
it("match:types_boolean", (t) => match(true, Boolean));
it("match:types_boolean_wrong", (t) => match(false, String));
expect(match("a boring string", Boolean)).to.equal(false));
it("match:types_boolean", (t) => expect(match(true, Boolean)).to.equal(true));
it("match:types_boolean_wrong", (t) => expect(match(false, String)).to.equal(false));

@@ -203,3 +235,3 @@ /**

it("match:everything_together", (t) =>
(
expect(
match(

@@ -217,3 +249,3 @@ {

)
));
).to.equal(true));

@@ -225,3 +257,3 @@ /**

let matchbake = match.bake({ name: { first: /[\w]*/, last: "White" } });
return (matchbake({ name: { first: "Walter", last: "White" } }));
return matchbake({ name: { first: "Walter", last: "White" } });
});

@@ -6,2 +6,3 @@ "use strict";

const { expect } = require('@hapi/code');
const { it } = (exports.lab = Lab.script());

@@ -12,7 +13,7 @@

*/
it("partial:null", (t) => partial(null, null));
it("partial:null", (t) => expect(partial(null, null)).to.equal(true));
it("partial:null_vs_not_null", (t) => partial(null, 0));
it("partial:null_vs_not_null", (t) => expect(partial(null, 0)).to.equal(false));
it("partial:not_null_vs_null", (t) => partial(0, null));
it("partial:not_null_vs_null", (t) => expect(partial(0, null)).to.equal(false));

@@ -22,11 +23,12 @@ /**

*/
it("partial:string", (t) => partial("This is a string!", "This is a string!"));
it("partial:string", (t) =>
expect(partial("This is a string!", "This is a string!")).to.equal(true));
it("partial:number", (t) => partial(3.141592, 3.141592));
it("partial:number", (t) => expect(partial(3.141592, 3.141592)).to.equal(true));
it("partial:boolean_false", (t) => partial(false, false));
it("partial:boolean_false", (t) => expect(partial(false, false)).to.equal(true));
it("partial:boolean_true", (t) => partial(false, false));
it("partial:boolean_true", (t) => expect(partial(false, false)).to.equal(true));
it("partial:undefined", (t) => partial(undefined, undefined));
it("partial:undefined", (t) => expect(partial(undefined, undefined)).to.equal(true));

@@ -36,5 +38,6 @@ /**

*/
it("partial:regexp", (t) => partial("hola k ase?", /k ase/));
it("partial:regexp", (t) => expect(partial("hola k ase?", /k ase/)).to.equal(true));
it("partial:regexp_no_match", (t) => partial("hola k ase?", /hello world/));
it("partial:regexp_no_match", (t) =>
expect(partial("hola k ase?", /hello world/)).to.equal(false));

@@ -45,9 +48,9 @@ /**

it("partial:function", (t) =>
partial(18, function (x) {
expect(partial(18, function (x) {
return x > 5;
}));
})).to.equal(true));
it("partial:function_arrow", (t) => partial(18, (x) => x > 5));
it("partial:function_arrow", (t) => expect(partial(18, (x) => x > 5)).to.equal(true));
it("partial:function_false", (t) => partial(18, (x) => x < 5));
it("partial:function_false", (t) => expect(partial(18, (x) => x < 5)).to.equal(false));

@@ -57,24 +60,33 @@ /**

*/
it("partial:object_empty", (t) => partial({}, {}));
it("partial:object_empty", (t) => expect(partial({}, {})).to.equal(true));
it("partial:object_equal", (t) =>
partial({ name: "oscar" }, { name: "oscar" }));
expect(partial({ name: "oscar" }, { name: "oscar" })).to.equal(true));
it("partial:object_different", (t) =>
partial({ name: "pedro" }, { name: "oscar" }));
expect(partial({ name: "pedro" }, { name: "oscar" })).to.equal(false));
it("partial:object_more_keys_value", (t) =>
partial({ name: "oscar", number: 18 }, { name: "oscar" }));
expect(partial({ name: "oscar", number: 18 }, { name: "oscar" })).to.equal(true));
it("partial:object_more_keys_value2", (t) =>
expect(partial({ name: "oscar", number: 18 }, { number: 18 })).to.equal(true));
it("partial:object_more_keys_expected", (t) =>
partial({ name: "oscar" }, { name: "", number: 18 }));
expect(partial({ name: "oscar" }, { name: "", number: 18 })).to.equal(false));
it("partial:object_with_regex_and_functions", (t) =>
partial({ name: "oscar", age: 23 }, { name: /os/, age: (x) => x > 18 }));
expect(
partial({ name: "oscar", age: 23 }, { name: /os/, age: (x) => x > 18 })
).to.equal(true));
it("partial:object_with_regex_and_functions_fails", (t) =>
partial({ name: "oscar", age: 23 }, { name: /ped/, age: (x) => x > 18 }));
expect(
partial({ name: "oscar", age: 23 }, { name: /ped/, age: (x) => x > 18 })
).to.equal(false));
it("partial:object_with_regex_and_functions_fails_all", (t) =>
partial({ name: "oscar", age: 23 }, { name: /ped/, age: (x) => x < 18 }));
expect(
partial({ name: "oscar", age: 23 }, { name: /ped/, age: (x) => x < 18 })
).to.equal(false));

@@ -84,26 +96,65 @@ /**

*/
it("partial:array_empty", (t) => partial([], []));
it("partial:array_empty", (t) => expect(partial([], [])).to.equal(true));
it("partial:array", (t) => partial([1, 2, "hola"], [1, 2, "hola"]));
it("partial:array", (t) =>
expect(
partial([1, 2, "hola"], [1, 2, "hola"])
).to.equal(true));
it("partial:array_different", (t) =>
partial([1, false, "hola"], [1, true, "adios"]));
expect(partial([1, false, "hola"], [1, true, "adios"])).to.equal(false));
it("partial:array_left_more_values", (t) => partial([1, 2, "hola"], [1, 2]));
it("partial:array_left_more_values", (t) =>
expect(
partial([1, 2, "hola"], [1, 2])
).to.equal(false));
it("partial:array_right_more_values", (t) => partial([1, 2], [1, 2, "hola"]));
it("partial:array_right_more_values", (t) =>
expect(
partial([1, 2], [1, 2, "hola"])
).to.equal(false));
it("partial:array_with_objects", (t) =>
expect(
partial([1, {"test": "aaa"}], [1, {"test": "aaa"}])
).to.equal(true));
it("partial:array_with_objects_missing", (t) =>
expect(
partial([1, {"test": "aaa"}], [1, {}])
).to.equal(true));
it("partial:array_with_objects_different_value", (t) =>
expect(
partial([1, {"test": "aaa"}], [1, {"test": "b"}])
).to.equal(false));
it("partial:array_with_objects_different_key", (t) =>
expect(
partial([1, {"test": "aaa"}], [1, {"test2": "aaa"}])
).to.equal(false));
it("partial:array_with_objects_missing_string", (t) =>
expect(
partial([1, {"test": "aaa", "key2": 33}], [1, {"key2": 33}])
).to.equal(true));
it("partial:array_with_objects_missing_int", (t) =>
expect(
partial([1, {"test": "aaa", "key2": 33}], [1, {"test": "aaa"}])
).to.equal(true));
/**
* Maps
*/
it("partial:map_empty", (t) => partial({}, new Map()));
it("partial:map_empty", (t) => expect(partial({}, new Map())).to.equal(true));
it("partial:map_equal", (t) =>
partial({ name: "oscar" }, new Map([["name", "oscar"]])));
expect(partial({ name: "oscar" }, new Map([["name", "oscar"]]))).to.equal(true));
it("partial:map_different", (t) =>
partial({ name: "oscar" }, new Map([["name", "pedro"]])));
expect(partial({ name: "oscar" }, new Map([["name", "pedro"]]))).to.equal(false));
it("partial:map_with_mote_keys", (t) =>
partial(
expect(partial(
{ name: "oscar" },

@@ -114,9 +165,11 @@ new Map([

])
));
)).to.equal(false));
it("partial:map_with_less_keys", (t) =>
partial({ name: "", number: 18 }, new Map([["name", "oscar"]])));
expect(
partial({ name: "oscar", number: 18 }, new Map([["name", "oscar"]]))
).to.equal(true));
it("partial:map_with_regex_and_functions", (t) =>
partial(
expect(partial(
{ name: "oscar", age: 23 },

@@ -127,6 +180,6 @@ new Map([

])
));
)).to.equal(true));
it("partial:map_with_regex_and_functions_fails", (t) =>
partial(
expect(partial(
{ name: "oscar", age: 23 },

@@ -137,6 +190,6 @@ new Map([

])
));
)).to.equal(false));
it("partial:map_with_regex_and_functions_fails_all", (t) =>
partial(
expect(partial(
{ name: "oscar", age: 23 },

@@ -147,3 +200,3 @@ new Map([

])
));
)).to.equal(false));

@@ -153,14 +206,14 @@ /**

*/
it("partial:set_empty", (t) => partial([], new Set()));
it("partial:set_empty", (t) => expect(partial([], new Set())).to.equal(true));
it("partial:set", (t) => partial([1, 2, "hola"], new Set([1, 2, "hola"])));
it("partial:set", (t) => expect(partial([1, 2, "hola"], new Set([1, 2, "hola"]))).to.equal(true));
it("partial:set_different", (t) =>
partial([1, true, "adios"], new Set([1, false, "hola"])));
expect(partial([1, true, "adios"], new Set([1, false, "hola"]))).to.equal(false));
it("partial:set_with_more_values", (t) =>
partial([1, 2], new Set([1, 2, "hola"])));
expect(partial([1, 2], new Set([1, 2, "hola"]))).to.equal(false));
it("partial:set_with_less_values", (t) =>
partial([1, 2, "hola"], new Set([1, 2])));
expect(partial([1, 2, "hola"], new Set([1, 2]))).to.equal(false));

@@ -170,8 +223,8 @@ /**

*/
it("partial:types_number", (t) => partial(3.1415, Number));
it("partial:types_number_wrong", (t) => partial(3.1415, String));
it("partial:types_string", (t) => partial("a boring string", String));
it("partial:types_string_wrong", (t) => partial("a boring string", Boolean));
it("partial:types_boolean", (t) => partial(true, Boolean));
it("partial:types_boolean_wrong", (t) => partial(false, String));
it("partial:types_number", (t) => expect(partial(3.1415, Number)).to.equal(true));
it("partial:types_number_wrong", (t) => expect(partial(3.1415, String)).to.equal(false));
it("partial:types_string", (t) => expect(partial("a boring string", String)).to.equal(true));
it("partial:types_string_wrong", (t) => expect(partial("a boring string", Boolean)).to.equal(false));
it("partial:types_boolean", (t) => expect(partial(true, Boolean)).to.equal(true));
it("partial:types_boolean_wrong", (t) => expect(partial(false, String)).to.equal(false));

@@ -182,3 +235,4 @@ /**

it("partial:everything_together", (t) =>
partial(
expect(
partial(
{

@@ -194,3 +248,4 @@ name: { first: "Walter", last: "White" },

}
));
)
).to.equal(true));

@@ -197,0 +252,0 @@ /**

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