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

match-json

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

match-json - npm Package Compare versions

Comparing version

to
1.1.1

@@ -30,2 +30,6 @@ 'use strict';

return compareArrays(value, expected); // eslint-disable-line no-use-before-define
case 'map':
return compareObjects(value, mapToObject(expected)); // eslint-disable-line no-use-before-define
case 'set':
return compareArrays(value, Array.from(expected)); // eslint-disable-line no-use-before-define
default:

@@ -87,2 +91,17 @@ return false;

/**
* Transform a Map into an object literal
*
* @param {Map} map A map to be transformed.
* @return {Object} The transformed object.
* @api private
*/
function mapToObject(map) {
const obj = {};
for (let [key, value] of map) {
obj[key] = value;
}
return obj;
}
module.exports = match;

@@ -12,2 +12,4 @@ 'use strict';

if (value instanceof Array) return 'array';
if (value instanceof Map) return 'map';
if (value instanceof Set) return 'set';
return typeof value;

@@ -14,0 +16,0 @@ }

{
"name": "match-json",
"version": "1.0.1",
"version": "1.1.1",
"description": "A JavaScript library to test JSON APIs",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,2 +0,2 @@

# match-json [![Build Status](https://travis-ci.org/ozkxr/match.svg?branch=master)](https://travis-ci.org/ozkxr/match) #
# match-json [![Build Status](https://travis-ci.org/ozkxr/match-json.svg?branch=master)](https://travis-ci.org/ozkxr/match) #

@@ -3,0 +3,0 @@ A JavaScript library to test JSON APIs.

@@ -6,3 +6,3 @@ 'use strict';

/*
/**
* Null values

@@ -16,3 +16,3 @@ */

/*
/**
* Primitive types

@@ -37,3 +37,3 @@ */

/**expected => value => match(value, expected);
/**
* Functions

@@ -77,5 +77,37 @@ */

test('match:array_right_more_values', t => t.false(match([ 1, 2 ], [ 1, 2, 'hola'])));
test('match:array_right_more_values', t => t.false(match([ 1, 2 ], [ 1, 2, 'hola' ])));
/**
* Maps
*/
test('match:map_empty', t => t.true(match({}, new Map())));
test('match:map_equal', t => t.true(match({ name: 'oscar' }, new Map([[ 'name', 'oscar' ]]))));
test('match:map_different', t => t.false(match({ name: 'oscar' }, new Map([[ 'name', 'pedro' ]]))));
test('match:map_with_mote_keys', t => t.false(match({ name: 'oscar' }, new Map([[ 'name', 'oscar' ], [ 'number', 18 ]]))));
test('match:map_with_less_keys', t => t.false(match({ name: '', number: 18 }, new Map([[ 'name', 'oscar' ]]))));
test('match:map_with_regex_and_functions', t => t.true(match({ name: 'oscar', age: 23 }, new Map([[ 'name', /os/ ], [ 'age', x => x > 18 ]]))));
test('match:map_with_regex_and_functions_fails', t => t.false(match({ name: 'oscar', 'age': 23 }, new Map([[ 'name', /ped/ ], [ 'age', x => x > 18 ]]))));
test('match:map_with_regex_and_functions_fails_all', t => t.false(match({ name: 'oscar', age: 23 }, new Map([[ 'name', /ped/ ], [ 'age', x => x < 18 ]]))));
/**
* Sets
*/
test('match:set_empty', t => t.true(match([], new Set())));
test('match:set', t => t.true(match([ 1, 2, 'hola' ], new Set([ 1, 2, 'hola' ]))));
test('match:set_different', t => t.false(match([ 1, true, 'adios' ], new Set([ 1, false, 'hola' ]))));
test('match:set_with_more_values', t => t.false(match([ 1, 2 ], new Set([ 1, 2, 'hola' ]))));
test('match:set_with_less_values', t => t.false(match([ 1, 2, 'hola' ], new Set([ 1, 2 ]))));
/**
* And everythong together

@@ -82,0 +114,0 @@ */

@@ -24,2 +24,8 @@ 'use strict';

test('type:array', t => t.true(type( [ 1, 2 ]) === 'array'));
test('type:object_with_constructor', t => t.true(type(new Object()) === 'object'));
test('type:array', t => t.true(type([ 1, 2 ]) === 'array'));
test('type:map', t => t.true(type(new Map()) === 'map'));
test('type:set', t => t.true(type(new Set()) === 'set'));