Skip to content

LaTableRouge/string-replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

string-replace

string-replace is a package used to find a string match in a file and replace it

Usage example

string-replace is available as an NPM package:

npm i @mlnop/string-replace --save-dev

Usual

const {stringReplaceOpenAndWrite, stringReplace} = require("@mlnop/string-replace");
const {resolve} = require("path");

// single file usage
stringReplaceOpenAndWrite(resolve(__dirname, "README.md"), [
  {
    from: /\bstring-replace/g,
    to: "ayaya",
  },
]);

// single or multiple file usage
stringReplace([
  {
    filePath: [resolve(__dirname, "README.md")],
    replace: [
      {
        from: /\bstring-replace/g,
        to: "ayaya",
      },
      {
        from: /\bUsage example/g,
        to: "hello there",
      },
    ],
  },
  {
    filePath: resolve(__dirname, "README.md"),
    replace: [
      {
        from: /\bstring-replace/g,
        to: "ayaya",
      },
      {
        from: /\bUsage example/g,
        to: "hello there",
      },
    ],
  },
]);

Vite plugin

for the vite compatibilty, you can pass a hook as second parameter in the function ("closeBundle" is the default value)

const {viteStringReplace} = require("@mlnop/string-replace");
const {resolve} = require("path");

// vite plugin single or multiple file usage
viteStringReplace(
  [
    {
      filePath: [resolve(__dirname, "README.md")],
      replace: [
        {
          from: /\bstring-replace/g,
          to: "ayaya",
        },
        {
          from: /\bUsage example/g,
          to: "hello there",
        },
      ],
    },
    {
      filePath: resolve(__dirname, "README.md"),
      replace: [
        {
          from: /\bstring-replace/g,
          to: "ayaya",
        },
        {
          from: /\bUsage example/g,
          to: "hello there",
        },
      ],
    },
  ],
  "closeBundle"
);

Changelog

1.0.5 — 07/11/2022

  • Added vite compatibility
  • Published to NPM.

1.0.0 — 07/11/2022

  • First commit.
  • Published to NPM.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published