A simple, fast, zero-dependency, ES2015+ aware deep matching utility
$ cnpm install clean-match
A simple, fast, zero-dependency, ES2015+ aware deep matching utility, with support for ES5 environments. Tested in Node 4+ and PhantomJS 2.
Install via npm:
npm install --save clean-match
And some basic usage in Node or Browserify:
var match = require("clean-match")
var foo = {a: 1, b: 2}
if (match.loose(foo, {a: 1, b: 2})) {
console.log("It matched!")
}
You may also use it in the browser:
<script src="./node_modules/clean-match/clean-match.js"></script>
<script>
var foo = {a: 1, b: 2}
if (match.loose(foo, {a: 1, b: 2})) {
alert("It matched!")
}
</script>
It's also usable as an AMD module:
define(["clean-match"], function (match) {
var foo = {a: 1, b: 2}
if (match.loose(foo, {a: 1, b: 2})) {
console.log("It matched!")
}
})
match.loose(a, b)
Compare two values, either primitives or objects, structurally without regard to their prototypes. Note that this does still do some type checking:
argumentsstack property on Errorsarguments, Errors) are checked to have the same prototype.Here's a couple other notes:
Buffer polyfill in Node.global.match.strict(a, b)
Compare two values, either primitives or objects, structurally, but also verify that their prototypes match (and their children, recursively). The above notes for match.loose also apply, except that symbols are checked for identity instead.
There's many reasons:
assert and Lodash's _.match being the primary exceptions.Copyright (c) 2016 and later, Isiah Meadows me@isiahmeadows.com.
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Copyright 2013 - present © cnpmjs.org | Home |