match-json
Advanced tools
Comparing version 0.1.1 to 0.1.5
@@ -54,5 +54,3 @@ 'use strict'; | ||
if (array.length !== expected.length) return false; | ||
return array.reduce((previous, current, index) => { | ||
return match(array[index], expected[index]) && previous; | ||
}, true); | ||
return array.every((item, index) => match(array[index], expected[index])); | ||
} | ||
@@ -69,6 +67,4 @@ | ||
function compareObjects(object, expected) { | ||
if (!compareArrays(Object.keys(object), Object.keys(expected))) return false; | ||
return Object.keys(expected).reduce((previous, current) => { | ||
return match(object[current], expected[current]) && previous; | ||
}, true); | ||
if (!compareArrays(Object.keys(object).sort(), Object.keys(expected).sort())) return false; | ||
return Object.keys(expected).every(key => match(object[key], expected[key])); | ||
} | ||
@@ -86,3 +82,3 @@ | ||
let result = func.call(null, value); | ||
if (typeof result !== 'boolean') { | ||
if (type(result) !== 'boolean') { | ||
throw new Error('Function provided should return a boolean'); | ||
@@ -89,0 +85,0 @@ } |
{ | ||
"name": "match-json", | ||
"version": "0.1.1", | ||
"description": "An JavaScript library to test JSON with some nice features", | ||
"keywords": [ "match", "json" ], | ||
"version": "0.1.5", | ||
"description": "A JavaScript library to test JSON APIs", | ||
"keywords": [ | ||
"match", | ||
"json", | ||
"api", | ||
"test", | ||
"revursive" | ||
], | ||
"main": "index.js", | ||
@@ -14,6 +20,10 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^0.13.0", | ||
"eslint": "^2.4.0", | ||
"eslint-config-airbnb": "^6.1.0" | ||
"ava": "^2.2.0", | ||
"eslint": "^6.0.1", | ||
"eslint-config-airbnb": "^17.1.1" | ||
}, | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/ozkxr/match" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# match [![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.svg?branch=master)](https://travis-ci.org/ozkxr/match) # | ||
An JavaScript library to test JSON with some nice features. | ||
A JavaScript library to test JSON APIs. | ||
@@ -8,7 +8,8 @@ It is built to test REST API endpoints but, of course, you can use it to whatever you want. | ||
## Install ## | ||
``` | ||
```bash | ||
npm install match-json | ||
``` | ||
## But, what it does? ## | ||
## Functionality ## | ||
@@ -30,2 +31,3 @@ Of course, match JSON objects. | ||
``` | ||
And structures (objects and arrays). | ||
@@ -71,3 +73,3 @@ | ||
``` | ||
```javascript | ||
const nameIsLarge = match.bake({ name: name => name.length > 10 }) | ||
@@ -80,3 +82,3 @@ nameIsLarge('Tom') // => false :( | ||
#### Match #### | ||
#### Match signature #### | ||
@@ -87,3 +89,3 @@ * `match( a : T, b : T ) : boolean` | ||
#### Bake #### | ||
#### Bake signature #### | ||
@@ -90,0 +92,0 @@ * `bake( a: T ) : PredicateFunction` |
@@ -93,3 +93,3 @@ 'use strict'; | ||
let matchbake = match.bake({name: { first: /[\w]*/, last: 'White' } }); | ||
return matchbake({ name: { first: /[\w]*/, last: 'White' } }); | ||
return t.true(matchbake({ name: { first: 'Walter', last: 'White' } })); | ||
}); |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10925
104
0
10
180