1.39.0 • Published 1 year ago
data-matching v1.39.0
data-matching
Matches a data object against a match object.
Syntax details
- Part of strings can be collected using '!{name}' syntax (see https://github.com/MayamaTakeshi/string-matching)
- data can be collected (stored in a dictionary passed to matching function) by using dm.collect('name')
- data that should be absent can be declared with dm.absent
Sample usage
Full match (all specified data must be present):
const dm = require("data-matching")
const assert = require('assert')
var received = {
connection: { ip: '192.168.2.10' },
media: [
{
type: 'application',
port: 9,
protocol: 'TCP/MRCPv2',
payloads: ["0"],
setup: 'active',
connection: 'new',
resource: 'speechsynth'
},
{
type: 'audio',
port: 14238,
protocol: 'RTP/AVP',
payloads: ["0", "8", "96"],
}
]
}
var expected = {
connection: { ip: dm.collect('remote_ip') },
media: [
{
type: 'application',
port: 9,
protocol: '!{transport_protocol}/MRCP!{mrcp_version}',
payloads: [dm.collect('mrcp_payload')],
setup: 'active',
connection: 'new',
resource: dm.any_of(['speechsynth', 'speechrecog'], 'media_resource')
},
{
type: 'audio',
port: 14238,
protocol: 'RTP/AVP',
payloads: ["0", "8", "96"],
}
]
}
var store = {}
assert(dm.full_match(expected)(received, store))
assert(store.remote_ip == "192.168.2.10")
assert(store.mrcp_payload == "0")
assert(store.media_resource == 'speechsynth')
assert(store.mrcp_version == 'v2')
assert(store.transport_protocol == 'TCP')
Partial match (only part of the data must match):
const dm = require("data-matching")
const assert = require('assert')
var received = {
request_uri: 'sip:alice@abc.com',
from_uri: '<sip:bob@cba.com>',
to_uri: 'sip:alice@abc.com',
call_id: 'ee98b779-3048-41cf-b85b-0a05bcc4038a',
cseq: 'INVITE 50',
}
var expected = {
request_uri: 'sip:!{user1}@!{domain1}',
from_uri: '<sip:!{user2}@!{domain2}>',
cseq: '!{method} 50',
some_absent_key: dm.absent,
}
var store = {}
assert(dm.partial_match(expected)(received, store))
assert(store.user1 == 'alice')
assert(store.domain1 == 'abc.com')
assert(store.user2 == 'bob')
assert(store.domain2 == 'cba.com')
assert(store.method == 'INVITE')
More examples:
See https://github.com/MayamaTakeshi/data-matching/blob/master/test/matching.test.js
1.39.0
1 year ago
1.37.0
1 year ago
1.38.0
1 year ago
1.35.1
1 year ago
1.35.0
1 year ago
1.36.0
1 year ago
1.34.0
1 year ago
1.29.0
2 years ago
1.27.1
2 years ago
1.32.0
2 years ago
1.30.0
2 years ago
1.28.0
2 years ago
1.33.0
2 years ago
1.31.0
2 years ago
1.25.0
2 years ago
1.26.0
2 years ago
1.27.0
2 years ago
1.24.1
3 years ago
1.24.0
3 years ago
1.23.10
3 years ago
1.23.9
3 years ago
1.23.8
4 years ago
1.23.7
4 years ago
1.23.6
4 years ago
1.23.5
4 years ago
1.23.4
5 years ago
1.23.3
5 years ago
1.23.2
5 years ago
1.23.1
5 years ago
1.23.0
5 years ago
1.22.0
5 years ago
1.19.0
5 years ago
1.18.5
5 years ago
1.21.0
5 years ago
1.20.0
5 years ago
1.18.4
5 years ago
1.18.3
5 years ago
1.18.2
6 years ago
1.18.1
6 years ago
1.18.0
6 years ago
1.16.0
6 years ago
1.15.0
7 years ago
1.14.0
7 years ago
1.13.0
7 years ago
1.12.0
7 years ago
1.11.0
7 years ago
1.10.0
7 years ago
1.9.0
7 years ago
1.8.0
7 years ago
1.7.0
7 years ago
1.6.0
7 years ago
1.5.0
8 years ago
1.4.0
8 years ago
1.3.0
8 years ago
1.2.0
8 years ago
1.1.0
8 years ago
1.0.0
8 years ago