node-htmldiff
Advanced tools
Comparing version 0.9.3 to 0.9.4
#!/usr/bin/env node | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs_1 = require("fs"); | ||
var path_1 = require("path"); | ||
var diffHTML = require("./js/htmldiff"); | ||
// Argument count. | ||
var argc = process.argv.length; | ||
// Name of the "executable", e. g. `htmldiff-cli`. | ||
var cli = path_1.parse(__filename).name; | ||
// Optional class attribute name for `<ins>` and `<del>` tags. | ||
var className = null; | ||
// Optional prefix for data-operation-index attribute. | ||
var dataPrefix = null; | ||
// Optional list of atomic tags. | ||
var atomicTags = null; | ||
/** | ||
* Output usage info and version on the console. | ||
*/ | ||
const fs_1 = require("fs"); | ||
const path_1 = require("path"); | ||
const htmldiff_1 = __importDefault(require("./js/htmldiff")); | ||
const argc = process.argv.length; | ||
const cli = (0, path_1.parse)(__filename).name; | ||
let className = null; | ||
let dataPrefix = null; | ||
let atomicTags = null; | ||
function printUsage() { | ||
var usage = cli + " v0.9.3\n\nUsage: " + cli + " beforeFile afterFile diffedFile [Options]\n\nbeforeFile:\n An HTML input file in its original form.\n\nafterFile:\n An HTML input file, based on beforeFile but with changes.\n\ndiffedFile:\n Name of the diffed HTML output file. All differences between beforeFile\n and afterFile will be surrounded with <ins> and <del> tags. If diffedFile\n is - (minus) the result will be written with console.log() to stdout.\n\nOptions:\n\n-c className (optional):\n className will be added as a class attribute on every <ins> and <del> tag.\n\n-p dataPrefix (optional):\n The data prefix to use for data attributes. The operation index data\n attribute will be named \"data-${dataPrefix-}operation-index\". If not\n used, the default attribute name \"data-operation-index\" will be added\n on every <ins> and <del> tag. The value of this attribute is an auto\n incremented counter.\n\n-t atomicTags (optional):\n Comma separated list of tag names. The list has to be in the form\n \"tag1,tag2,...\" e. g. \"head,script,style\". An atomic tag is one whose\n child nodes should not be compared - the entire tag should be treated\n as one token. This is useful for tags where it does not make sense to\n insert <ins> and <del> tags. If not used, this default list will be used:\n \"iframe,object,math,svg,script,video,head,style\"."; | ||
const usage = `${cli} v0.9.4 | ||
Usage: ${cli} beforeFile afterFile diffedFile [Options] | ||
beforeFile: | ||
An HTML input file in its original form. | ||
afterFile: | ||
An HTML input file, based on beforeFile but with changes. | ||
diffedFile: | ||
Name of the diffed HTML output file. All differences between beforeFile | ||
and afterFile will be surrounded with <ins> and <del> tags. If diffedFile | ||
is - (minus) the result will be written with console.log() to stdout. | ||
Options: | ||
-c className (optional): | ||
className will be added as a class attribute on every <ins> and <del> tag. | ||
-p dataPrefix (optional): | ||
The data prefix to use for data attributes. The operation index data | ||
attribute will be named "data-$\{dataPrefix-}operation-index". If not | ||
used, the default attribute name "data-operation-index" will be added | ||
on every <ins> and <del> tag. The value of this attribute is an auto | ||
incremented counter. | ||
-t atomicTags (optional): | ||
Comma separated list of tag names. The list has to be in the form | ||
"tag1,tag2,..." e. g. "head,script,style". An atomic tag is one whose | ||
child nodes should not be compared - the entire tag should be treated | ||
as one token. This is useful for tags where it does not make sense to | ||
insert <ins> and <del> tags. If not used, this default list will be used: | ||
"iframe,object,math,svg,script,video,head,style".`; | ||
console.log(usage); | ||
} | ||
/** | ||
* Read content of a file and return content as a string. The encoding of the | ||
* file is considered to be in UTF-8 format by default. | ||
* | ||
* @param {string} fileName - The name of the file to be read. | ||
* | ||
* @returns {string} - The content of 'fileName' as a string. An empty string is | ||
* considered to be an error which will be logged. | ||
*/ | ||
function readFileContent(fileName) { | ||
try { | ||
var result = fs_1.readFileSync(path_1.resolve(fileName), "utf-8"); | ||
const result = (0, fs_1.readFileSync)((0, path_1.resolve)(fileName), "utf-8"); | ||
if (result === "") { | ||
console.error("File \"" + fileName + "\" is empty."); | ||
console.error(`File "${fileName}" is empty.`); | ||
} | ||
@@ -42,16 +61,6 @@ return result; | ||
catch (error) { | ||
console.error("Couldn't read file \"" + fileName + "\"\n" + error.stack); | ||
console.error(`Couldn't read file "${fileName}"\n${error}`); | ||
return ""; | ||
} | ||
} | ||
/** | ||
* Set the value of one the variables for the `diff` function based on a given | ||
* switch name. The function fails (return false) if the value of the variable | ||
* is already set (duplicate switch) or the switch name is unknown. | ||
* | ||
* @param name {string} - The name of the switch (one of `-c`, `-p` or `-t`) | ||
* @param value {string} - The value of the switch given on the command line. | ||
* | ||
* @returns {boolean} - `true` if the switch could be resolved, otherwise `false`. | ||
*/ | ||
function resolveSwitch(name, value) { | ||
@@ -78,7 +87,5 @@ switch (name) { | ||
} | ||
// Unknown switch | ||
return false; | ||
} | ||
// Invalid argc | ||
var validArgc = [5, 7, 9, 11]; | ||
const validArgc = [5, 7, 9, 11]; | ||
if (validArgc.indexOf(argc) === -1) { | ||
@@ -88,3 +95,2 @@ printUsage(); | ||
} | ||
// Resolve switches | ||
if (argc > 6) { | ||
@@ -108,12 +114,11 @@ if (!resolveSwitch(process.argv[5], process.argv[6])) { | ||
} | ||
// Execute diff | ||
var beforeFile = readFileContent(process.argv[2]); | ||
const beforeFile = readFileContent(process.argv[2]); | ||
if (!beforeFile) { | ||
process.exit(1); | ||
} | ||
var afterFile = readFileContent(process.argv[3]); | ||
const afterFile = readFileContent(process.argv[3]); | ||
if (!afterFile) { | ||
process.exit(1); | ||
} | ||
var diffedResult = diffHTML(beforeFile, afterFile, className, dataPrefix, atomicTags); | ||
const diffedResult = (0, htmldiff_1.default)(beforeFile, afterFile, className, dataPrefix, atomicTags); | ||
if (process.argv[4] === "-") { | ||
@@ -123,3 +128,3 @@ console.log(diffedResult); | ||
else { | ||
fs_1.writeFileSync(path_1.resolve(process.argv[4]), diffedResult); | ||
(0, fs_1.writeFileSync)((0, path_1.resolve)(process.argv[4]), diffedResult); | ||
} |
/** | ||
* Compares two pieces of HTML content and returns the combined content with differences | ||
* wrapped in <ins> and <del> tags. | ||
* | ||
* @param {string} before The HTML content before the changes. | ||
* @param {string} after The HTML content after the changes. | ||
* @param {string} className (Optional) The class attribute to include in `<ins>` and `<del>` tags. | ||
* @param {string} dataPrefix (Optional) The data prefix to use for data attributes. The | ||
* operation index data attribute will be named `data-${dataPrefix-}operation-index`. | ||
* @param {string} atomicTags (Optional) Comma separated list of tag names. The list has to | ||
* be in the form `tag1,tag2,...` e. g. `head,script,style`. An atomic tag is one whose | ||
* child nodes should not be compared - the entire tag should be treated as one token. | ||
* This is useful for tags where it does not make sense to insert `<ins>` and `<del>` | ||
* tags. If not used, the default list `iframe,object,math,svg,script,video,head,style` | ||
* will be used. | ||
* | ||
* @return {string} The combined HTML content with differences wrapped in `<ins>` and `<del>` tags. | ||
* @param before The HTML content before the changes. | ||
* @param after The HTML content after the changes. | ||
* @param className (Optional) The class attribute to include in `<ins>` and `<del>` tags. | ||
* @param dataPrefix (Optional) The data prefix to use for data attributes. The operation index data | ||
* attribute will be named `data-${dataPrefix-}operation-index`. | ||
* @param atomicTags (Optional) Comma separated list of tag names. The list has to be in the form | ||
* `tag1,tag2,...` e. g. `head,script,style`. An atomic tag is one whose child nodes should not be | ||
* compared - the entire tag should be treated as one token. This is useful for tags where it does | ||
* not make sense to insert `<ins>` and `<del>` tags. If not used, the default list | ||
* `iframe,object,math,svg,script,video,head,style` will be used. | ||
* @return The combined HTML content with differences wrapped in `<ins>` and `<del>` tags. | ||
*/ | ||
declare function diff(before: string, after: string, className?: string | null, dataPrefix?: string | null, atomicTags?: string | null): string; | ||
export = diff; |
@@ -73,3 +73,3 @@ /** | ||
// Added head and style (for style tags inside the body) | ||
var defaultAtomicTagsRegExp = new RegExp('^<(iframe|object|math|svg|script|video|head|style)'); | ||
var defaultAtomicTagsRegExp = new RegExp('^<(iframe|object|math|svg|script|video|head|style|a)'); | ||
@@ -291,2 +291,8 @@ /** | ||
} | ||
// If the token is an a element, grab it's data attribute to include in the key. | ||
var a = /^<a.*href=['"]([^"']*)['"]/.exec(token); | ||
if (a) { | ||
return '<a href="' + a[1] + '"></a>'; | ||
} | ||
@@ -293,0 +299,0 @@ // If the token is an object element, grab it's data attribute to include in the key. |
@@ -5,4 +5,4 @@ { | ||
"companyname": "idesis GmbH", | ||
"copyright": "©2018, idesis GmbH; ©2012 The Network Inc. and contributors", | ||
"version": "0.9.3", | ||
"copyright": "©2022, idesis GmbH; ©2012 The Network Inc. and contributors", | ||
"version": "0.9.4", | ||
"identifier": "de.idesis.node-htmldiff", | ||
@@ -18,11 +18,11 @@ "keywords": [ | ||
"author": { | ||
"name": "Michael Nitze", | ||
"email": "michael.nitze@idesis.de", | ||
"url": "http://www.idesis.de" | ||
"name": "Michael Nitze", | ||
"email": "michael.nitze@idesis.de", | ||
"url": "https://www.idesis.de" | ||
}, | ||
"contributors": [ | ||
"The Network Inc. (http://www.tninetwork.com, https://github.com/tnwinc/htmldiff.js)", | ||
"The Network Inc. (https://www.tninetwork.com, https://github.com/tnwinc/htmldiff.js)", | ||
"Inkling (https://www.inkling.com, https://github.com/inkling/htmldiff.js)", | ||
"Ian White (ianwhitester@gmail.com, https://github.com/ian97531)" | ||
], | ||
], | ||
"repository": { | ||
@@ -34,4 +34,4 @@ "type": "git", | ||
"bugs": { | ||
"url": "https://github.com/idesis-gmbh/htmldiff.js/issues", | ||
"email": "produktion@idesis.de" | ||
"url": "https://github.com/idesis-gmbh/htmldiff.js/issues", | ||
"email": "produktion@idesis.de" | ||
}, | ||
@@ -52,8 +52,12 @@ "private": false, | ||
"types": "js/htmldiff.d.ts", | ||
"dependencies": { }, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"typescript": "2.7.2", | ||
"tslint": "5.9.1", | ||
"@types/node": "9.6.0", | ||
"@types/node": "18.7.11", | ||
"@typescript-eslint/eslint-plugin": "5.34.0", | ||
"@typescript-eslint/parser": "5.34.0", | ||
"chai": "*", | ||
"eslint": "8.22.0", | ||
"eslint-plugin-jsdoc": "39.3.6", | ||
"pkg": "5.8.0", | ||
"typescript": "4.7.4", | ||
"mocha": "*" | ||
@@ -64,6 +68,12 @@ }, | ||
"testsample": "node htmldiff-cli.js sample/before.html sample/after.html - -c myDiffClass -p myPrefix", | ||
"lint": "tslint --exclude ./htmldiff-cli.d.ts --config ./tslint.json ./*.ts ./js/*.ts", | ||
"lint": "eslint -c eslintrc.json --parser-options=project:./tsconfig.json --ext .ts ./", | ||
"premake": "npm run lint", | ||
"make": "tsc -p tsconfig.json && node -e \"require('fs').unlinkSync('./htmldiff-cli.d.ts')\"" | ||
"make": "tsc -p tsconfig.json && node -e \"require('fs').unlinkSync('./htmldiff-cli.d.ts')\"", | ||
"pack-macos-aarch64": "pkg -t node18-macos-arm64 -C GZip --output ./bin/macos-aarch64/htmldiff-cli htmldiff-cli.js -c ./pkg.json", | ||
"pack-macos-x64": " pkg -t node18-macos-x64 -C GZip --output ./bin/macos-x64/htmldiff-cli htmldiff-cli.js -c ./pkg.json", | ||
"pack-win32-x64": " pkg -t node18-win32-x64 -C GZip --output ./bin/win32-x64/htmldiff-cli htmldiff-cli.js -c ./pkg.json", | ||
"pack-linux-x64": " pkg -t node18-linuxstatic-x64 -C GZip --output ./bin/linux-x64/htmldiff-cli htmldiff-cli.js -c ./pkg.json", | ||
"pack-linux-aarch64": "pkg -t node18-linuxstatic-arm64 -C GZip --output ./bin/linux-aarch64/htmldiff-cli htmldiff-cli.js -c ./pkg.json", | ||
"pack-all": "npm run pack-macos-aarch64 && npm run pack-macos-x64 && npm run pack-win32-x64 && npm run pack-linux-x64 && npm run pack-linux-aarch64" | ||
} | ||
} | ||
} |
@@ -145,4 +145,4 @@ # htmldiff.js | ||
MIT © [idesis GmbH](http://www.idesis.de), Rellinghauser Straße 334F, D-45136 Essen | ||
MIT © [idesis GmbH](https://www.idesis.de), Max-Keith-Straße 66 (E 11), D-45136 Essen | ||
See the `LICENSE` file for details. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
120376
21
1
9
1902