This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
Values stored in groups don't retain the original types #24
Open
Description
I was using the regex groups features and noticed that for fields with non-string type values e.g. numbers, boolean etc..., end up being cast into string when they are added into the groups object in the result. The matches object in the result seems to be normal.
Here is an example test to illustrate
test('Maintain types in groups', () => {
const payload = {
response: {
status: 200,
_transferSize: 2863
},
}
const result = match(payload, {
response: {
status: /^(?<respStatus>[0-9]{3})/,
_transferSize: /(?<respSize>\d+)/,
}
})
const expected = {
match: true,
total: 2,
matches: {
response: {
status: 200,
_transferSize: 2863
}
},
groups: {
respStatus: 200,
respSize: 2863
}
}
assert.isTrue(result.match)
assert.deepEqual(result, expected)
})
Test result
AssertionError: expected { Object (match, total, ...) } to deeply equal { Object (match, total, ...) }
+ expected - actual
{
"groups": {
- "respSize": "2863"
- "respStatus": "200"
+ "respSize": 2863
+ "respStatus": 200
}
"match": true
"matches": {
"response": {
We might want to look into this issue, especially if the user is actually writing a regex group in the pattern to be matching by specific type.
Activity