From aa932958662139bf804e1272b0ac74401c75fc6e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 5 Aug 2018 16:45:54 +0300 Subject: [PATCH] more playing with patterns (need more testing)... Signed-off-by: Alex A. Naanou --- diff.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/diff.js b/diff.js index 9df0cd9..010961d 100644 --- a/diff.js +++ b/diff.js @@ -342,13 +342,31 @@ module.STRING = // NUMBER(func) // -> pattern // -// XXX support range checking, ... +// XXX TEST... var NUMBER = module.NUMBER = makeCIPattern('NUMBER', function(obj, cmp){ // XXX do the .value test.... - return obj === NUMBER || typeof(obj) == typeof(123) }, + return obj === NUMBER + || (typeof(obj) == typeof(123) + && (this.value.length == 1 ? + this.value[0] == obj + // min/max... + : this.value.length == 2 ? + this.value[0] <= obj + && this.value[1] > obj + // min/max/step... + : this.value.length == 3 ? + this.value[0] <= obj + && this.value[1] > obj + && (obj + (this.value[0] % this.value[2])) % this.value[2] + : this.value[0] instanceof Function ? + this.value[0](obj) + // pattern... + : this.value[0] != null ? + cmp(this.value[0], obj) + : true )) }, function(...value){ this.value = value })