Problem:
There are scenarios that require matching an item in an array but also the following item (or items at any other index). Example:
[
{
type: 'code',
raw: '```\n{ issues: [1,2] }\n```\n',
lang: '',
text: '{ issues: [1,2] }'
},
{ type: 'hr', raw: '---\n\n' },
{
type: 'heading',
raw: '## Action Items\n',
depth: 2,
text: 'Action Items',
tokens: [ [Object] ]
},
{
type: 'heading',
raw: '#### Test Issue #1 - #1 - 03 October 2020\n',
depth: 4,
text: 'Test Issue #1 - #1 - 03 October 2020',
tokens: [ [Object] ]
},
{
type: 'list',
raw: '- [ ] Action item #1 for @Link- \n' +
'- [ ] @Link- has to do action items #2\n' +
'\n',
ordered: false,
start: '',
loose: false,
items: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object]
]
}
]
For the payload I would like to match the following objects:
{
type: 'heading',
raw: '#### Test Issue #1 - #1 - 03 October 2020\n',
depth: 4,
text: 'Test Issue #1 - #1 - 03 October 2020',
tokens: [ [Object] ]
},
{
type: 'list',
raw: '- [ ] Action item #1 for @Link- \n' +
'- [ ] @Link- has to do action items #2\n' +
'\n',
ordered: false,
start: '',
loose: false,
items: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object]
]
}
However, the match() function accepts only 1 pattern. If arguments are passed as follows:
match(
block,
{
type: 'heading',
depth: 4,
text: /.*(?<issueNumber>#[0-9]*) - (?<date>.*)/
},
{
type: 'list',
ordered: false,
loose: false
}
)
The method will assume the second pattern object as the callback.
Proposed Solution
Allow match() to accept an array of patterns while providing a new optional flag that will inform the method that it should handle an array of patterns not lookup the array structure in the payload.
Problem:
There are scenarios that require matching an item in an array but also the following item (or items at any other index). Example:
For the
payloadI would like to match the following objects:However, the
match()function accepts only 1pattern. If arguments are passed as follows:The method will assume the second pattern object as the callback.
Proposed Solution
Allow
match()to accept anarray of patternswhile providing a new optional flag that will inform the method that it should handle anarray of patternsnot lookup the array structure in thepayload.