From c0c90b117d167f1f2f80b857a6fcf1a328c25fbf Mon Sep 17 00:00:00 2001 From: Simon Blackwell Date: Fri, 15 Feb 2019 04:58:07 -0500 Subject: [PATCH] `$length` now handles `.count`, `.count()`, `.size`, `.size()`, `.length`. --- README.md | 2 ++ index.js | 6 +++++- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63e86cf..86eb607 100644 --- a/README.md +++ b/README.md @@ -452,6 +452,8 @@ $year - `{: {$year: number year}}` ## Updates +2019-02-15 v2.03b - `$length` now handles `.count`, `.count()`, `.size`, `.size()`, `.length`. + 2019-02-12 v2.03b - All functions now have basic documentation. 2019-02-11 v2.02b - Lots of documentation. Started deprecation on method name `.match` in favor of `.query`, but both will work for now through aliasing. diff --git a/index.js b/index.js index 5643f2b..d1a1184 100644 --- a/index.js +++ b/index.js @@ -553,8 +553,12 @@ this[as||key] = iterable.length } else if(typeof(iterable.count)==="function") { this[as||key] = iterable.count(); + } else if(typeof(iterable.count)==="number") { + this[as||key] = iterable.count; } else if(typeof(iterable.size)==="function") { this[as||key] = iterable.size(); + } else if(typeof(iterable.size)==="number") { + this[as||key] = iterable.size; } else { let count = 0; for(let value of iterable) { @@ -778,7 +782,7 @@ return /^\d{3}-?\d{2}-?\d{4}$/.test(value); }, $length(value,length) { - return a && a.length===length; + return a && (a.length===length || a.size===length); }, $lock(value,_,key) { try { diff --git a/package.json b/package.json index 229603a..813365b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "joqular", - "version": "2.0.3b", + "version": "2.0.4b", "description": "JOQULAR (JavaScript Object Query Language Representation) for JSON data matching, transformation, validation and extraction", "main": "index.js", "scripts": {