diff --git a/README.md b/README.md index f8f32e6..21ad9d6 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ - [Diff](#diff) - [Diff class API](#diff-class-api) - [Diff object API](#diff-object-api) + - [Shorthands and functions](#shorthands-and-functions) - [Supported JavaScript objects](#supported-javascript-objects) - [Extended 'Text' object support](#extended-text-object-support) - [Options](#options) @@ -267,7 +268,10 @@ var diff = new Diff(A, B) `Diff.cmp(A, B) -> bool` Deep compare `A` to `B`. -`Diff.clone()` +`Diff.vars(pattern, A) -> obj` +Get variable values defined (via `VAR`/`LIKE`) in `pattern` matching corresponding values in `obj`. + +`Diff.clone(title)` Clone the `Diff` constructor, useful for extending or tweaking the type handlers (see: [Extending](#extending-diff) below). `Diff.fromJSON(json) -> diff` @@ -313,6 +317,24 @@ Return the *parent diff* that was used to generate the current *child diff* or t Serialize the *diff* to JSON. Note that the output may or may not be JSON compatible depending on the inputs. +### Shorthands and functions + +`cmp(A, B) -> bool` +Deep compare `A` and `B`. + +This is a shorthand to: `Diff.cmp(A, B) -> bool` + +`patch(diff, A) -> A'` +Apply changes in `diff` to `A` (*patch*). + +This is a shorthand to: `diff.patch(A) -> A'` + +`vars(pattern, A) -> obj` +Get variable values defined (via `VAR`/`LIKE`) in `pattern` matching corresponding values in `obj`. + +This is a shorthand to: `Diff.vars(pattern, B) -> obj` + + ### Supported JavaScript objects The object support can be split into two, basic objects that are stored as-is and containers that support item changes when their types match. diff --git a/diff.js b/diff.js index 01ba54f..50936dc 100644 --- a/diff.js +++ b/diff.js @@ -2347,6 +2347,11 @@ var DiffClassPrototype = { // proxy generic stuff to .types... cmp: proxy('types.cmp'), + vars: function(pattern, obj){ + var o = {} + this.cmp(pattern, obj, null, o) + return o.ns || {} + }, // XXX do format/version conversion... fromJSON: function(json){ @@ -2529,6 +2534,13 @@ function(diff, obj, options, types){ .patch(obj, options) } +// Extract pattern VAR/LIKE matching values from obj... +// +var vars = +module.vars = +function(pattern, obj){ + return Diff.vars(pattern, obj) } + /**********************************************************************