From 90051fd2ff8ad67b7f4e12269d7c9e98315b42fc Mon Sep 17 00:00:00 2001 From: Ayman Date: Sun, 24 May 2020 10:32:25 +0400 Subject: [PATCH 1/3] Implements a solution for unordered index matching case --- index.js | 10 +++++++++- test/test_objectron.js | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 2920a31..7a3976c 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,15 @@ const match = (payload, pattern, callback) => { */ } else if (element instanceof Object) { currentNode[key][index] = {} - tester(payload[key][index], element, currentNode[key][index]) + + payload[key].forEach((payloadItem, payloadIndex) => { + if(payloadItem instanceof Object) { + const payloadItemMatch = match(payloadItem, element) + if(payloadItemMatch.match) { + tester(payload[key][payloadIndex], element, currentNode[key][index]) + } + } + }) } else if (payload[key].includes(element)) { currentNode[key][index] = element result.total += 1 diff --git a/test/test_objectron.js b/test/test_objectron.js index 9de41ee..77ec5c8 100644 --- a/test/test_objectron.js +++ b/test/test_objectron.js @@ -564,7 +564,15 @@ suite('Objectron Core Tests', () => { { type: 'markdown', text: '*This must be it*' - } + }, + { + type: 'html', + text: 'Hello world' + }, + { + type: 'yaml', + text: 'Another text!' + }, ] } } @@ -578,14 +586,22 @@ suite('Objectron Core Tests', () => { { type: 'markdown', text: /.*/ - } + }, + { + type: 'html', + text: /(.*?)<\/b>/ + }, + { + type: 'yaml', + text: /(?.*)/, + }, ] } }) const expected = { match: true, - total: 8, + total: 11, matches: { api: 13, ids: [12, 130, 45], @@ -595,13 +611,24 @@ suite('Objectron Core Tests', () => { { type: 'markdown', text: '*This must be it*' - } + }, + { + type: 'html', + text: 'Hello world' + }, + { + type: 'yaml', + text: 'Another text!' + }, ] } }, - groups: {} + groups: { + yamlText: 'Another text!' + } } - assert.isFalse(result.match) + assert.isTrue(result.match) + assert.deepEqual(result, expected) }) }) From 80fd903bf5dca33f839236ea2c6932366f8a70d0 Mon Sep 17 00:00:00 2001 From: Ayman Date: Sun, 24 May 2020 20:19:18 +0400 Subject: [PATCH 2/3] StandardJS lint for index.js --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7a3976c..faf53ef 100644 --- a/index.js +++ b/index.js @@ -64,9 +64,9 @@ const match = (payload, pattern, callback) => { currentNode[key][index] = {} payload[key].forEach((payloadItem, payloadIndex) => { - if(payloadItem instanceof Object) { + if (payloadItem instanceof Object) { const payloadItemMatch = match(payloadItem, element) - if(payloadItemMatch.match) { + if (payloadItemMatch.match) { tester(payload[key][payloadIndex], element, currentNode[key][index]) } } From af437f7db28da0fd2492670e04778f7fc3273ddc Mon Sep 17 00:00:00 2001 From: Bassem Dghaidi Date: Sun, 24 May 2020 19:06:52 +0200 Subject: [PATCH 3/3] Releasing 0.1.13 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7d9a87..bc55736 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@menadevs/objectron", - "version": "0.1.12", + "version": "0.1.13", "description": "Compares a set of match rules contained with an object to determine if the latter conforms to the matching rules", "main": "index.js", "devDependencies": {