This repository was archived by the owner on Jan 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
This repository was archived by the owner on Jan 2, 2023. It is now read-only.
Ability to match multiple patterns in 1 call #23
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
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.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed