Skip to content

Support matching string with array or object #7

@bas080

Description

@bas080

Considering patroon allows matching array with object and object with array, why not also allow matching a character of a string with an array or object?

const fn = patroon(
  'a', () => 'first character is a',
  [_, 'a'], () => 'second character is a',
  {2: 'b'}, () => 'third character is b',
)

fn('aaaa') // => 'first character is a'
fn('hallo') // => 'seconds character is a'
fn('baba') // => 'third character is b'

So really the pattern 'a' is equivalent to:

{0: 'a'}
// and
['a']

This requires a major version bump as string patterns are no longer a === (strict equal check).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmajorResults in a major version bump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions