Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

magic-regexp

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-regexp

[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37K
decreased by-54.46%
Maintainers
1
Weekly downloads
 
Created
Source

🦄 magic-regexp

npm version npm downloads Github Actions Codecov

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

  • More TypeScript guard-rails
  • More complex RegExp features/syntax
  • Instrumentation for accurately getting coverage on RegExps
  • Hybrid/partially-compiled RegExps for better dynamic support

Usage

Install package:

# npm
npm install magic-regexp

# yarn
yarn add magic-regexp

# pnpm
pnpm install magic-regexp
import { createRegExp, exactly } from 'magic-regexp'

const regExp = createRegExp(exactly('foo/test.js').after('bar/'))
console.log(regExp)

// /(?<=bar\/)foo\/test\.js/

In order to statically transform magic-regexps at build time, you can use the included unplugin.

Nuxt:

import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  // This will also enable auto-imports of magic-regexp helpers
  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.

FAQs

Package last updated on 16 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc