Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rttc

Package Overview
Dependencies
Maintainers
4
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rttc - npm Package Compare versions

Comparing version 3.1.3 to 3.2.0

lib/is-equal.js

3

index.js

@@ -5,3 +5,4 @@ module.exports = {

coerce: require('./lib/coerce'),
infer: require('./lib/infer')
infer: require('./lib/infer'),
isEqual: require('./lib/is-equal')
};
{
"name": "rttc",
"version": "3.1.3",
"version": "3.2.0",
"description": "Runtime type-checking for JavaScript.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,49 +0,4 @@

/**
* Module dependencies
*/
var _ = require('lodash');
/**
* A variation on the lodash equality check that uses the expected typeSchema
* for additional context (it stringifies lamdas and compares them that way)
*
* @param {=} actualResult
* @param {*} compareTo
* @param {*} typeSchema
* @return {Boolean}
*/
module.exports = function isEquivalent (actualResult, compareTo, typeSchema) {
// Use a lodash equality check, but customize it a bit
var _keypath = [];
return _.isEqual(actualResult, compareTo, function(value, other, indexOrKey) {
// Keep track of indices/keys already traversed in order to dereference the appropriate part
// of the type schema (`indexOrKey` will be undefined if this is the top-level)
if (!_.isUndefined(indexOrKey)){
_keypath.push(indexOrKey);
}
try {
// Attempt to look up the appropriate keypath within the type schema, or
// use the top-level type schema if we haven't tracked any key/indices traversed
// yet.
var typeToCompareAgainst = typeSchema;
if (_keypath.length > 0) {
typeToCompareAgainst = _.get(typeSchema, _keypath.join('.'));
}
// If this type is a lamda, `.toString()` the functions and compare
// them that way.
if (typeToCompareAgainst === 'lamda') {
return (value.toString() === other.toString());
}
}
catch (e){ return false; }
// If this is not a lamda input, just let the default lodash isEqual handling
// take care of it.
return undefined;
});
};
// This file is here for backwards compatibility.
// (the logic herein is now exposed as `rttc.isEqual()`
// and should be used as such)
module.exports = require('../../lib/is-equal');
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc