New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

glamm

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glamm

Python regular expressions to JavaScript regex

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Glamm: Python to JavaScript Regex Converter

Glamm is a lightweight utility that converts Python-flavored regular expressions into JavaScript-compatible ones. It helps bridge the gap between the regex syntax of the two languages, allowing you to use familiar Python patterns in a JavaScript environment.

Features

Glamm currently supports the following conversions:

  • Named Capture Groups: (?P<name>...) is converted to (?<name>...)
  • Named Group References: (?P=name) is converted to \k<name>
  • Possessive Quantifiers: *+, ++, ?+ are converted to their JavaScript equivalents.
  • Start of String Anchor: \A is converted to ^.
  • End of String Anchors: \Z and \z are converted to $.
  • Inline Flags: Extracts flags like i, s, m, u from (?is...).
  • Inline Comments: (?#...) are removed.

Code Example

Here's an example of how to use Glamm to convert a Python regex pattern:

import { glamm } from "glamm";

const pythonPattern = "(?i)(?P<username>\w+), (?P=username)@gmail.com";

const { regex } = glamm(pythonPattern);

console.log(regex);
// Output: /(?<username>\w+), \k<username>@gmail.com/i

Testing

This project uses Vitest for testing. To run the tests, use the following command:

npm test

Coverage

To generate a test coverage report, run:

npm run coverage

This will create a coverage directory with a detailed report.

FAQs

Package last updated on 06 Nov 2025

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