azpepoze.node_tools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +27 -0
  2. package/package.json +16 -0
package/index.js ADDED
@@ -0,0 +1,27 @@
1
+ const fs = require("fs");
2
+
3
+ /**
4
+ * Replaces content in a file based on a regular expression.
5
+ *
6
+ * @param {string} path - The path to the file.
7
+ * @param {RegExp} regex - The regular expression to match the content to replace.
8
+ * @param {string} target - The string to replace the matched content with.
9
+ */
10
+ function File_Content_Replace(path, regex, target) {
11
+ try {
12
+ // Read the file content
13
+ const content = fs.readFileSync(path, "utf8");
14
+
15
+ // Replace the content using the regex and target
16
+ const updatedContent = content.replace(regex, target);
17
+
18
+ // Write the updated content back to the file
19
+ fs.writeFileSync(path, updatedContent, "utf8");
20
+
21
+ console.log(`File updated successfully: ${path}`);
22
+ } catch (error) {
23
+ console.error(`Error processing the file at ${path}:`, error);
24
+ }
25
+ }
26
+
27
+ module.exports = { File_Content_Replace };
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "azpepoze.node_tools",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "keywords": [
7
+ "AzPepoze",
8
+ "az_node_tools"
9
+ ],
10
+ "author": "AzPepoze",
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/AzPepoze/Az_Node_Tools"
15
+ }
16
+ }