Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit b481313

Browse files
author
Bassem Dghaidi
authored
Merge pull request #12 from mena-devs/develop
0.1.12
2 parents 1b0b2e1 + 62a54d0 commit b481313

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const match = (payload, pattern, callback) => {
3131
* with the result object
3232
*/
3333
if (value instanceof RegExp) {
34-
const matcher = payload[key].match(value) || []
34+
const matcher = value.exec(payload[key]) || []
3535
if (matcher.length > 0) {
3636
result.groups = { ...result.groups, ...matcher.groups }
3737
currentNode[key] = payload[key]
@@ -49,7 +49,7 @@ const match = (payload, pattern, callback) => {
4949
* Level N depth RegExp handling
5050
*/
5151
if (element instanceof RegExp) {
52-
const matcher = payload[key][index].match(element) || []
52+
const matcher = element.exec(payload[key][index]) || []
5353
if (matcher.length > 0) {
5454
result.groups = { ...result.groups, ...matcher.groups }
5555
currentNode[key] = payload[key]

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@menadevs/objectron",
3-
"version": "0.1.11",
3+
"version": "0.1.12",
44
"description": "Compares a set of match rules contained with an object to determine if the latter conforms to the matching rules",
55
"main": "index.js",
66
"devDependencies": {

test/test_objectron.js

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,42 @@ suite('Objectron Core Tests', () => {
389389
assert.deepEqual(result, expected)
390390
})
391391

392+
test('Match number type values against regex pattern', () => {
393+
const payload = {
394+
age: 15,
395+
shoeSize: 44.5,
396+
temperature: {
397+
type: 'celcius',
398+
degree: -20
399+
}
400+
};
401+
402+
const result = match(payload, {
403+
age: /\d*/,
404+
shoeSize: /(\d+\.?\d*|\d*\.?\d+)/,
405+
temperature: {
406+
degree: /\-\d*/
407+
}
408+
});
409+
410+
const expected = {
411+
match: true,
412+
total: 3,
413+
matches: {
414+
age: 15,
415+
shoeSize: 44.5,
416+
temperature: {
417+
degree: -20
418+
}
419+
},
420+
groups: {}
421+
}
422+
423+
424+
assert.isTrue(result.match);
425+
assert.deepEqual(result, expected);
426+
});
427+
392428
test('Callback fired on match', () => {
393429
let called = false
394430

@@ -414,7 +450,8 @@ suite('Objectron Core Tests', () => {
414450
fields: [
415451
{
416452
type: 'plain_text',
417-
text: 'going home?'
453+
text: 'going home?',
454+
rating: 5.5
418455
},
419456
{
420457
type: 'markdown',
@@ -432,21 +469,28 @@ suite('Objectron Core Tests', () => {
432469
fields: [
433470
{
434471
type: 'plain_text',
435-
text: /(?<verb>\S+) (?<what>.+)?/
472+
text: /(?<verb>\S+) (?<what>.+)?/,
473+
rating: /(\d+\.?\d*|\d*\.?\d+)/
436474
}
437475
]
438476
}
439477
})
440478

441479
const expected = {
442480
match: true,
443-
total: 7,
481+
total: 8,
444482
matches: {
445483
api: 13,
446484
ids: [130, 45, 12],
447485
components: {
448486
type: 'section',
449-
fields: [{ type: 'plain_text', text: 'going home?' }]
487+
fields: [
488+
{
489+
type: 'plain_text',
490+
text: 'going home?',
491+
rating: 5.5
492+
}
493+
]
450494
}
451495
},
452496
groups: { verb: 'going', what: 'home?' }

0 commit comments

Comments
 (0)