js-comments-eraser 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 (3) hide show
  1. package/index.js +51 -0
  2. package/package.json +12 -0
  3. package/readme.md +46 -0
package/index.js ADDED
@@ -0,0 +1,51 @@
1
+ const fs = require('fs');
2
+
3
+ // Function to remove comment lines
4
+ function removeCommentsFromFile(fileContent) {
5
+
6
+ const commentRegex1 = /(http:\/\/)/gm;
7
+ const commentRegex2 = /(https:\/\/)/gm;
8
+ const step1 = fileContent.replace(commentRegex1, 'http:--').replace(commentRegex2, 'https:--')
9
+
10
+ const commentRegex = /\/\/(?!gm;).*?$|\/\*[\s\S]*?\*\//gm;
11
+ const step2 = step1.replace(commentRegex, '')
12
+
13
+ const commentRegex1n = /(http:--)/gm;
14
+ const commentRegex2n = /(https:--)/gm;
15
+ const step3 = step2.replace(commentRegex1n, 'http://').replace(commentRegex2n, 'https://')
16
+
17
+ const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
18
+ const step4 = step3.replace(falseIfBlockRegex, '')
19
+
20
+ return step4;
21
+ }
22
+
23
+ // Get command line arguments
24
+ const args = process.argv.slice(2);
25
+
26
+ if (args.length !== 2) {
27
+ console.error('Usage: node nocomments <source.js> <target.js>');
28
+ process.exit(1);
29
+ }
30
+
31
+ const sourceFile = args[0];
32
+ const targetFile = args[1];
33
+
34
+ // Read source file and clear comments
35
+ fs.readFile(sourceFile, 'utf8', (err, data) => {
36
+ if (err) {
37
+ console.error(`Could not read source file: ${sourceFile}`, err);
38
+ process.exit(1);
39
+ }
40
+
41
+ const cleanedContent = removeCommentsFromFile(data);
42
+
43
+ // Write cleaned content to destination file
44
+ fs.writeFile(targetFile, cleanedContent, 'utf8', err => {
45
+ if (err) {
46
+ console.error(`Could not write target file: ${targetFile}`, err);
47
+ process.exit(1);
48
+ }
49
+ console.log(`Comments were cleaned up and saved to ${targetFile}.`);
50
+ });
51
+ });
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "js-comments-eraser",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "keywords": ["node", "js", "javascript", "delete", "scrape", "comment", "remove", "eraser", "server", "client", "cleaner", "comments"],
9
+ "author": "aydincandan@gmail.com",
10
+ "license": "ISC",
11
+ "description": "clears comments for javascript only"
12
+ }
package/readme.md ADDED
@@ -0,0 +1,46 @@
1
+ ## Türkçe
2
+
3
+ Projenize dahil etmek için aşağıdaki gibi yapın
4
+
5
+ ```
6
+ $ npm i js-comments-eraser
7
+ ```
8
+
9
+ Komut satırından kullanabilmek için **yorumyok.js** gibi bir dosya açın ve içine aşağıdakini yapıştırın.
10
+
11
+
12
+ ```
13
+ return yorumyok = require('js-comments-eraser')
14
+ ```
15
+
16
+ Daha sonra aşağıdaki gibi komut satırından kullanın.
17
+
18
+ ```
19
+ $ node yorumyok yorumlu.js yorumsuz.js
20
+ ```
21
+
22
+ [js-comments-eraser](https://github.com/aydincandan/Back-End-NodeMiddle-npmjs.com/pulls) için önerileriniz dikkate alınacaktır.
23
+
24
+
25
+
26
+ ## English
27
+
28
+ To include it in your project, do the following
29
+
30
+ ```
31
+ $ npm i js-comments-eraser
32
+ ```
33
+
34
+ To use it from the command line, open a file like **nocomments.js** and paste the following into it.
35
+
36
+ ```
37
+ return nocomments = require('js-comments-eraser')
38
+ ```
39
+
40
+ Then use it from the command line as follows.
41
+
42
+ ```
43
+ $ node nocomments withcomments.js withoutcomments.js
44
+ ```
45
+
46
+ Your suggestions for [js-comments-eraser](https://github.com/aydincandan/Back-End-NodeMiddle-npmjs.com/pulls) will be taken into consideration.