Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: experimental type-level RegExp match #288

Merged
merged 24 commits into from
May 5, 2023

Conversation

didavid61202
Copy link
Collaborator

@didavid61202 didavid61202 commented Apr 6, 2023

Update

Add type-level-regexp as dependency, and create a new subpath export type-level-regexp for end-users to try out this experimental features by importing magic-regexp helpers from magic-regexp/type-level-regexp.

this experimental features utilize generic types import from type-level-regexp to enhance the current MagicRegExp regexp object and return fully typed matched result when passing it to literal string's match, matchAll and replace functions.

for detail example please see test/type-level-regexp.test.ts

Usage

original semver example

const regExp = createRegExp(
      exactly('bar')
        .or('baz')
        .groupedAs('g1')
        .and(exactly('qux').and(digit.times(2)).groupedAs('g2')),
      new Set([caseInsensitive])
    )


    const replaceFunctionResult = 'prefix_babAzqUx42_suffix'.replace(
    //     ^? 'prefix_ba_capture-1: bAz, offset: 9, groups: { g1: bAz, g2: qUx42 }_suffix'
      regExp,
      (match, c1, c2, offset, input, groups) => // all arguments are typed
        `_capture-1: ${c1}, offset: ${offset}, groups: { g1: ${groups.g1}, g2: ${groups.g2} }`
    )

Related issues

#233
#235

Tasks

  • add/update tests
  • update docs (mark as experimental feature)

@vercel
Copy link

vercel bot commented Apr 6, 2023

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

@danielroe first needs to authorize it.

@what-the-diff
Copy link

what-the-diff bot commented Apr 6, 2023

PR Summary

  • Type-level RegExp Match Result Feature Added
    A new feature has been added that enhances regular expression matching capabilities at the type level.
  • Updated Documentation and Examples
    The documentation and example code have been updated to demonstrate the usage of the new feature.
  • Experimental Test Added
    A new experimental test has been included to verify the functionality of the type-level RegExp match result feature.
  • Further-Magic Import Specifier Support in Transformer Plugin
    The transformer plugin now supports further-magic import specifiers, allowing for enhanced flexibility and customization.

@didavid61202 didavid61202 marked this pull request as ready for review April 9, 2023 11:17
@didavid61202 didavid61202 force-pushed the feat/experimental-type-level-regexp branch from ebfcb54 to 8307b9a Compare April 9, 2023 11:52
@codecov-commenter
Copy link

codecov-commenter commented Apr 9, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (0ff5bcf) 100.00% compared to head (446ce19) 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #288    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            7         8     +1     
  Lines          533       671   +138     
  Branches        60        65     +5     
==========================================
+ Hits           533       671   +138     
Impacted Files Coverage Δ
src/further-magic.ts 100.00% <100.00%> (ø)
src/index.ts 100.00% <100.00%> (ø)
src/transform.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@didavid61202 didavid61202 force-pushed the feat/experimental-type-level-regexp branch from 260cdca to 5a5e756 Compare April 14, 2023 10:46
@didavid61202
Copy link
Collaborator Author

Hi @danielroe,

I've rebase and update the createRegExp function in the subpath export type-level-regexp to variadic functions.

Also update two small typo in docs and JSDoc.

please review and check if it needs more updates or fix when you have some free time 😊

@vercel
Copy link

vercel bot commented Apr 15, 2023

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

Name Status Preview Comments Updated (UTC)
magic-regexp ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2023 9:45am

@danielroe
Copy link
Member

Sorry for the long time to merge! This is fantastic and can't wait to start using it.

@danielroe danielroe merged commit 1bf8bb4 into unjs:main May 5, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants