Permalink
Browse files

pull in obj-ops.

  • Loading branch information...
dominictarr committed Sep 26, 2011
1 parent 929c355 commit c9f53144e19b72d8e8483b82124fd8b7c7ea62ae
Showing with 69 additions and 0 deletions.
  1. +11 −0 functions.js
  2. +57 −0 objects.js
  3. +1 −0 package.json
View
@@ -49,3 +49,14 @@ exports.curry = function (/*funx, args...*/) {
}))
}
}
+
+
+exports.deepCurry = function () {
+ var args = [].slice.call(arguments)
+ , funx = args.shift()
+
+ return function () {
+ var _args = [].slice.call(arguments)
+ return funx.apply(this, objects.merge([], args, _args))
+ }
+}
View
@@ -119,3 +119,60 @@ var mapToArray = exports.mapToArray = function (ary, iterator){
})
return r
}
+
+
+diff = exports.diff = function (old, nw) {
+ var ab = deepMerge (nw, old)
+ , s = {}
+
+ each(ab, function (ignore, k) {
+
+ console.log(typeof nw[k], typeof old[k], !!old[k])
+ //if the property is not in the new object, it must have been deleted.
+ if (nw[k] == null)
+ s[k] = null //null on a diff means to delete that property.
+ else if ('object' === typeof nw[k] && 'object' === typeof old[k] && old[k])
+ s[k] = diff(old[k], nw[k])
+ else if (nw[k] !== old[k])
+ s[k] = nw[k] === undefined ? null : nw[k]
+
+ })
+ return s
+
+}
+
+patch = exports.patch = function (old, ptch) {
+ var nw = deepMerge({}, old)
+
+ each(ptch, function (ignore, k) {
+
+ //if the property is not in the new object, it must have been deleted.
+ if (ptch[k] === null)
+ delete nw[k]
+ else if ('object' === typeof ptch[k])
+ nw[k] = patch(old[k], ptch[k])
+ else
+ nw[k] = ptch[k]
+
+ })
+
+ return nw
+
+}
+
+deepMerge = exports.deepMerge = function (old, nw) {
+ var ab = merge({}, nw, old)
+ , s = Array.isArray(nw) ? [] : {}
+
+ each(ab, function (ignore, k) {
+
+ s[k] = nw[k] === undefined ? old[k] : nw[k]
+ if ('object' === typeof nw[k] && 'object' === typeof old[k] && old[k] && nw[k] && old[k]) {
+ s[k] = deepMerge (old[k], nw[k])
+ }
+
+ })
+
+ return s
+
+}
View
@@ -2,6 +2,7 @@
, "version": "2.3.3"
, "description": "utility belt was (Dominic's Utilities)"
, "homepage": "http://github.com/dominictarr/d-utils"
+, "main": "./index.js"
, "repository":
{ "type": "git"
, "url": "https://github.com/dominictarr/d-utils.git" }

0 comments on commit c9f5314

Please sign in to comment.