Standardize string quotes to single quotes and improve code readability

This commit is contained in:
2026-01-26 22:22:27 +00:00
parent 3f665c293e
commit 3dd14bb9c0

View File

@@ -14,10 +14,10 @@
* Example:
* npm run bookmarklet -- code/bookmarklets/example-bookmarklet.js
*/
import fs from "fs";
import path from "path";
import clipboardy from "clipboardy";
import { fileURLToPath } from "url";
import fs from 'fs';
import path from 'path';
import clipboardy from 'clipboardy';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -29,9 +29,9 @@ const __dirname = path.dirname(__filename);
*/
function removeComments(code) {
// Remove multi-line comments /* ... */
code = code.replace(/\/\*[\s\S]*?\*\//g, "");
code = code.replace(/\/\*[\s\S]*?\*\//g, '');
// Remove single-line comments //
code = code.replace(/\/\/.*$/gm, "");
code = code.replace(/\/\/.*$/gm, '');
return code;
}
@@ -42,12 +42,12 @@ function removeComments(code) {
*/
function minify(code) {
return code
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0)
.join(" ")
.replace(/\s+/g, " ")
.replace(/\s*([{}();,])\s*/g, "$1");
.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0)
.join(' ')
.replace(/\s+/g, ' ')
.replace(/\s*([{}();,])\s*/g, '$1');
}
/**
@@ -62,7 +62,7 @@ function generateBookmarklet(filePath) {
}
// Read the JavaScript file
const jsCode = fs.readFileSync(filePath, "utf8");
const jsCode = fs.readFileSync(filePath, 'utf8');
// Clean and minify
let cleanedCode = removeComments(jsCode);
@@ -79,11 +79,11 @@ try {
const filePath = process.argv[2];
if (!filePath) {
console.error("❌ Error: Please provide a file path");
console.log("\nUsage:");
console.log(" npm run bookmarklet -- <path-to-js-file>");
console.log("\nExample:");
console.log(" npm run bookmarklet -- code/bookmarklets/my-bookmarklet.js");
console.error('❌ Error: Please provide a file path');
console.log('\nUsage:');
console.log(' npm run bookmarklet -- <path-to-js-file>');
console.log('\nExample:');
console.log(' npm run bookmarklet -- code/bookmarklets/my-bookmarklet.js');
process.exit(1);
}
@@ -93,14 +93,14 @@ try {
// Copy to clipboard
clipboardy.writeSync(bookmarklet);
console.log("✅ Bookmarklet generated successfully!");
console.log('✅ Bookmarklet generated successfully!');
console.log(`📁 Source: ${fileName}`);
console.log(`📋 Copied to clipboard (${bookmarklet.length} characters)`);
console.log("\n📝 Next steps:");
console.log(" 1. Create a new bookmark in your browser");
console.log(" 2. Paste the clipboard content as the URL");
console.log(" 3. Give it a name and save");
console.log('\n📝 Next steps:');
console.log(' 1. Create a new bookmark in your browser');
console.log(' 2. Paste the clipboard content as the URL');
console.log(' 3. Give it a name and save');
} catch (error) {
console.error("❌ Error:", error.message);
console.error('❌ Error:', error.message);
process.exit(1);
}