Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add chained input and.referenceToGroup #21

Merged
merged 3 commits into from
Jul 23, 2022

Conversation

didavid61202
Copy link
Collaborator

@didavid61202 didavid61202 commented Jul 23, 2022

Add a chained input and.referenceToGroup (regex: \k<groupName>) to add a new pattern that references the previously captured groups using the group name.

The argument of and.referenceToGroup (group name) have type safety by inferring from the Input type and should show autocomplete.

Not sure if the naming is clear, align with other names and easy to understand? need suggestion!

Usage

import { createRegExp, word, oneOrMore } from 'magic-regexp'

const RE = createRegExp(
  word
    .as('firstWord')
    .and(word.as('secondWord'))
    .and(oneOrMore(char))
    .and.referenceToGroup('secondWord')
    .and.referenceToGroup('firstWord')
) // /(?<firstWord>\w)(?<secondWord>\w)(.)+\k<secondWord>\k<firstWord>/

assert.equal(RE.test('TEN<==O==>NET'), true)

@vercel
Copy link

vercel bot commented Jul 23, 2022

Someone is attempting to deploy a commit to a Personal Account owned by @danielroe on Vercel.

@danielroe first needs to authorize it.

@vercel
Copy link

vercel bot commented Jul 23, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
magic-regexp ✅ Ready (Inspect) Visit Preview Jul 23, 2022 at 7:08PM (UTC)

@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2022

Codecov Report

Merging #21 (bb60665) into main (f35efa4) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main       #21   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          297       306    +9     
  Branches        77        79    +2     
=========================================
+ Hits           297       306    +9     
Impacted Files Coverage Δ
src/core/internal.ts 100.00% <100.00%> (ø)
src/core/inputs.ts 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f35efa4...bb60665. Read the comment docs.

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! ❤️

Will probably add example featuring this into playground/docs unless you do first as this is such a nice addition.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants