Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
match-json
Advanced tools
A JavaScript library to test JSON APIs.
It is built to test REST API endpoints but, of course, you can use it to whatever you want.
npm install match-json
Of course, match JSON objects.
You can compare primitives.
// Numbers
match(3.1415, 3.1415) // => true
//Strings
match('Uno Dos Tres', 'Uno Dos Tres') // => true
// Booleans
match(false, false) // => true
// And with undefined and null values
match(undefined, undefined) // => true
match(null, null) // => true
And structures (objects and arrays).
match({ name: 'Link', color: 'green' }, { name: 'Link', color: 'green' }) // => true
match([ 'deku', 'goron', 'zora' ], [ 'deku', 'goron', 'zora' ]) // => true
You can match using functions
// Yeah, with functions!
match({ name: 'Samus' }, hero => hero.name.length >= 5) // => true
And regular expressions
// Yeah, with RegExp too!
match('Kvothe', /K.ot.*e?/) // => true
And everything together!
match({
name: { first: 'Walter', last: 'White' },
age: 51
},
{
name: { first: /[\w]*/, last: 'White' },
age: age => age > 18
}); // => YEAH, true!
Also, you can also predefine an expected pattern.
const nameIsLarge = match.bake({ name: name => name.length > 10 })
nameIsLarge('Tom') // => false :(
nameIsLarge('Tooooooooom') // => true :D
match( a : T, b : T ) : boolean
match( a : T, test : RegExp ) : boolean
match( a : T, test : PredicateFunction ) : boolean
bake( a: T ) : PredicateFunction
( where PredicateFunction = ( w : T ) : boolean )
Feel free to open an issue and/or make a PR if you found a bug or think in a way this lib or even the README can be improved.
MIT
FAQs
A light assertion library built with JSON APIs in mind.
The npm package match-json receives a total of 28,331 weekly downloads. As such, match-json popularity was classified as popular.
We found that match-json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.