Skip to content
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.

Ability to match multiple patterns in 1 call #23

Open
@Link-

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions