mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 11:00:12 +00:00
added experimental diff format pattern + minor fixes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e136912edc
commit
04320742ad
34
diff.js
34
diff.js
@ -275,7 +275,8 @@ var LogicTypePrototype = {
|
||||
}
|
||||
|
||||
var res = this.__cmp__(obj, cmp, cache)
|
||||
|| (obj.__cmp__
|
||||
|| (obj != null
|
||||
&& obj.__cmp__
|
||||
&& obj.__cmp__(this, cmp, cache))
|
||||
c.set(obj, res)
|
||||
|
||||
@ -307,12 +308,38 @@ var makeCIPattern = function(name, check, init){
|
||||
// ANY
|
||||
// -> pattern
|
||||
//
|
||||
// XXX AT('moo', ANY) matches L even if 'moo' in L is false...
|
||||
var ANY =
|
||||
module.ANY =
|
||||
makeCIPattern('ANY',
|
||||
function(){ return true })()
|
||||
|
||||
|
||||
// Bool pattern...
|
||||
//
|
||||
// BOOL
|
||||
// -> pattern
|
||||
//
|
||||
var BOOL =
|
||||
module.BOOL =
|
||||
makeCIPattern('BOOL',
|
||||
function(obj){
|
||||
return obj === true || obj === false })()
|
||||
|
||||
|
||||
// Function pattern...
|
||||
//
|
||||
// FUNCTION
|
||||
// -> pattern
|
||||
//
|
||||
// XXX add signature checking...
|
||||
var FUNCTION =
|
||||
module.FUNCTION =
|
||||
makeCIPattern('FUNCTION',
|
||||
function(obj){
|
||||
return obj instanceof Function })()
|
||||
|
||||
|
||||
// String pattern...
|
||||
//
|
||||
// STRING
|
||||
@ -408,7 +435,7 @@ module.ARRAY =
|
||||
|| (obj instanceof Array
|
||||
// XXX make this fail on first fail -- currently
|
||||
// this runs every test on every elem...
|
||||
&& this.value.filter(function(value){
|
||||
&& (this.value || []).filter(function(value){
|
||||
return (typeof(value) == typeof(123) ?
|
||||
obj.length == value
|
||||
// function...
|
||||
@ -418,7 +445,7 @@ module.ARRAY =
|
||||
: obj.filter(function(e){
|
||||
return cmp(value, e)
|
||||
}).length == obj.length)
|
||||
}).length == this.value.length) },
|
||||
}).length == (this.value || []).length) },
|
||||
function(...value){ this.value = value })
|
||||
|
||||
|
||||
@ -873,7 +900,6 @@ module.Types = {
|
||||
var typeB = this.detect(B, undefined, options)
|
||||
|
||||
// type match...
|
||||
//if(type === typeB){
|
||||
if(type === typeB && this.has(type)){
|
||||
return type
|
||||
|
||||
|
||||
89
format.js
Normal file
89
format.js
Normal file
@ -0,0 +1,89 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
**********************************************************************/
|
||||
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
||||
(function(require){ var module={} // make module AMD/node compatible...
|
||||
/*********************************************************************/
|
||||
|
||||
var diff = require('./diff')
|
||||
var {
|
||||
ANY,
|
||||
BOOL, NUMBER, STRING, ARRAY, FUNCTION,
|
||||
OR, AND, NOT,
|
||||
AT, OF, IN,
|
||||
|
||||
EMPTY, NONE,
|
||||
} = diff
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
// XXX need better mismatch checking -- ideally stating the exact spot
|
||||
// where we did not match...
|
||||
//
|
||||
|
||||
var VALUE =
|
||||
module.VALUE = OR(
|
||||
EMPTY,
|
||||
NONE,
|
||||
ANY)
|
||||
|
||||
|
||||
var CHANGE =
|
||||
module.CHANGE = AND(
|
||||
AT('path', ARRAY),
|
||||
// XXX optional...
|
||||
// ...see DIFF_OBJECT's options for description...
|
||||
AT('type', OR(STRING, undefined)),
|
||||
OR(
|
||||
// A ans B...
|
||||
AND(
|
||||
AT('A', VALUE),
|
||||
AT('B', VALUE)),
|
||||
// only A...
|
||||
AT('A', VALUE),
|
||||
// only B...
|
||||
AT('B', VALUE)))
|
||||
|
||||
|
||||
var DIFF_FORMAT_FLAT =
|
||||
module.DIFF_FORMAT_FLAT = ARRAY(CHANGE)
|
||||
|
||||
|
||||
// XXX
|
||||
var DIFF_FORMAT_TREE =
|
||||
module.DIFF_FORMAT_TREE = ANY
|
||||
|
||||
|
||||
var DIFF_OBJECT =
|
||||
module.DIFF_OBJECT = AND(
|
||||
AT('format', diff.FORMAT_NAME),
|
||||
//AT('version', STRING(/\d+\.\d+\.\d+/)),
|
||||
AT('placeholders', AND(
|
||||
// XXX must be unique ANY...
|
||||
AT('NONE', ANY),
|
||||
AT('EMPTY', ANY))),
|
||||
AT('options', AND(
|
||||
AT('tree_diff', OR(BOOL, null)),
|
||||
AT('keep_none', OR(BOOL, null)),
|
||||
AT('min_text_length', OR(NUMBER, null)),
|
||||
AT('no_attributes', OR(BOOL, null)),
|
||||
AT('NONE', OR(ANY, null)),
|
||||
AT('EMPTY', OR(ANY, null)),
|
||||
AT('no_length', OR(BOOL, null)),
|
||||
AT('cmp', OR(FUNCTION, null)) )),
|
||||
AT('timestamp', NUMBER),
|
||||
OR(
|
||||
AND(
|
||||
AT('structure', 'flat'),
|
||||
AT('diff', DIFF_FORMAT_FLAT)),
|
||||
AND(
|
||||
AT('structure', 'tree'),
|
||||
AT('diff', DIFF_FORMAT_TREE))) )
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* vim:set ts=4 sw=4 : */ return module })
|
||||
Loading…
x
Reference in New Issue
Block a user