🦄 magic-regexp
A compiled-away, type-safe, readable RegExp alternative
Features
⚠️ magic-regexp
is currently a work in progress. ⚠️
- Runtime is zero-dependency and ultra-minimal
- Ships with transform for compiling runtime to pure RegExp
- Supports automatically typed capture groups
- Packed with useful utilities:
charIn
, charNotIn
, anyOf
, char
, word
, digit
, whitespace
, letter
, tab
, linefeed
, carriageReturn
, not
, maybe
, exactly
- All chainable with
and
, or
, after
, before
, notAfter
, notBefore
, times
, as
, at
Future ideas
Usage
Install package:
npm install magic-regexp
yarn add magic-regexp
pnpm install magic-regexp
import { createRegExp, exactly } from 'magic-regexp'
const regExp = createRegExp(exactly('foo/test.js').after('bar/'))
console.log(regExp)
In order to statically transform magic-regexps at build time, you can use the included unplugin.
Nuxt:
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
modules: ['magic-regexp/nuxt'],
})
Vite:
import { defineConfig } from 'vite'
import { MagicRegExpTransformPlugin } from 'magic-regexp'
export default defineConfig({
plugins: [MagicRegExpTransformPlugin.vite()],
})
unbuild:
import { defineBuildConfig } from 'unbuild'
import { MagicRegExpTransformPlugin } from 'magic-regexp'
export default defineBuildConfig({
hooks: {
'rollup:options': (options, config) => {
config.plugins.push(MagicRegExpTransformPlugin.rollup())
},
},
})
💻 Development
- Clone this repository
- Enable Corepack using
corepack enable
(use npm i -g corepack
for Node.js < 16.10) - Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
License
Made with ❤️
Published under MIT License.