Socket
Socket
Sign inDemoInstall

fixids

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fixids - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

85

bin/index.js

@@ -16,4 +16,85 @@ #!/usr/bin/env node

import { config } from 'dotenv';
import { printTitle } from './utils/title';
import { addIdsToHtmlFiles } from './utils/fix';
import readdirp from 'readdirp';
import { JSDOM } from 'jsdom';
import randomstring from 'randomstring';
import ora from 'ora';
const printTitle = () => {
console.log(chalk.green.bold(`
███████╗██╗██╗ ██╗ ██╗██████╗ ███████╗
██╔════╝██║╚██╗██╔╝ ██║██╔══██╗██╔════╝
█████╗ ██║ ╚███╔╝█████╗██║██║ ██║███████╗
██╔══╝ ██║ ██╔██╗╚════╝██║██║ ██║╚════██║
██║ ██║██╔╝ ██╗ ██║██████╔╝███████║
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝
`));
};
const generateRandomId = (largeId) => {
return randomstring.generate({ length: largeId, charset: 'alphanumeric' });
};
const oraStart = (text = '') => {
return ora({
text,
spinner: {
interval: 800,
frames: ['🚀', '🤖', '🚀', '🤖', '🚀', '🤖', '🚀', '🤖'],
},
}).start();
};
const addIdsToHtmlFiles = (directory, largeId, tagsToModify, excludeTags) => __awaiter(void 0, void 0, void 0, function* () {
let reviewSpinner;
try {
console.log(chalk.green.bold(`🤖: Browsing Directory "${directory}"`));
let totalFixed = 0;
const files = yield readdirp.promise(path.join(process.cwd(), directory), {
fileFilter: '*.html',
directoryFilter: (di) => !di.basename.startsWith('.'),
});
const totalFiles = files.length;
reviewSpinner = oraStart(chalk.green(`Total Files: ${totalFiles}`));
files.forEach((file, index) => {
try {
const filePath = file.fullPath;
reviewSpinner.text = chalk.green.bold(`🤖: Fixing file [${index + 1} - ${totalFiles}]: ${filePath}`);
const fileContent = fs.readFileSync(filePath, 'utf8');
const dom = new JSDOM(fileContent, { includeNodeLocations: true });
const elements = dom.window.document.querySelectorAll('*:not(html):not(head):not(body):not(script):not(style)');
let elementsFixed = 0;
elements.forEach((element) => {
var _a;
if (tagsToModify.length === 0 || tagsToModify.includes(element.tagName.toLowerCase())) {
if (!element.hasAttribute('id')
&& !excludeTags.includes(element.tagName.toLowerCase())
&& ((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) !== 'head') {
element.setAttribute('id', generateRandomId(largeId));
elementsFixed++;
}
}
});
if (elementsFixed > 0) {
let fixedContent = dom.serialize({ pretty: true });
if (!fileContent.includes('<html'))
fixedContent = fixedContent.replace(/<\/?html>/gi, '');
if (!fileContent.includes('<head'))
fixedContent = fixedContent.replace(/<\/?head>/gi, '');
if (!fileContent.includes('<body'))
fixedContent = fixedContent.replace(/<\/?body>/gi, '');
fs.writeFileSync(filePath, fixedContent);
totalFixed++;
}
reviewSpinner.text = chalk.green.bold(`🤖: File fixed correctly [${index + 1} - ${totalFiles}]: ${filePath}`);
}
catch (err) {
reviewSpinner.fail(chalk.red.bold(`🤖: Error in file "${file.fullPath}"`, err));
}
});
reviewSpinner.stop();
console.log(chalk.green.bold(`🤖: A total of ${totalFixed} files have been fixed.`));
}
catch (err) {
console.log(chalk.red(`🤖: Error browsing directory "${directory}"`, err));
if (reviewSpinner)
reviewSpinner.stop();
}
});
const main = () => __awaiter(void 0, void 0, void 0, function* () {

@@ -20,0 +101,0 @@ printTitle();

2

package.json
{
"name": "fixids",
"version": "1.0.4",
"version": "1.0.5",
"description": "",

@@ -5,0 +5,0 @@ "main": "bin/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc