Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

has(obj, match)

  • Loading branch information...
commit fd8deb69b9d17f3561fc0b3d61b93a2be4d0c674 1 parent cef3cf4
@dominictarr authored
Showing with 28 additions and 2 deletions.
  1. +28 −2 objects.js
View
30 objects.js
@@ -196,9 +196,7 @@ deepMerge = exports.deepMerge = function (old, nw) {
if ('object' === typeof nw[k] && 'object' === typeof old[k] && old[k] && nw[k] && old[k]) {
s[k] = deepMerge (old[k], nw[k])
}
-
})
-
return s
}
@@ -210,4 +208,32 @@ var path = exports.path = function (object, path) {
object = object[key]
}
return object
+}
+
+var eachPath = exports.eachPath = function (object, opts, iterator) {
+ // function iterator (value, path)
+}
+
+/*
+NOTE: naive implementation.
+`match` must not contain circular references.
+*/
+
+var has = exports.has = function (obj, match) {
+ if(obj == null && match != null)
+ return false
+
+ for (var key in match) {
+ //deep/complex checks
+ if('object' == typeof match[key]) {
+ if(!has(obj[key], match[key]))
+ return false
+ } else if ('function' == typeof match[key]) {
+ if (!match[key](obj[key]))
+ return false
+ } else if(match[key] !== obj[key])
+ return false
+ //if match is a function, apply it to the corrisponding obj[key]
+ }
+ return true
}
Please sign in to comment.
Something went wrong with that request. Please try again.