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

Ability to match multiple patterns in 1 call #23

Open
Link- opened this issue Oct 4, 2020 · 0 comments
Open

Ability to match multiple patterns in 1 call #23

Link- opened this issue Oct 4, 2020 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Link-
Copy link
Member

Link- commented Oct 4, 2020

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.

@Link- Link- added enhancement New feature or request help wanted Extra attention is needed labels Oct 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant