Socket
Book a DemoInstallSign in
Socket

@reliverse/bleregex

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reliverse/bleregex

@reliverse/bleregex is a collection of various useful regexes for javascript and typescript

1.0.1
latest
npmnpm
Version published
Maintainers
1
Created
Source

Bleregex

@reliverse/bleregex: a collection of various useful regexes for javascript and typescript

bun add @reliverse/bleregex

Usage Example

import { VERSION_PATTERNS } from "@reliverse/bleregex";

/**
 * Updates version strings in a file's content.
 */
async function updateVersionInContent(
  filePath: string,
  content: string,
  oldVersion: string,
  newVersion: string,
): Promise<boolean> {
  let updatedContent = content;
  let changed = false;

  // Debug: Log which file is being checked and what patterns are being used
  relinka("verbose", `[updateVersionInContent] Checking file: ${filePath}`);

  if (/\.(json|jsonc|json5)$/.test(filePath)) {
    const jsonPattern = VERSION_PATTERNS.find((p) => p.id === "json-version");
    if (jsonPattern && content.includes(`"version": "${oldVersion}"`)) {
      relinka(
        "verbose",
        `[updateVersionInContent] JSON pattern matched in: ${filePath}`,
      );
      updatedContent = content.replace(
        jsonPattern.pattern(oldVersion),
        `"version": "${newVersion}"`,
      );
      changed = true;
    }
  } else if (filePath.endsWith(".ts")) {
    const tsPatterns = VERSION_PATTERNS.filter((p) => p.id.startsWith("ts-"));
    for (const { id, pattern } of tsPatterns) {
      const regex = pattern(oldVersion);
      if (regex.test(updatedContent)) {
        relinka(
          "verbose",
          `[updateVersionInContent] Pattern '${id}' matched in: ${filePath}`,
        );
        updatedContent = updatedContent.replace(regex, `$1${newVersion}$2`);
        changed = true;
      } else {
        relinka(
          "verbose",
          `[updateVersionInContent] Pattern '${id}' did NOT match in: ${filePath}`,
        );
      }
    }
  }

  if (changed) {
    relinka(
      "verbose",
      `[updateVersionInContent] Version updated in: ${filePath}`,
    );
    await writeFileSafe(filePath, updatedContent, "version update");
  } else {
    relinka(
      "verbose",
      `[updateVersionInContent] No version updated in: ${filePath}`,
    );
  }
  return changed;
}

License

MIT © Nazar Kornienko (blefnk), Reliverse

FAQs

Package last updated on 17 May 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.