1.0.5 • Published 2 years ago

@mlnop/string-replace v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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.
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago