New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

swk-compare

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swk-compare

simple comparison library

latest
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

swk-compare

Description

A simple library to assist with validating data by comparing it to an expectation

How To Use

var similair = compare(myValue, myExpectation);

myValue in the example above can be any of the following:

  • a scalar value (i.e. integer, string, boolean)
  • an array
  • an object
  • a function

myExpectation can contain the same

The comparison uses like for like:

var similar = compare("a", "a"); // true
var similar = compare("a", "b"); // false

or it can use a validation function:

var similar = compare("a", function (context) {
    return context === "a");
});// true

The comparison is recursive, so it will work with deeply nested structures

var similar = compare(
    [1, 2, 3, {"foo": {"bar": {"baz": function () { return true; }}}}],
    [1, 2, 3, {"foo": {"bar": {"baz": function (f) { return f() === true; }}}}]
); // true

FAQs

Package last updated on 13 Nov 2014

Did you know?

Socket

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.

Install

Related posts